← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:avoid-simplejson-for-resource-encoder into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:avoid-simplejson-for-resource-encoder into launchpad:master.

Commit message:
Avoid using simplejson with lazr.restful.ResourceJSONEncoder

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/425734

Now that `ResourceJSONEncoder` is based on `json.JSONEncoder` rather than on `simplejson.encoder.JSONEncoderForHTML`, it no longer supports extra parameters that `simplejson.dumps` wants to pass to it, so use it via the ordinary `json.dumps`.

(In hindsight, lazr.restful 2.0.1 should probably have been 2.1.0 or even 3.0.0 due to this.  But it's unlikely to be worth going back and fixing that now - Launchpad is almost certainly the only significant user of this code.)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:avoid-simplejson-for-resource-encoder into launchpad:master.
diff --git a/lib/lp/bugs/browser/bug.py b/lib/lp/bugs/browser/bug.py
index cbc391c..1759a8e 100644
--- a/lib/lp/bugs/browser/bug.py
+++ b/lib/lp/bugs/browser/bug.py
@@ -26,6 +26,7 @@ __all__ = [
 
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
+import json
 import re
 
 from lazr.enum import (
@@ -40,7 +41,6 @@ from lazr.restful import (
     )
 from lazr.restful.interface import copy_field
 from lazr.restful.interfaces import IJSONRequestCache
-from simplejson import dumps
 from zope import formlib
 from zope.component import (
     getMultiAdapter,
@@ -1007,7 +1007,7 @@ class BugSecrecyEditView(LaunchpadFormView, BugSubscriptionPortletDetails):
                     can_add_package_task_to_bug(bug))
                 self.request.response.setHeader(
                     'content-type', 'application/json')
-                return dumps(
+                return json.dumps(
                     result_data, cls=ResourceJSONEncoder,
                     media_type=EntryResource.JSON_TYPE)
             else:
diff --git a/lib/lp/registry/browser/pillar.py b/lib/lp/registry/browser/pillar.py
index 3f5c29d..7817a7c 100644
--- a/lib/lp/registry/browser/pillar.py
+++ b/lib/lp/registry/browser/pillar.py
@@ -13,13 +13,12 @@ __all__ = [
     'PillarSharingView',
     ]
 
-
+import json
 from operator import attrgetter
 
 from lazr.restful import ResourceJSONEncoder
 from lazr.restful.interfaces import IJSONRequestCache
 from lazr.restful.utils import get_current_web_service_request
-import simplejson
 from zope.component import getUtility
 from zope.interface import (
     implementer,
@@ -342,8 +341,7 @@ class PillarSharingView(LaunchpadView):
 
     @property
     def json_sharing_picker_config(self):
-        return simplejson.dumps(
-            self.sharing_picker_config, cls=ResourceJSONEncoder)
+        return json.dumps(self.sharing_picker_config, cls=ResourceJSONEncoder)
 
     def _getBatchNavigator(self, grantees):
         """Return the batch navigator to be used to batch the grantees."""
diff --git a/lib/lp/services/webapp/publisher.py b/lib/lp/services/webapp/publisher.py
index 9e01c04..dc73ef4 100644
--- a/lib/lp/services/webapp/publisher.py
+++ b/lib/lp/services/webapp/publisher.py
@@ -27,6 +27,7 @@ __all__ = [
 
 from cgi import FieldStorage
 import http.client
+import json
 import re
 from urllib.parse import urlparse
 from wsgiref.headers import Headers
@@ -40,7 +41,6 @@ from lazr.restful.interfaces import IJSONRequestCache
 from lazr.restful.marshallers import URLDereferencingMixin
 from lazr.restful.tales import WebLayerAPI
 from lazr.restful.utils import get_current_browser_request
-import simplejson
 import six
 from zope.app.publisher.xmlrpc import IMethodPublisher
 from zope.component import (
@@ -496,7 +496,7 @@ class LaunchpadView(UserAttributeCache):
             cache['context'] = self.context
         if self.user is None:
             cache = obfuscate_structure(cache)
-        return simplejson.dumps(
+        return json.dumps(
             cache, cls=ResourceJSONEncoder,
             media_type=EntryResource.JSON_TYPE)
 
@@ -1093,7 +1093,7 @@ class RedirectionView(URLDereferencingMixin):
         if self.cache_view:
             return self.cache_view.getCacheJSON()
         else:
-            return simplejson.dumps({})
+            return json.dumps({})
 
     def __call__(self):
         self.request.response.redirect(self.target, status=self.status)
diff --git a/lib/lp/testing/yuixhr.py b/lib/lp/testing/yuixhr.py
index f35a655..5f83617 100644
--- a/lib/lp/testing/yuixhr.py
+++ b/lib/lp/testing/yuixhr.py
@@ -12,6 +12,7 @@ __all__ = [
 
 from fnmatch import fnmatchcase
 import importlib
+import json
 import os
 import sys
 from textwrap import dedent
@@ -20,7 +21,6 @@ import unittest
 
 from lazr.restful import ResourceJSONEncoder
 from lazr.restful.utils import get_current_browser_request
-import simplejson
 from zope.component import getUtility
 from zope.exceptions.exceptionformatter import format_exception
 from zope.interface import implementer
@@ -406,12 +406,11 @@ class YUITestFixtureControllerView(LaunchpadView):
                 'Content-Type', 'application/json')
             # We use the ProxyFactory so that the restful
             # redaction code is always used.
-            result = simplejson.dumps(
-                ProxyFactory(data), cls=ResourceJSONEncoder)
+            result = json.dumps(ProxyFactory(data), cls=ResourceJSONEncoder)
         return result
 
     def renderTEARDOWN(self):
-        data = simplejson.loads(self.request.form['data'])
+        data = json.loads(self.request.form['data'])
         fixtures = self.get_fixtures()
         try:
             for fixture_name in reversed(self.fixtures):

Follow ups