dabo Commit
Revision 5235
Date: 2009-05-27 22:20:59 -0700 (Wed, 27 May 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5235
Changed:
U trunk/dabo/dApp.py
U trunk/dabo/lib/__init__.py
D trunk/dabo/lib/simplejson/
Log:
Reverted the changes made yesterday to incorporate simplejson. Instead, I added
a workaround to return the data in plain string form if simplejson is not
available.
Diff:
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2009-05-27 04:18:09 UTC (rev 5234)
+++ trunk/dabo/dApp.py 2009-05-28 05:20:59 UTC (rev 5235)
@@ -30,10 +30,11 @@
try:
import simplejson
except ImportError:
- # Not installed on the user's Python; use the included version
- from dabo.lib import simplejson as simplejson
+ # Not installed on the user's Python
+ simplejson = None
+
class Collection(list):
""" Collection : Base class for the various collection
classes used in the app object.
@@ -559,9 +560,13 @@
if runCheck:
currVers = self._currentUpdateVersion()
# See if there is a later version
- url = "%s/check/%s" % (dabo.webupdate_urlbase, currVers)
+ if simplejson:
+ # It's installed
+ url = "%s/check/%s" % (dabo.webupdate_urlbase,
currVers)
+ else:
+ url = "%s/checkNoJson/%s" %
(dabo.webupdate_urlbase, currVers)
try:
- resp =
simplejson.loads(urllib2.urlopen(url).read())
+ resp = urllib2.urlopen(url).read()
except urllib2.URLError, e:
# Could not connect
dabo.errorLog.write(_("Could not connect to the
Dabo servers: %s") % e)
@@ -571,6 +576,12 @@
except StandardError, e:
dabo.errorLog.write(_("Failed to open URL
'%(url)s'. Error: %(e)s") % locals())
return e
+ if simplejson:
+ resp = simplejson.loads(resp)
+ else:
+ # Sucks using eval(), but that's really the
only choice without simplejson
+ # (or rewriting yet again).
+ resp = eval(resp)
prf.setValue("last_check", now)
return (firstTime, resp)
Modified: trunk/dabo/lib/__init__.py
===================================================================
--- trunk/dabo/lib/__init__.py 2009-05-27 04:18:09 UTC (rev 5234)
+++ trunk/dabo/lib/__init__.py 2009-05-28 05:20:59 UTC (rev 5235)
@@ -7,8 +7,6 @@
# from dabo.lib.ListSorter import ListSorter
# import dabo.lib.ofFunctions as oFox
-import os
-import sys
import uuid
import dabo
@@ -23,30 +21,31 @@
try:
import simplejson
-except ImportError:
- # Not installed in site-packages; use the included version
- pth = os.path.split(dabo.__file__)[0]
- sys.path.append("%s/lib" % pth)
- 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):
+ 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
-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
-
_______________________________________________
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]