dabo Commit
Revision 5695
Date: 2010-02-18 11:02:46 -0800 (Thu, 18 Feb 2010)
Author: Nate
Trac: http://trac.dabodev.com/changeset/5695
Changed:
U trunk/dabo/lib/__init__.py
Log:
In r5686, we lost some functionality. If simplejson failed to import, we would
set the JsonConverter to None. In 5686, the behavior changed so that the
JsonConverter variable was set to the DejavuConvertor. This converter requires
simplejson (go figure) and will not find it. When it doesn't import simplejson
properly, it would spit out a message about it being required and would exit.
This commit restores the original behavior while keeping in play both the
DejavuConverter and the cjson and json converters from before.
On another note, it looks like 5234 included simplejson in the distro, Maybe
we should be import solely from there and not worrying about the multi-imports?
Diff:
Modified: trunk/dabo/lib/__init__.py
===================================================================
--- trunk/dabo/lib/__init__.py 2010-02-16 21:55:03 UTC (rev 5694)
+++ trunk/dabo/lib/__init__.py 2010-02-18 19:02:46 UTC (rev 5695)
@@ -2,7 +2,7 @@
""" External libraries that can be loaded into Daboized applications.
"""
-# Don't put any import statements here. Code will explicitly import
+# Don't put any import statements here. Code will explicitly import
# what it needs. For example:
# from dabo.lib.ListSorter import ListSorter
# import dabo.lib.ofFunctions as oFox
@@ -27,8 +27,26 @@
except ImportError:
try:
import simplejson as json
- jsonEncode = json.dumps
- jsonDecode = json.loads
+ import dejavuJSON
+ jsonConverter = dejavuJSON.Converter()
+ def jsonEncode(val):
+ return jsonConverter.dumps(val)
+
+ def jsonDecode(val):
+ 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
except ImportError:
# Python 2.6 comes with the json module built-in
try:
@@ -36,27 +54,8 @@
jsonEncode = json.dumps
jsonDecode = json.loads
except ImportError:
- json = None
-
-if not json:
- import dejavuJSON
- jsonConverter = dejavuJSON.Converter()
- def jsonEncode(val):
- return jsonConverter.dumps(val)
-
- def jsonDecode(val):
- 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
-
+ jsonConverter = None
+ def jsonEncode(val):
+ raise ImportError("The cjson, simplejson, or
json modules are not installed")
+ def jsonDecode(val):
+ raise ImportError("The cjson, simplejson, or
json modules are not installed")
_______________________________________________
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]