changeset 2258:8a3a1a59a050 beta

Fixed simplejson import on python 2.5
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 11 May 2012 01:30:19 +0200
parents 790398822cad
children 90431eda6608 30ab2e403a20
files rhodecode/lib/ext_json.py
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/ext_json.py	Thu May 10 20:21:05 2012 +0200
+++ b/rhodecode/lib/ext_json.py	Fri May 11 01:30:19 2012 +0200
@@ -81,22 +81,24 @@
     _sj = None
 
 
-# simplejson not found try out regular json module
-import json as _json
-
+try:
+    # simplejson not found try out regular json module
+    import json as _json
 
-# extended JSON encoder for json
-class ExtendedEncoder(_json.JSONEncoder):
-    def default(self, obj):
-        try:
-            return _obj_dump(obj)
-        except NotImplementedError:
-            pass
-        return _json.JSONEncoder.default(self, obj)
-# monkey-patch JSON encoder to use extended version
-_json.dumps = functools.partial(_json.dumps, cls=ExtendedEncoder)
-_json.dump = functools.partial(_json.dump, cls=ExtendedEncoder)
-stdlib = _json
+    # extended JSON encoder for json
+    class ExtendedEncoder(_json.JSONEncoder):
+        def default(self, obj):
+            try:
+                return _obj_dump(obj)
+            except NotImplementedError:
+                pass
+            return _json.JSONEncoder.default(self, obj)
+    # monkey-patch JSON encoder to use extended version
+    _json.dumps = functools.partial(_json.dumps, cls=ExtendedEncoder)
+    _json.dump = functools.partial(_json.dump, cls=ExtendedEncoder)
+    stdlib = _json
+except ImportError:
+    _json = None
 
 # set all available json modules
 simplejson = _sj