dabo Commit
Revision 4552
Date: 2008-10-05 12:44:52 -0700 (Sun, 05 Oct 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4552

Changed:
U   trunk/dabo/lib/__init__.py

Log:
Refactored the imports to better catch cases where simplejson is not installed.


Diff:
Modified: trunk/dabo/lib/__init__.py
===================================================================
--- trunk/dabo/lib/__init__.py  2008-10-05 18:37:54 UTC (rev 4551)
+++ trunk/dabo/lib/__init__.py  2008-10-05 19:44:52 UTC (rev 4552)
@@ -8,25 +8,41 @@
 #      import dabo.lib.ofFunctions as oFox
 
 import uuid
+import dabo
 
+
+def getRandomUUID():
+       return str(uuid.uuid4())
+
+
+def getMachineUUID():
+       return str(uuid.uuid1())
+
+
 try:
-       import dejavuJSON
+       import simplejson
 except:
        jsonConverter = None
        def jsonEncode(val): raise ImportError, "The simplejson module is not 
installed"
        def jsonDecode(val): raise ImportError, "The simplejson module is not 
installed"
 else:
+       import dejavuJSON
        jsonConverter = dejavuJSON.Converter()
        def jsonEncode(val):
                return jsonConverter.dumps(val)
        
        def jsonDecode(val):
-               return jsonConverter.loads(val)
-
-
-def getRandomUUID():
-       return str(uuid.uuid4())
-
-
-def getMachineUUID():
-       return str(uuid.uuid1())
+               ret = None
+               try:
+                       ret = jsonConverter.loads(val)
+               except UnicodeDecodeError:
+                       # Try typical encodings, starting with the default.
+                       for enctype in (dabo.defaultEncoding, "utf-8", 
"latin-1"):
+                               try:
+                                       ret = jsonConverter.loads(val, enctype)
+                                       break
+                               except UnicodeDecodeError:
+                                       continue
+               if ret is None:
+                       raise
+               return ret




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to