Adapter.native_json

This commit is contained in:
mdipierro
2013-01-21 14:13:05 -06:00
parent 1518cbd16e
commit d15f13dcbd
2 changed files with 21 additions and 17 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.1-alpha.2+timestamp.2013.01.21.14.05.02 Version 2.4.1-alpha.2+timestamp.2013.01.21.14.12.24
+20 -16
View File
@@ -612,6 +612,7 @@ class ConnectionPool(object):
################################################################################### ###################################################################################
class BaseAdapter(ConnectionPool): class BaseAdapter(ConnectionPool):
native_json = False
driver = None driver = None
driver_name = None driver_name = None
drivers = () # list of drivers from which to pick drivers = () # list of drivers from which to pick
@@ -1790,12 +1791,13 @@ class BaseAdapter(ConnectionPool):
else: else:
obj = str(obj) obj = str(obj)
elif fieldtype == 'json': elif fieldtype == 'json':
if have_serializers: if not self.native_json:
obj = serializers.json(obj) if have_serializers:
elif simplejson: obj = serializers.json(obj)
obj = simplejson.dumps(items) elif simplejson:
else: obj = simplejson.dumps(items)
raise RuntimeError("missing simplejson") else:
raise RuntimeError("missing simplejson")
if not isinstance(obj,bytes): if not isinstance(obj,bytes):
obj = bytes(obj) obj = bytes(obj)
try: try:
@@ -1928,16 +1930,17 @@ class BaseAdapter(ConnectionPool):
return float(value) return float(value)
def parse_json(self, value, field_type): def parse_json(self, value, field_type):
if not isinstance(value, basestring): if not self.native_json:
raise RuntimeError('json data not a string') if not isinstance(value, basestring):
if isinstance(value, unicode): raise RuntimeError('json data not a string')
value = value.encode('utf-8') if isinstance(value, unicode):
if have_serializers: value = value.encode('utf-8')
value = serializers.loads_json(value) if have_serializers:
elif simplejson: value = serializers.loads_json(value)
value = simplejson.loads(value) elif simplejson:
else: value = simplejson.loads(value)
raise RuntimeError("missing simplejson") else:
raise RuntimeError("missing simplejson")
return value return value
def build_parsemap(self): def build_parsemap(self):
@@ -4959,6 +4962,7 @@ def cleanup(text):
return text return text
class MongoDBAdapter(NoSQLAdapter): class MongoDBAdapter(NoSQLAdapter):
native_json = True
drivers = ('pymongo',) drivers = ('pymongo',)
uploads_in_blob = True uploads_in_blob = True