summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-08-18 16:34:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-08-18 16:36:56 -0400
commit871330c37907d894f021b8ec0f44b31c2460ce0c (patch)
tree71b5ddf4ae73743684049e0c24e2595ff575c7c1
parentb653fedca5f0fc384c990e93d82c0780c9e76f2c (diff)
downloadsqlalchemy-871330c37907d894f021b8ec0f44b31c2460ce0c.tar.gz
- forgot to implement py3k logic for JSON.NULL
-rw-r--r--lib/sqlalchemy/dialects/postgresql/json.py44
1 files changed, 21 insertions, 23 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py
index 2e2e71d0c..2a56649db 100644
--- a/lib/sqlalchemy/dialects/postgresql/json.py
+++ b/lib/sqlalchemy/dialects/postgresql/json.py
@@ -265,38 +265,36 @@ class JSON(sqltypes.Indexable, sqltypes.TypeEngine):
json_serializer = dialect._json_serializer or json.dumps
if util.py2k:
encoding = dialect.encoding
-
- def process(value):
- if value is self.NULL:
- value = None
- elif isinstance(value, elements.Null) or (
- value is None and self.none_as_null
- ):
- return None
- return json_serializer(value).encode(encoding)
else:
- def process(value):
- if isinstance(value, elements.Null) or (
- value is None and self.none_as_null
- ):
- return None
+ encoding = None
+
+ def process(value):
+ if value is self.NULL:
+ value = None
+ elif isinstance(value, elements.Null) or (
+ value is None and self.none_as_null
+ ):
+ return None
+ if encoding:
+ return json_serializer(value).encode(encoding)
+ else:
return json_serializer(value)
+
return process
def result_processor(self, dialect, coltype):
json_deserializer = dialect._json_deserializer or json.loads
if util.py2k:
encoding = dialect.encoding
-
- def process(value):
- if value is None:
- return None
- return json_deserializer(value.decode(encoding))
else:
- def process(value):
- if value is None:
- return None
- return json_deserializer(value)
+ encoding = None
+
+ def process(value):
+ if value is None:
+ return None
+ if encoding:
+ value = value.decode(encoding)
+ return json_deserializer(value)
return process