fixed json odd behavior
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.1-alpha.2+timestamp.2013.01.21.08.39.03
|
Version 2.4.1-alpha.2+timestamp.2013.01.21.14.05.02
|
||||||
|
|||||||
+37
-41
@@ -224,6 +224,13 @@ try:
|
|||||||
have_serializers = True
|
have_serializers = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
have_serializers = False
|
have_serializers = False
|
||||||
|
try:
|
||||||
|
import json as simplejson
|
||||||
|
except ImportError:
|
||||||
|
try:
|
||||||
|
import gluon.contrib.simplejson as simplejson
|
||||||
|
except ImportError:
|
||||||
|
simplejson = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import validators
|
import validators
|
||||||
@@ -1782,16 +1789,13 @@ class BaseAdapter(ConnectionPool):
|
|||||||
obj = obj.isoformat()[:10]
|
obj = obj.isoformat()[:10]
|
||||||
else:
|
else:
|
||||||
obj = str(obj)
|
obj = str(obj)
|
||||||
elif (fieldtype == 'json'):
|
elif fieldtype == 'json':
|
||||||
if not isinstance(obj, basestring):
|
if have_serializers:
|
||||||
if have_serializers:
|
obj = serializers.json(obj)
|
||||||
obj = serializers.json(obj)
|
elif simplejson:
|
||||||
else:
|
obj = simplejson.dumps(items)
|
||||||
try:
|
else:
|
||||||
import json as simplejson
|
raise RuntimeError("missing simplejson")
|
||||||
except ImportError:
|
|
||||||
import gluon.contrib.simplejson as simplejson
|
|
||||||
obj = simplejson.dumps(items)
|
|
||||||
if not isinstance(obj,bytes):
|
if not isinstance(obj,bytes):
|
||||||
obj = bytes(obj)
|
obj = bytes(obj)
|
||||||
try:
|
try:
|
||||||
@@ -1924,17 +1928,16 @@ class BaseAdapter(ConnectionPool):
|
|||||||
return float(value)
|
return float(value)
|
||||||
|
|
||||||
def parse_json(self, value, field_type):
|
def parse_json(self, value, field_type):
|
||||||
if isinstance(value, basestring):
|
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:
|
||||||
else:
|
value = serializers.loads_json(value)
|
||||||
try:
|
elif simplejson:
|
||||||
import json as simplejson
|
value = simplejson.loads(value)
|
||||||
except ImportError:
|
else:
|
||||||
import gluon.contrib.simplejson as simplejson
|
raise RuntimeError("missing simplejson")
|
||||||
value = simplejson.loads(value)
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def build_parsemap(self):
|
def build_parsemap(self):
|
||||||
@@ -4250,16 +4253,13 @@ class NoSQLAdapter(BaseAdapter):
|
|||||||
elif fieldtype == 'blob':
|
elif fieldtype == 'blob':
|
||||||
pass
|
pass
|
||||||
elif fieldtype == 'json':
|
elif fieldtype == 'json':
|
||||||
if isinstance(obj, basestring):
|
obj = self.to_unicode(obj)
|
||||||
obj = self.to_unicode(obj)
|
if have_serializers:
|
||||||
if have_serializers:
|
obj = serializers.loads_json(obj)
|
||||||
obj = serializers.loads_json(obj)
|
elif simplejson:
|
||||||
else:
|
obj = simplejson.loads(obj)
|
||||||
try:
|
else:
|
||||||
import json as simplejson
|
raise RuntimeError("missing simplejson")
|
||||||
except ImportError:
|
|
||||||
import gluon.contrib.simplejson as simplejson
|
|
||||||
obj = simplejson.loads(obj)
|
|
||||||
elif is_string and field_is_type('list:string'):
|
elif is_string and field_is_type('list:string'):
|
||||||
return map(self.to_unicode,obj)
|
return map(self.to_unicode,obj)
|
||||||
elif is_list:
|
elif is_list:
|
||||||
@@ -6792,12 +6792,10 @@ class Row(object):
|
|||||||
return serializers.json(item,
|
return serializers.json(item,
|
||||||
default=default or
|
default=default or
|
||||||
serializers.custom_json)
|
serializers.custom_json)
|
||||||
else:
|
elif simplejson:
|
||||||
try:
|
|
||||||
import json as simplejson
|
|
||||||
except ImportError:
|
|
||||||
import gluon.contrib.simplejson as simplejson
|
|
||||||
return simplejson.dumps(item)
|
return simplejson.dumps(item)
|
||||||
|
else:
|
||||||
|
raise RuntimeError("missing simplejson")
|
||||||
else:
|
else:
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@@ -9733,12 +9731,10 @@ class Rows(object):
|
|||||||
return serializers.json(items,
|
return serializers.json(items,
|
||||||
default=default or
|
default=default or
|
||||||
serializers.custom_json)
|
serializers.custom_json)
|
||||||
else:
|
elif simplejson:
|
||||||
try:
|
|
||||||
import json as simplejson
|
|
||||||
except ImportError:
|
|
||||||
import gluon.contrib.simplejson as simplejson
|
|
||||||
return simplejson.dumps(items)
|
return simplejson.dumps(items)
|
||||||
|
else:
|
||||||
|
raise RuntimeError("missing simplejson")
|
||||||
|
|
||||||
# for consistent naming yet backwards compatible
|
# for consistent naming yet backwards compatible
|
||||||
as_csv = __str__
|
as_csv = __str__
|
||||||
|
|||||||
Reference in New Issue
Block a user