← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Use lazr.restful.ResourceJSONEncoder for mustache listings

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

I'd like to remove `simplejson` as a dependency of Launchpad; for the most part it duplicates `json` from the standard library.  The only exception I've run into is `simplejson.encoder.JSONEncoderForHTML`.  Fortunately, we already ran into this in `lazr.restful`, and so `lazr.restful.ResourceJSONEncoder` is a sufficiently accurate emulation of `simplejson.encoder.JSONEncoderForHTML` that we can use instead (it does a few extra things as well, but that doesn't matter here).

Removing the bulk of trivial uses of `simplejson.dumps` and `simplejson.loads` will be a separate branch.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:avoid-simplejson-encoder into launchpad:master.
diff --git a/lib/lp/bugs/browser/buglisting.py b/lib/lp/bugs/browser/buglisting.py
index 1a1bdd6..cef7d6e 100644
--- a/lib/lp/bugs/browser/buglisting.py
+++ b/lib/lp/bugs/browser/buglisting.py
@@ -19,15 +19,15 @@ __all__ = [
     "TextualBugTaskSearchListingView",
 ]
 
+import json
 import os.path
 from urllib.parse import parse_qs, parse_qsl, quote, urlencode
 
 import pystache
 from lazr.delegates import delegate_to
+from lazr.restful import ResourceJSONEncoder
 from lazr.restful.interfaces import IJSONRequestCache
 from lazr.uri import URI
-from simplejson import dumps
-from simplejson.encoder import JSONEncoderForHTML
 from zope.authentication.interfaces import IUnauthenticatedPrincipal
 from zope.browserpage import ViewPageTemplateFile
 from zope.component import getAdapter, getUtility, queryMultiAdapter
@@ -842,8 +842,8 @@ class BugListingBatchNavigator(TableBatchNavigator):
 
     @property
     def mustache_listings(self):
-        return "LP.mustache_listings = %s;" % dumps(
-            self.mustache_template, cls=JSONEncoderForHTML
+        return "LP.mustache_listings = %s;" % json.dumps(
+            self.mustache_template, cls=ResourceJSONEncoder
         )
 
     @property