summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-11-28 03:04:59 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-11-28 03:04:59 +0000
commit06d47888114f6f9fd86f306ffccf05caa8741e7b (patch)
treedbbf064913ae5e26fb9878071e0a7f1267254b58
parente0ce35ef72d66613cb65223254d3a7214eaead47 (diff)
parentd58844e5483483240f97537e9a77b4e79cea2ab3 (diff)
downloadpsycopg2-06d47888114f6f9fd86f306ffccf05caa8741e7b.tar.gz
Merge remote-tracking branch 'jdufresne/json'
-rw-r--r--lib/_json.py32
1 files changed, 4 insertions, 28 deletions
diff --git a/lib/_json.py b/lib/_json.py
index 92a9def..cd2e7e1 100644
--- a/lib/_json.py
+++ b/lib/_json.py
@@ -27,22 +27,13 @@ extensions importing register_json from extras.
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
+import json
import sys
from psycopg2._psycopg import ISQLQuote, QuotedString
from psycopg2._psycopg import new_type, new_array_type, register_type
-# import the best json implementation available
-if sys.version_info[:2] >= (2, 6):
- import json
-else:
- try:
- import simplejson as json
- except ImportError:
- json = None
-
-
# oids from PostgreSQL 9.2
JSON_OID = 114
JSONARRAY_OID = 199
@@ -67,13 +58,7 @@ class Json(object):
def __init__(self, adapted, dumps=None):
self.adapted = adapted
self._conn = None
-
- if dumps is not None:
- self._dumps = dumps
- elif json is not None:
- self._dumps = json.dumps
- else:
- self._dumps = None
+ self._dumps = dumps or json.dumps
def __conform__(self, proto):
if proto is ISQLQuote:
@@ -86,13 +71,7 @@ class Json(object):
provided in the constructor. You can override this method to create a
customized JSON wrapper.
"""
- dumps = self._dumps
- if dumps is not None:
- return dumps(obj)
- else:
- raise ImportError(
- "json module not available: "
- "you should provide a dumps function")
+ return self._dumps(obj)
def prepare(self, conn):
self._conn = conn
@@ -181,10 +160,7 @@ def register_default_jsonb(conn_or_curs=None, globally=False, loads=None):
def _create_json_typecasters(oid, array_oid, loads=None, name='JSON'):
"""Create typecasters for json data type."""
if loads is None:
- if json is None:
- raise ImportError("no json module available")
- else:
- loads = json.loads
+ loads = json.loads
def typecast_json(s, cur):
if s is None: