Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Upgrade ujson to 1.35 #537

Merged
merged 4 commits into from
Jan 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ This document describes changes between each past release.
2.14.1 (unreleased)
-------------------

- Nothing changed yet.
**Protocol**

- Forward slashes (``/``) are not escaped anymore in JSON responses (ref #537)


2.14.0 (2016-01-15)
Expand Down
2 changes: 1 addition & 1 deletion cliquet/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setup_json_serializer(config):
requests.models.json = utils.json

# Override json renderer using ujson
renderer = JSONRenderer(serializer=lambda v, **kw: utils.json.dumps(v))
renderer = JSONRenderer(serializer=utils.json_serializer)
config.add_renderer('json', renderer)


Expand Down
4 changes: 4 additions & 0 deletions cliquet/tests/test_views_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def test_returns_info_about_url_and_version(self):
self.assertEqual(response.json['project_docs'],
'https://cliquet.rtfd.org/')

def test_does_not_escape_forward_slashes(self):
response = self.app.get('/')
self.assertNotIn('\\/', str(response.body))

def test_do_not_returns_eos_if_empty_in_settings(self):
response = self.app.get('/')
self.assertNotIn('eos', response.json)
Expand Down
9 changes: 8 additions & 1 deletion cliquet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
from base64 import b64decode, b64encode
from binascii import hexlify
from six.moves.urllib import parse as urlparse

# ujson is not installable with pypy
try:
try: # pragma: no cover
import ujson as json # NOQA

def json_serializer(v, **kw):
return json.dumps(v, escape_forward_slashes=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm not 100% sure that it is better, but you could do json_serializer = functools.partial(json.dumps, escape_forward_slashes=False)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Telepathy for the win 👍


except ImportError: # pragma: no cover
import json # NOQA

json_serializer = json.dumps

try:
# Register psycopg2cffi as psycopg2
from psycopg2cffi import compat
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
]
else:
# ujson is not pypy compliant, as it uses the CPython C API
REQUIREMENTS.append('ujson')
REQUIREMENTS.append('ujson >= 1.35')
POSTGRESQL_REQUIRES = [
'SQLAlchemy',
'psycopg2>2.5',
Expand Down