From d15f13dcbdcf1dff5df3db9f5fbcdc28154c33ef Mon Sep 17 00:00:00 2001 From: mdipierro Date: Mon, 21 Jan 2013 14:13:05 -0600 Subject: [PATCH] Adapter.native_json --- VERSION | 2 +- gluon/dal.py | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/VERSION b/VERSION index 329b391a..874f6048 100644 --- a/VERSION +++ b/VERSION @@ -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 diff --git a/gluon/dal.py b/gluon/dal.py index cc078046..4d4daa48 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -612,6 +612,7 @@ class ConnectionPool(object): ################################################################################### class BaseAdapter(ConnectionPool): + native_json = False driver = None driver_name = None drivers = () # list of drivers from which to pick @@ -1790,12 +1791,13 @@ class BaseAdapter(ConnectionPool): else: obj = str(obj) elif fieldtype == 'json': - if have_serializers: - obj = serializers.json(obj) - elif simplejson: - obj = simplejson.dumps(items) - else: - raise RuntimeError("missing simplejson") + if not self.native_json: + if have_serializers: + obj = serializers.json(obj) + elif simplejson: + obj = simplejson.dumps(items) + else: + raise RuntimeError("missing simplejson") if not isinstance(obj,bytes): obj = bytes(obj) try: @@ -1928,16 +1930,17 @@ class BaseAdapter(ConnectionPool): return float(value) def parse_json(self, value, field_type): - if not isinstance(value, basestring): - raise RuntimeError('json data not a string') - if isinstance(value, unicode): - value = value.encode('utf-8') - if have_serializers: - value = serializers.loads_json(value) - elif simplejson: - value = simplejson.loads(value) - else: - raise RuntimeError("missing simplejson") + if not self.native_json: + if not isinstance(value, basestring): + raise RuntimeError('json data not a string') + if isinstance(value, unicode): + value = value.encode('utf-8') + if have_serializers: + value = serializers.loads_json(value) + elif simplejson: + value = simplejson.loads(value) + else: + raise RuntimeError("missing simplejson") return value def build_parsemap(self): @@ -4959,6 +4962,7 @@ def cleanup(text): return text class MongoDBAdapter(NoSQLAdapter): + native_json = True drivers = ('pymongo',) uploads_in_blob = True