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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 0a4bad92ca1181605140f832183f1450014efc67
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:avoid-simplejson-encoder
Merge into: launchpad:master
Diff against target: 33 lines (+4/-4)
1 file modified
lib/lp/bugs/browser/buglisting.py (+4/-4)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+431839@code.launchpad.net

Commit message

Use lazr.restful.ResourceJSONEncoder for mustache listings

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/browser/buglisting.py b/lib/lp/bugs/browser/buglisting.py
2index 1a1bdd6..cef7d6e 100644
3--- a/lib/lp/bugs/browser/buglisting.py
4+++ b/lib/lp/bugs/browser/buglisting.py
5@@ -19,15 +19,15 @@ __all__ = [
6 "TextualBugTaskSearchListingView",
7 ]
8
9+import json
10 import os.path
11 from urllib.parse import parse_qs, parse_qsl, quote, urlencode
12
13 import pystache
14 from lazr.delegates import delegate_to
15+from lazr.restful import ResourceJSONEncoder
16 from lazr.restful.interfaces import IJSONRequestCache
17 from lazr.uri import URI
18-from simplejson import dumps
19-from simplejson.encoder import JSONEncoderForHTML
20 from zope.authentication.interfaces import IUnauthenticatedPrincipal
21 from zope.browserpage import ViewPageTemplateFile
22 from zope.component import getAdapter, getUtility, queryMultiAdapter
23@@ -842,8 +842,8 @@ class BugListingBatchNavigator(TableBatchNavigator):
24
25 @property
26 def mustache_listings(self):
27- return "LP.mustache_listings = %s;" % dumps(
28- self.mustache_template, cls=JSONEncoderForHTML
29+ return "LP.mustache_listings = %s;" % json.dumps(
30+ self.mustache_template, cls=ResourceJSONEncoder
31 )
32
33 @property

Subscribers

People subscribed via source and target branches

to status/vote changes: