merge stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 23 Apr 2010 17:32:47 +0200
branchstable
changeset 5395 e0ab7433e640
parent 5394 105011657405 (current diff)
parent 5392 899d93e4dbe0 (diff)
child 5399 03c641ae00a6
merge
--- a/cwconfig.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/cwconfig.py	Fri Apr 23 17:32:47 2010 +0200
@@ -226,7 +226,7 @@
       }),
     ('short-line-size',
      {'type' : 'int',
-      'default': 40,
+      'default': 80,
       'help': _('maximum number of characters in short description'),
       'group': 'navigation',
       }),
--- a/devtools/testlib.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/devtools/testlib.py	Fri Apr 23 17:32:47 2010 +0200
@@ -14,11 +14,6 @@
 from math import log
 from contextlib import contextmanager
 
-try:
-    import json
-except ImportError:
-    import simplejson as json
-
 import yams.schema
 
 from logilab.common.testlib import TestCase, InnerTest
@@ -35,7 +30,7 @@
 from cubicweb.web import Redirect, application
 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS
 from cubicweb.devtools import fake, htmlparser
-
+from cubicweb.utils import json
 
 # low-level utilities ##########################################################
 
--- a/test/unittest_utils.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/test/unittest_utils.py	Fri Apr 23 17:32:47 2010 +0200
@@ -14,11 +14,7 @@
 from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, RepeatList
 
 try:
-    try:
-        import json 
-    except ImportError:
-        import simplejson as json
-    from cubicweb.utils import CubicWebJsonEncoder
+    from cubicweb.utils import CubicWebJsonEncoder, json
 except ImportError:
     json = None
 
--- a/utils.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/utils.py	Fri Apr 23 17:32:47 2010 +0200
@@ -240,7 +240,7 @@
         if self.jsvars:
             w(u'<script type="text/javascript"><!--//--><![CDATA[//><!--\n')
             for var, value, override in self.jsvars:
-                vardecl = u'%s = %s;' % (var, dumps(value))
+                vardecl = u'%s = %s;' % (var, json.dumps(value))
                 if not override:
                     vardecl = (u'if (typeof %s == "undefined") {%s}' %
                                (var, vardecl))
@@ -339,16 +339,16 @@
     return __answer_cache[0]
 
 try:
-    try:
-        # may not be there if cubicweb-web not installed
-        from json import dumps, JSONEncoder
-    except ImportError:
-        from simplejson import dumps, JSONEncoder
+    # may not be there if cubicweb-web not installed
+    if sys.version_info < (2,6):
+        import simplejson as json
+    else:
+        import json
 except ImportError:
     pass
 else:
 
-    class CubicWebJsonEncoder(JSONEncoder):
+    class CubicWebJsonEncoder(json.JSONEncoder):
         """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
@@ -356,14 +356,14 @@
         # .iterencode() is called once on the main structure to encode and then
         # never gets called again.
         # For the record, our main use case is in FormValidateController with:
-        #   dumps((status, args, entity), cls=CubicWebJsonEncoder)
+        #   json.dumps((status, args, entity), cls=CubicWebJsonEncoder)
         # where we want all the entity attributes, including eid, to be part
         # of the json object dumped.
         # This would have once more been easier if Entity didn't extend dict.
         def _iterencode(self, obj, markers=None):
             if hasattr(obj, '__json_encode__'):
                 obj = obj.__json_encode__()
-            return JSONEncoder._iterencode(self, obj, markers)
+            return json.JSONEncoder._iterencode(self, obj, markers)
 
         def default(self, obj):
             if isinstance(obj, datetime.datetime):
@@ -377,7 +377,7 @@
             elif isinstance(obj, decimal.Decimal):
                 return float(obj)
             try:
-                return JSONEncoder.default(self, obj)
+                return json.JSONEncoder.default(self, obj)
             except TypeError:
                 # we never ever want to fail because of an unknown type,
                 # just return None in those cases.
--- a/view.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/view.py	Fri Apr 23 17:32:47 2010 +0200
@@ -12,11 +12,7 @@
 from cStringIO import StringIO
 from warnings import warn
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
+from cubicweb.utils import json
 from logilab.common.deprecation import deprecated
 from logilab.mtconverter import xml_escape
 
@@ -487,11 +483,11 @@
     def build_update_js_call(self, cbname, msg):
         rql = self.cw_rset.printable_rql()
         return "javascript:userCallbackThenUpdateUI('%s', '%s', %s, %s, '%s', '%s')" % (
-            cbname, self.id, dumps(rql), dumps(msg),
+            cbname, self.id, json.dumps(rql), json.dumps(msg),
             self.__registry__, self.div_id())
 
     def build_reload_js_call(self, cbname, msg):
-        return "javascript:userCallbackThenReloadPage('%s', %s)" % (cbname, dumps(msg))
+        return "javascript:userCallbackThenReloadPage('%s', %s)" % (cbname, json.dumps(msg))
 
     build_js = build_update_js_call # expect updatable component by default
 
--- a/web/__init__.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/__init__.py	Fri Apr 23 17:32:47 2010 +0200
@@ -10,10 +10,14 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
+import sys
+if sys.version_info < (2,6):
+    import simplejson as json
+else:
+    import json
+
+dumps = json.dumps
+
 from urllib import quote as urlquote
 
 from logilab.common.deprecation import deprecated
--- a/web/_exceptions.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/_exceptions.py	Fri Apr 23 17:32:47 2010 +0200
@@ -57,8 +57,5 @@
         self.reason = reason
 
     def dumps(self):
-        try:
-            from json import dumps
-        except ImportError:
-            from simplejson import dumps
-        return dumps({'reason': self.reason})
+        from cubicweb.web import json
+        return json.dumps({'reason': self.reason})
--- a/web/component.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/component.py	Fri Apr 23 17:32:47 2010 +0200
@@ -8,15 +8,11 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from logilab.common.deprecation import class_renamed
 from logilab.mtconverter import xml_escape
 
 from cubicweb import role
+from cubicweb.web import json
 from cubicweb.view import Component
 from cubicweb.selectors import (
     paginated_rset, one_line_rset, primary_view, match_context_prop,
@@ -125,8 +121,8 @@
             rql = params.pop('rql', self.cw_rset.printable_rql())
             # latest 'true' used for 'swap' mode
             url = 'javascript: replacePageChunk(%s, %s, %s, %s, true)' % (
-                dumps(params.get('divid', 'paginated-content')),
-                dumps(rql), dumps(params.pop('vid', None)), dumps(params))
+                json.dumps(params.get('divid', 'paginated-content')),
+                json.dumps(rql), json.dumps(params.pop('vid', None)), json.dumps(params))
         else:
             url = self._cw.build_url(path, **params)
         return url
--- a/web/request.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/request.py	Fri Apr 23 17:32:47 2010 +0200
@@ -16,11 +16,6 @@
 from urlparse import urlsplit
 from itertools import count
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from rql.utils import rqlvar_maker
 
 from logilab.common.decorators import cached
@@ -33,7 +28,8 @@
 from cubicweb.utils import SizeConstrainedList, HTMLHead, make_uid
 from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE_NOEXT
 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit,
-                          RequestError, StatusResponse)
+                          RequestError, StatusResponse, json)
+dumps = json.dumps
 
 _MARKER = object()
 
--- a/web/test/unittest_views_basecontrollers.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/test/unittest_views_basecontrollers.py	Fri Apr 23 17:32:47 2010 +0200
@@ -5,10 +5,6 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
-try:
-    import json
-except ImportError:
-    import simplejson as json
 
 from logilab.common.testlib import unittest_main, mock_object
 
@@ -16,7 +12,7 @@
 from cubicweb.view import STRICT_DOCTYPE
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.uilib import rql_for_eid
-from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError
+from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError, json
 from cubicweb.entities.authobjs import CWUser
 from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes
 u = unicode
--- a/web/test/unittest_views_baseviews.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/test/unittest_views_baseviews.py	Fri Apr 23 17:32:47 2010 +0200
@@ -5,11 +5,6 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
-try:
-    from json import loads
-except ImportError:
-    from simplejson import loads
-
 from logilab.common.testlib import unittest_main
 from logilab.mtconverter import html_unescape
 
@@ -17,6 +12,8 @@
 
 from cubicweb.web.htmlwidgets import TableWidget
 from cubicweb.web.views import vid_from_rset
+from cubicweb.web import json
+loads = json.loads
 
 def loadjson(value):
     return loads(html_unescape(value))
--- a/web/views/autoform.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/autoform.py	Fri Apr 23 17:32:47 2010 +0200
@@ -109,11 +109,6 @@
 
 from warnings import warn
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from logilab.mtconverter import xml_escape
 from logilab.common.decorators import iclassmethod, cached
 
@@ -123,7 +118,7 @@
 from cubicweb.selectors import (
     match_kwargs, match_form_params, non_final_entity,
     specified_etype_implements)
-from cubicweb.web import stdmsgs, uicfg, eid_param, \
+from cubicweb.web import stdmsgs, uicfg, eid_param, dumps, \
      form as f, formwidgets as fw, formfields as ff
 from cubicweb.web.views import forms
 
--- a/web/views/basecontrollers.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/basecontrollers.py	Fri Apr 23 17:32:47 2010 +0200
@@ -12,11 +12,6 @@
 
 from smtplib import SMTP
 
-try:
-    import json
-except ImportError:
-    import simplejson as json
-
 from logilab.common.decorators import cached
 from logilab.common.date import strptime
 
@@ -25,7 +20,7 @@
 from cubicweb.utils import CubicWebJsonEncoder
 from cubicweb.selectors import authenticated_user, match_form_params
 from cubicweb.mail import format_mail
-from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed, json_dumps
+from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed, json_dumps, json
 from cubicweb.web.controller import Controller
 from cubicweb.web.views import vid_from_rset
 from cubicweb.web.views.formrenderers import FormRenderer
--- a/web/views/baseviews.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/baseviews.py	Fri Apr 23 17:32:47 2010 +0200
@@ -311,7 +311,8 @@
 
     def call(self, **kwargs):
         """display a list of entities by calling their <item_vid> view"""
-        if not 'vtitle' in self._cw.form:
+        showtitle = kwargs.pop('showtitle', not 'vtitle' in self._cw.form)
+        if showtitle:
             self.w(u'<h1>%s</h1>' % self.title)
         super(SameETypeListView, self).call(**kwargs)
 
--- a/web/views/editforms.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/editforms.py	Fri Apr 23 17:32:47 2010 +0200
@@ -11,11 +11,6 @@
 
 from copy import copy
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from logilab.mtconverter import xml_escape
 from logilab.common.decorators import cached
 
@@ -23,7 +18,7 @@
                                 specified_etype_implements, implements, yes)
 from cubicweb.view import EntityView
 from cubicweb import tags
-from cubicweb.web import uicfg, stdmsgs, eid_param, \
+from cubicweb.web import uicfg, stdmsgs, eid_param, dumps, \
      formfields as ff, formwidgets as fw
 from cubicweb.web.form import FormViewMixIn, FieldNotFound
 from cubicweb.web.views import forms
--- a/web/views/facets.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/facets.py	Fri Apr 23 17:32:47 2010 +0200
@@ -7,16 +7,12 @@
 """
 __docformat__ = "restructuredtext en"
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from logilab.mtconverter import xml_escape
 
 from cubicweb.appobject import objectify_selector
 from cubicweb.selectors import (non_final_entity, multi_lines_rset,
                                 match_context_prop, yes, relation_possible)
+from cubicweb.web import dumps
 from cubicweb.web.box import BoxTemplate
 from cubicweb.web.facet import (AbstractFacet, FacetStringWidget, RelationFacet,
                                 prepare_facets_rqlst, filter_hiddens, _cleanup_rqlst,
--- a/web/views/formrenderers.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/formrenderers.py	Fri Apr 23 17:32:47 2010 +0200
@@ -25,15 +25,10 @@
 from logilab.common import dictattr
 from logilab.mtconverter import xml_escape
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from cubicweb import tags
 from cubicweb.appobject import AppObject
 from cubicweb.selectors import implements, yes
-from cubicweb.web import eid_param, formwidgets as fwdgs
+from cubicweb.web import dumps, eid_param, formwidgets as fwdgs
 
 
 def checkbox(name, value, attrs='', checked=None):
--- a/web/views/igeocodable.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/igeocodable.py	Fri Apr 23 17:32:47 2010 +0200
@@ -7,14 +7,10 @@
 """
 __docformat__ = "restructuredtext en"
 
-try:
-    import json
-except ImportError:
-    import simplejson as json
-
 from cubicweb.interfaces import IGeocodable
 from cubicweb.view import EntityView
 from cubicweb.selectors import implements
+from cubicweb.web import json
 
 class GeocodingJsonView(EntityView):
     __regid__ = 'geocoding-json'
--- a/web/views/plots.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/plots.py	Fri Apr 23 17:32:47 2010 +0200
@@ -7,17 +7,13 @@
 """
 __docformat__ = "restructuredtext en"
 
-try:
-    from json import dumps
-except ImportError:
-    from simplejson import dumps
-
 from logilab.common.date import datetime2ticks
 from logilab.mtconverter import xml_escape
 
 from cubicweb.utils import UStringIO
 from cubicweb.appobject import objectify_selector
 from cubicweb.selectors import multi_columns_rset
+from cubicweb.web import dumps
 from cubicweb.web.views import baseviews
 
 @objectify_selector
--- a/web/views/timeline.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/timeline.py	Fri Apr 23 17:32:47 2010 +0200
@@ -9,16 +9,12 @@
 """
 __docformat__ = "restructuredtext en"
 
-try:
-    import json
-except ImportError:
-    import simplejson as json
-
 from logilab.mtconverter import xml_escape
 
 from cubicweb.interfaces import ICalendarable
 from cubicweb.selectors import implements
 from cubicweb.view import EntityView, StartupView
+from cubicweb.web import json
 
 _ = unicode
 
--- a/web/views/treeview.py	Fri Apr 23 17:31:46 2010 +0200
+++ b/web/views/treeview.py	Fri Apr 23 17:32:47 2010 +0200
@@ -7,16 +7,12 @@
 """
 __docformat__ = "restructuredtext en"
 
-try:
-    import json
-except ImportError:
-    import simplejson as json
-
 from logilab.mtconverter import xml_escape
 from cubicweb.utils import make_uid
 from cubicweb.interfaces import ITree
 from cubicweb.selectors import implements
 from cubicweb.view import EntityView
+from cubicweb.web import json
 
 def treecookiename(treeid):
     return str('%s-treestate' % treeid)