# HG changeset patch # User Alexandre Fayolle # Date 1271965684 0 # Node ID 84d14ddfae13c0e9fda2cedb60694eabf265757f # Parent 2c3f14bc25904a4e980539375aafef15e53acb92 [python2.6] prefer python2.6's builtin json module over simplejson diff -r 2c3f14bc2590 -r 84d14ddfae13 devtools/testlib.py --- a/devtools/testlib.py Thu Apr 22 19:37:56 2010 +0000 +++ b/devtools/testlib.py Thu Apr 22 19:48:04 2010 +0000 @@ -14,7 +14,10 @@ from math import log from contextlib import contextmanager -import simplejson +try: + import json +except ImportError: + import simplejson as json import yams.schema @@ -483,7 +486,7 @@ def remote_call(self, fname, *args): """remote json call simulation""" - dump = simplejson.dumps + dump = json.dumps args = [dump(arg) for arg in args] req = self.request(fname=fname, pageid='123', arg=args) ctrl = self.vreg['controllers'].select('json', req) diff -r 2c3f14bc2590 -r 84d14ddfae13 goa/goactl.py --- a/goa/goactl.py Thu Apr 22 19:37:56 2010 +0000 +++ b/goa/goactl.py Thu Apr 22 19:48:04 2010 +0000 @@ -17,7 +17,11 @@ def slink_directories(): - import rql, yams, yapps, simplejson, docutils, roman + import rql, yams, yapps, docutils, roman + try: + import json as simplejson + except ImportError: + import simplejson from logilab import common as lgc from logilab import constraint as lgcstr from logilab import mtconverter as lgmtc diff -r 2c3f14bc2590 -r 84d14ddfae13 test/unittest_utils.py --- a/test/unittest_utils.py Thu Apr 22 19:37:56 2010 +0000 +++ b/test/unittest_utils.py Thu Apr 22 19:48:04 2010 +0000 @@ -14,10 +14,13 @@ from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, RepeatList try: - import simplejson + try: + import json + except ImportError: + import simplejson as json from cubicweb.utils import CubicWebJsonEncoder except ImportError: - simplejson = None + json = None class MakeUidTC(TestCase): def test_1(self): @@ -107,11 +110,11 @@ class JSONEncoderTC(TestCase): def setUp(self): - if simplejson is None: - self.skip('simplejson not available') + if json is None: + self.skip('json not available') def encode(self, value): - return simplejson.dumps(value, cls=CubicWebJsonEncoder) + return json.dumps(value, cls=CubicWebJsonEncoder) def test_encoding_dates(self): self.assertEquals(self.encode(datetime.datetime(2009, 9, 9, 20, 30)), diff -r 2c3f14bc2590 -r 84d14ddfae13 utils.py --- a/utils.py Thu Apr 22 19:37:56 2010 +0000 +++ b/utils.py Thu Apr 22 19:48:04 2010 +0000 @@ -339,14 +339,17 @@ return __answer_cache[0] try: - # may not be there if cubicweb-web not installed - from simplejson import dumps, JSONEncoder + try: + # may not be there if cubicweb-web not installed + from json import dumps, JSONEncoder + except ImportError: + from simplejson import dumps, JSONEncoder except ImportError: pass else: class CubicWebJsonEncoder(JSONEncoder): - """define a simplejson encoder to be able to encode yams std types""" + """define a json encoder to be able to encode yams std types""" # _iterencode is the only entry point I've found to use a custom encode # hook early enough: .default() is called if nothing else matched before, diff -r 2c3f14bc2590 -r 84d14ddfae13 view.py --- a/view.py Thu Apr 22 19:37:56 2010 +0000 +++ b/view.py Thu Apr 22 19:48:04 2010 +0000 @@ -12,7 +12,10 @@ from cStringIO import StringIO from warnings import warn -from simplejson import dumps +try: + from json import dumps +except ImportError: + from simplejson import dumps from logilab.common.deprecation import deprecated from logilab.mtconverter import xml_escape diff -r 2c3f14bc2590 -r 84d14ddfae13 web/__init__.py --- a/web/__init__.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/__init__.py Thu Apr 22 19:48:04 2010 +0000 @@ -10,7 +10,10 @@ __docformat__ = "restructuredtext en" _ = unicode -from simplejson import dumps +try: + from json import dumps +except ImportError: + from simplejson import dumps from urllib import quote as urlquote from logilab.common.deprecation import deprecated diff -r 2c3f14bc2590 -r 84d14ddfae13 web/_exceptions.py --- a/web/_exceptions.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/_exceptions.py Thu Apr 22 19:48:04 2010 +0000 @@ -57,5 +57,8 @@ self.reason = reason def dumps(self): - import simplejson - return simplejson.dumps({'reason': self.reason}) + try: + from json import dumps + except ImportError: + from simplejson import dumps + return dumps({'reason': self.reason}) diff -r 2c3f14bc2590 -r 84d14ddfae13 web/application.py --- a/web/application.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/application.py Thu Apr 22 19:48:04 2010 +0000 @@ -385,6 +385,9 @@ self.error_handler(req, ex, tb=False) except Exception, ex: self.error_handler(req, ex, tb=True) + except: + self.critical('Catch all triggered!!!') + self.exception('this is what happened') finally: if req.cnx is not None: try: diff -r 2c3f14bc2590 -r 84d14ddfae13 web/component.py --- a/web/component.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/component.py Thu Apr 22 19:48:04 2010 +0000 @@ -8,7 +8,10 @@ __docformat__ = "restructuredtext en" _ = unicode -from simplejson import dumps +try: + from json import dumps +except ImportError: + from simplejson import dumps from logilab.common.deprecation import class_renamed from logilab.mtconverter import xml_escape diff -r 2c3f14bc2590 -r 84d14ddfae13 web/formwidgets.py --- a/web/formwidgets.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/formwidgets.py Thu Apr 22 19:48:04 2010 +0000 @@ -515,7 +515,6 @@ @classmethod def add_localized_infos(cls, req): """inserts JS variables defining localized months and days""" - # import here to avoid dependancy from cubicweb to simplejson _ = req._ monthnames = [_(mname) for mname in cls.monthnames] daynames = [_(dname) for dname in cls.daynames] diff -r 2c3f14bc2590 -r 84d14ddfae13 web/request.py --- a/web/request.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/request.py Thu Apr 22 19:48:04 2010 +0000 @@ -16,7 +16,10 @@ from urlparse import urlsplit from itertools import count -from simplejson import dumps +try: + from json import dumps +except ImportError: + from simplejson import dumps from rql.utils import rqlvar_maker diff -r 2c3f14bc2590 -r 84d14ddfae13 web/test/unittest_views_basecontrollers.py --- a/web/test/unittest_views_basecontrollers.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/test/unittest_views_basecontrollers.py Thu Apr 22 19:48:04 2010 +0000 @@ -5,7 +5,10 @@ :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses """ -import simplejson +try: + import json +except ImportError: + import simplejson as json from logilab.common.testlib import unittest_main, mock_object @@ -550,7 +553,7 @@ # rql = 'Any T,N WHERE T is Tag, T name N' # ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) # self.assertEquals(ctrl.publish(), -# simplejson.dumps(self.execute(rql).rows)) +# json.dumps(self.execute(rql).rows)) def test_remote_add_existing_tag(self): self.remote_call('tag_entity', self.john.eid, ['python']) @@ -627,14 +630,14 @@ # silly tests def test_external_resource(self): self.assertEquals(self.remote_call('external_resource', 'RSS_LOGO')[0], - simplejson.dumps(self.request().external_resource('RSS_LOGO'))) + json.dumps(self.request().external_resource('RSS_LOGO'))) def test_i18n(self): self.assertEquals(self.remote_call('i18n', ['bimboom'])[0], - simplejson.dumps(['bimboom'])) + json.dumps(['bimboom'])) def test_format_date(self): self.assertEquals(self.remote_call('format_date', '2007-01-01 12:00:00')[0], - simplejson.dumps('2007/01/01')) + json.dumps('2007/01/01')) diff -r 2c3f14bc2590 -r 84d14ddfae13 web/test/unittest_views_baseviews.py --- a/web/test/unittest_views_baseviews.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/test/unittest_views_baseviews.py Thu Apr 22 19:48:04 2010 +0000 @@ -5,7 +5,10 @@ :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses """ -from simplejson import loads +try: + from json import loads +except ImportError: + from simplejson import loads from logilab.common.testlib import unittest_main from logilab.mtconverter import html_unescape diff -r 2c3f14bc2590 -r 84d14ddfae13 web/views/autoform.py --- a/web/views/autoform.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/views/autoform.py Thu Apr 22 19:48:04 2010 +0000 @@ -109,7 +109,10 @@ from warnings import warn -from simplejson import dumps +try: + from json import dumps +except ImportError: + from simplejson import dumps from logilab.mtconverter import xml_escape from logilab.common.decorators import iclassmethod, cached diff -r 2c3f14bc2590 -r 84d14ddfae13 web/views/basecontrollers.py --- a/web/views/basecontrollers.py Thu Apr 22 19:37:56 2010 +0000 +++ b/web/views/basecontrollers.py Thu Apr 22 19:48:04 2010 +0000 @@ -12,7 +12,10 @@ from smtplib import SMTP -import simplejson +try: + import json +except ImportError: + import simplejson as json from logilab.common.decorators import cached from logilab.common.date import strptime @@ -34,7 +37,7 @@ HAS_SEARCH_RESTRICTION = False def jsonize(func): - """decorator to sets correct content_type and calls `simplejson.dumps` on + """decorator to sets correct content_type and calls `json.dumps` on results """ def wrapper(self, *args, **kwargs): @@ -236,7 +239,7 @@ errback = str(self._cw.form.get('__onfailure', 'null')) cbargs = str(self._cw.form.get('__cbargs', 'null')) self._cw.set_content_type('text/html') - jsargs = simplejson.dumps((status, args, entity), cls=CubicWebJsonEncoder) + jsargs = json.dumps((status, args, entity), cls=CubicWebJsonEncoder) return """