utils.py
changeset 5940 0e3ae19b181a
parent 5883 7a5f370c5be1
child 6044 9e48ebd5400c
--- a/utils.py	Thu Jul 08 12:54:28 2010 +0200
+++ b/utils.py	Thu Jul 08 13:33:40 2010 +0200
@@ -327,12 +327,13 @@
 
 try:
     # may not be there if cubicweb-web not installed
-    if sys.version_info < (2,6):
+    if sys.version_info < (2, 6):
         import simplejson as json
     else:
         import json
 except ImportError:
-    pass
+    json_dumps = None
+
 else:
 
     class CubicWebJsonEncoder(json.JSONEncoder):
@@ -360,6 +361,9 @@
                 # just return None in those cases.
                 return None
 
+    def json_dumps(value):
+        return json.dumps(value, cls=CubicWebJsonEncoder)
+
 
 @deprecated('[3.7] merge_dicts is deprecated')
 def merge_dicts(dict1, dict2):