Hello community,
here is the log from the commit of package python-canonicaljson for
openSUSE:Factory checked in at 2020-08-14 10:04:15
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-canonicaljson (Old)
and /work/SRC/openSUSE:Factory/.python-canonicaljson.new.3399 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-canonicaljson"
Fri Aug 14 10:04:15 2020 rev:6 rq:826608 version:1.2.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-canonicaljson/python-canonicaljson.changes
2019-03-01 16:48:16.301779873 +0100
+++
/work/SRC/openSUSE:Factory/.python-canonicaljson.new.3399/python-canonicaljson.changes
2020-08-14 10:04:21.625318188 +0200
@@ -1,0 +2,11 @@
+Thu Aug 13 21:28:31 UTC 2020 - Marcus Rueckert <[email protected]>
+
+- Update to 1.2.0:
+ - JSON from the standard library is used automatically on PyPy.
+ - Support for Python versions which are end-of-lifed was dropped,
+ Python >= 3.5 is supported and tested in continuous
+ integration.
+ - An API to configure the underlying JSON library was added
+ (set_json_library).
+
+-------------------------------------------------------------------
Old:
----
v1.1.4.tar.gz
New:
----
v1.2.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-canonicaljson.spec ++++++
--- /var/tmp/diff_new_pack.3S0IbU/_old 2020-08-14 10:04:26.589320707 +0200
+++ /var/tmp/diff_new_pack.3S0IbU/_new 2020-08-14 10:04:26.593320708 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-canonicaljson
#
-# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -28,7 +28,7 @@
%define github_user matrix-org
%define short_name canonicaljson
Name: python-%{short_name}%{psuffix}
-Version: 1.1.4
+Version: 1.2.0
Release: 0
Summary: Canonical JSON for Python
License: Apache-2.0
++++++ v1.1.4.tar.gz -> v1.2.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/.gitignore
new/python-canonicaljson-1.2.0/.gitignore
--- old/python-canonicaljson-1.1.4/.gitignore 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/.gitignore 2020-07-27 17:42:49.000000000
+0200
@@ -6,3 +6,4 @@
*.pyc
/build/
/dist/
+.python-version
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/.travis/install.sh
new/python-canonicaljson-1.2.0/.travis/install.sh
--- old/python-canonicaljson-1.1.4/.travis/install.sh 2018-05-23
10:28:32.000000000 +0200
+++ new/python-canonicaljson-1.2.0/.travis/install.sh 2020-07-27
17:42:49.000000000 +0200
@@ -5,13 +5,8 @@
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
# osx build uses a 'generic' language which doesn't come with pip
case "${TOXENV}" in
- py27)
- # for py27, use the system python
- sudo `dirname $0`/get-pip.py
- sudo pip install tox
- ;;
- py36)
- # for py36, use homebrew python, which comes with pip.
+ py38)
+ # for py38, use homebrew python, which comes with pip.
# see also https://docs.brew.sh/Homebrew-and-Python
brew upgrade python
pip3 install tox
@@ -24,5 +19,3 @@
else
pip install tox
fi
-
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/.travis.yml
new/python-canonicaljson-1.2.0/.travis.yml
--- old/python-canonicaljson-1.1.4/.travis.yml 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/.travis.yml 2020-07-27 17:42:49.000000000
+0200
@@ -5,40 +5,30 @@
matrix:
include:
- - python: 2.7
+ - python: 3.6
env: TOXENV=packaging
-
- - python: 2.7
- env: TOXENV=pep8
- python: 3.6
- env: TOXENV=py3pep8
-
- - python: 2.7
- env: TOXENV=py27
-
- - os: osx
- language: generic
- env: TOXENV=py27
-
- - python: 3.3
- env: TOXENV=py33
+ env: TOXENV=pep8
- - python: 3.4
- env: TOXENV=py34
-
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
+ - python: 3.7
+ env: TOXENV=py37
+
+ - python: 3.8
+ env: TOXENV=py38
+
- os: osx
language: generic
- env: TOXENV=py36
+ env: TOXENV=py38
- - python: pypy
- env: TOXENV=pypy
+ - python: pypy3
+ env: TOXENV=pypy3
install:
- ./.travis/install.sh
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/CHANGES.md
new/python-canonicaljson-1.2.0/CHANGES.md
--- old/python-canonicaljson-1.1.4/CHANGES.md 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/CHANGES.md 2020-07-27 17:42:49.000000000
+0200
@@ -1,3 +1,10 @@
+Version 1.2.0 released 2020-07-27
+
+* JSON from the standard library is used automatically on PyPy.
+* Support for Python versions which are end-of-lifed was dropped, Python >= 3.5
+ is supported and tested in continuous integration.
+* An API to configure the underlying JSON library was added
(`set_json_library`).
+
Version 1.1.4 released 2018-05-23
* Fix error when encoding non-BMP characters on UCS-2 python builds
@@ -21,9 +28,9 @@
Version 1.1.0 released 2018-04-06
* Significant performance improvements
- (https://github.com/matrix-org/python-canonicaljson/pull/7,
- https://github.com/matrix-org/python-canonicaljson/pull/8,
- https://github.com/matrix-org/python-canonicaljson/pull/9)
+ ([\#7](https://github.com/matrix-org/python-canonicaljson/pull/7),
+ [\#8](https://github.com/matrix-org/python-canonicaljson/pull/8),
+ [\#9](https://github.com/matrix-org/python-canonicaljson/pull/9))
Version 1.0.0 released 2015-08-21
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/README.rst
new/python-canonicaljson-1.2.0/README.rst
--- old/python-canonicaljson-1.1.4/README.rst 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/README.rst 2020-07-27 17:42:49.000000000
+0200
@@ -20,6 +20,8 @@
* Encodes the JSON as UTF-8.
* Can encode ``frozendict`` immutable dictionaries.
+Supports Python versions 3.5 and newer.
+
.. _`RFC 7159`: https://tools.ietf.org/html/rfc7159
Installing
@@ -36,3 +38,18 @@
import canonicaljson
assert canonicaljson.encode_canonical_json({}) == b'{}'
+
+The underlying JSON implementation can be choosen with the following:
+
+.. code:: python
+
+ import json
+ import canonicaljson
+ canonicaljson.set_json_library(json)
+
+.. note::
+
+ By default canonicaljson uses `simplejson`_ under the hood (except for
PyPy,
+ which uses the standard library json module).
+
+.. _simplejson: https://simplejson.readthedocs.io/
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/canonicaljson.py
new/python-canonicaljson-1.2.0/canonicaljson.py
--- old/python-canonicaljson-1.1.4/canonicaljson.py 2018-05-23
10:28:32.000000000 +0200
+++ new/python-canonicaljson-1.2.0/canonicaljson.py 2020-07-27
17:42:49.000000000 +0200
@@ -16,15 +16,11 @@
# limitations under the License.
import re
-from six import unichr, PY2, PY3
-
-# using simplejson rather than regular json gives approximately a 100%
-# performance improvement (as measured on python 2.7.12/simplejson 3.13.2)
-import simplejson as json
+import platform
from frozendict import frozendict
-__version__ = '1.1.4'
+__version__ = '1.2.0'
def _default(obj):
@@ -43,19 +39,37 @@
# (in any case, simplejson's ensure_ascii doesn't get U+2028 and U+2029 right,
# as per https://github.com/simplejson/simplejson/issues/206).
#
-_canonical_encoder = json.JSONEncoder(
- ensure_ascii=True,
- separators=(',', ':'),
- sort_keys=True,
- default=_default,
-)
-
-_pretty_encoder = json.JSONEncoder(
- ensure_ascii=True,
- indent=4,
- sort_keys=True,
- default=_default,
-)
+
+# Declare these in the module scope, but they get configured in
+# set_json_library.
+_canonical_encoder = None
+_pretty_encoder = None
+
+
+def set_json_library(json_lib):
+ """
+ Set the underlying JSON library that canonicaljson uses to json_lib.
+
+ Params:
+ json_lib: The module to use for JSON encoding. Must have a
+ `JSONEncoder` property.
+ """
+ global _canonical_encoder
+ _canonical_encoder = json_lib.JSONEncoder(
+ ensure_ascii=True,
+ separators=(',', ':'),
+ sort_keys=True,
+ default=_default,
+ )
+
+ global _pretty_encoder
+ _pretty_encoder = json_lib.JSONEncoder(
+ ensure_ascii=True,
+ indent=4,
+ sort_keys=True,
+ default=_default,
+ )
+
# This regexp matches either `\uNNNN` or `\\`. We match '\\' (and leave it
# unchanged) to make sure that the regex doesn't accidentally capture the uNNNN
@@ -75,11 +89,11 @@
"""
# make the fast path fast: if there are no matches in the string, the
- # whole thing is ascii. On python 2, that means we're done. On python 3,
- # we have to turn it into a bytes, which is quickest with encode('utf-8')
+ # whole thing is ascii. We have to turn it into a bytes, which is
+ # quickest with encode('utf-8')
m = _U_ESCAPE.search(s)
if not m:
- return s if PY2 else s.encode('utf-8')
+ return s.encode('utf-8')
# appending to a string (or a bytes) is slooow, so we accumulate sections
# of string result in 'chunks', and join them all together later.
@@ -105,30 +119,24 @@
else:
# \uNNNN, but we have to watch out for surrogate pairs.
#
- # On python 2, str.encode("utf-8") will decode utf-16 surrogates
- # before re-encoding, so it's fine for us to pass the surrogates
- # through. (Indeed we must, to deal with UCS-2 python builds, per
- # https://github.com/matrix-org/python-canonicaljson/issues/12).
- #
- # On python 3, str.encode("utf-8") complains about surrogates, so
- # we have to unpack them.
+ # str.encode("utf-8") complains about surrogates, so we have to
+ # unpack them.
c = int(g, 16)
if c < 0x20:
# leave as a \uNNNN escape
chunks.append(s[pos:end])
else:
- if PY3: # pragma nocover
- if c & 0xfc00 == 0xd800 and s[end:end + 2] == '\\u':
- esc2 = s[end + 2:end + 6]
- c2 = int(esc2, 16)
- if c2 & 0xfc00 == 0xdc00:
- c = 0x10000 + (((c - 0xd800) << 10) |
- (c2 - 0xdc00))
- end += 6
+ if c & 0xfc00 == 0xd800 and s[end:end + 2] == '\\u':
+ esc2 = s[end + 2:end + 6]
+ c2 = int(esc2, 16)
+ if c2 & 0xfc00 == 0xdc00:
+ c = 0x10000 + (((c - 0xd800) << 10) |
+ (c2 - 0xdc00))
+ end += 6
chunks.append(s[pos:start])
- chunks.append(unichr(c))
+ chunks.append(chr(c))
pos = end
m = _U_ESCAPE.search(s, pos)
@@ -156,3 +164,20 @@
"""Encodes the JSON object dict as human readable ascii bytes."""
return _pretty_encoder.encode(json_object).encode("ascii")
+
+
+if platform.python_implementation() == "PyPy": # pragma: no cover
+ # pypy ships with an optimised JSON encoder/decoder that is faster than
+ # simplejson's C extension.
+ import json
+else: # pragma: no cover
+ # using simplejson rather than regular json on CPython for backwards
+ # compatibility (simplejson on Python 3.5 handles parsing of bytes while
+ # the standard library json does not).
+ #
+ # Note that it seems performance is on par or better using json from the
+ # standard library as of Python 3.7.
+ import simplejson as json
+
+# Set the JSON library to the backwards compatible version.
+set_json_library(json)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/debian/changelog
new/python-canonicaljson-1.2.0/debian/changelog
--- old/python-canonicaljson-1.1.4/debian/changelog 2018-05-23
10:28:32.000000000 +0200
+++ new/python-canonicaljson-1.2.0/debian/changelog 2020-07-27
17:42:49.000000000 +0200
@@ -1,4 +1,4 @@
-python-canonicaljson (1.1.4) UNRELEASED; urgency=medium
+python-canonicaljson (1.1.4) stable; urgency=medium
* Fix error when encoding non-BMP characters on UCS-2 python builds
(fixes issue #12).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/setup.cfg
new/python-canonicaljson-1.2.0/setup.cfg
--- old/python-canonicaljson-1.1.4/setup.cfg 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/setup.cfg 1970-01-01 01:00:00.000000000
+0100
@@ -1,3 +0,0 @@
-[bdist_wheel]
-# we can generate universal wheels that support both Python 2 and Python 3.
-universal=1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/setup.py
new/python-canonicaljson-1.2.0/setup.py
--- old/python-canonicaljson-1.1.4/setup.py 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/setup.py 2020-07-27 17:42:49.000000000
+0200
@@ -48,7 +48,6 @@
install_requires=[
"simplejson>=3.6.5",
"frozendict>=1.0",
- "six",
],
zip_safe=True,
long_description=read_file(("README.rst",)),
@@ -57,6 +56,7 @@
author_email='[email protected]',
url='https://github.com/matrix-org/python-canonicaljson',
license='Apache License, Version 2.0',
+ python_requires="~=3.5",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/test_canonicaljson.py
new/python-canonicaljson-1.2.0/test_canonicaljson.py
--- old/python-canonicaljson-1.1.4/test_canonicaljson.py 2018-05-23
10:28:32.000000000 +0200
+++ new/python-canonicaljson-1.2.0/test_canonicaljson.py 2020-07-27
17:42:49.000000000 +0200
@@ -18,57 +18,59 @@
from canonicaljson import (
encode_canonical_json,
encode_pretty_printed_json,
+ set_json_library,
)
from frozendict import frozendict
import unittest
+from unittest import mock
class TestCanonicalJson(unittest.TestCase):
def test_encode_canonical(self):
- self.assertEquals(encode_canonical_json({}), b'{}')
+ self.assertEqual(encode_canonical_json({}), b'{}')
# ctrl-chars should be encoded.
- self.assertEquals(
+ self.assertEqual(
encode_canonical_json(u"text\u0003\r\n"),
b'"text\\u0003\\r\\n"',
)
# quotes and backslashes should be escaped.
- self.assertEquals(
+ self.assertEqual(
encode_canonical_json(r'"\ test'),
b'"\\"\\\\ test"',
)
# non-ascii should come out utf8-encoded.
- self.assertEquals(encode_canonical_json({
+ self.assertEqual(encode_canonical_json({
u"la merde amusée": u"💩",
}), b'{"la merde amus\xc3\xa9e":"\xF0\x9F\x92\xA9"}')
# so should U+2028 and U+2029
- self.assertEquals(
+ self.assertEqual(
encode_canonical_json({u"spaces": u"\u2028 \u2029"}),
b'{"spaces":"\xe2\x80\xa8 \xe2\x80\xa9"}',
)
# but we need to watch out for 'u1234' after backslash, which should
# get encoded to an escaped backslash, followed by u1234
- self.assertEquals(
+ self.assertEqual(
encode_canonical_json(u"\\u1234"),
b'"\\\\u1234"',
)
def test_encode_pretty_printed(self):
- self.assertEquals(encode_pretty_printed_json({}), b'{}')
+ self.assertEqual(encode_pretty_printed_json({}), b'{}')
def test_frozen_dict(self):
- self.assertEquals(
+ self.assertEqual(
encode_canonical_json(frozendict({"a": 1})),
b'{"a":1}',
)
- self.assertEquals(
+ self.assertEqual(
encode_pretty_printed_json(frozendict({"a": 1})),
b'{\n "a": 1\n}')
@@ -78,3 +80,15 @@
unknown_object = Unknown()
with self.assertRaises(Exception):
encode_canonical_json(unknown_object)
+
+ def test_set_json(self):
+ """Ensure that changing the underlying JSON implementation works."""
+ mock_json = mock.Mock(spec=["JSONEncoder"])
+ mock_json.JSONEncoder.return_value.encode.return_value = "sentinel"
+ try:
+ set_json_library(mock_json)
+ self.assertEqual(encode_canonical_json({}), b"sentinel")
+ finally:
+ # Reset the JSON library to whatever was originally set.
+ from canonicaljson import json
+ set_json_library(json)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/python-canonicaljson-1.1.4/tox.ini
new/python-canonicaljson-1.2.0/tox.ini
--- old/python-canonicaljson-1.1.4/tox.ini 2018-05-23 10:28:32.000000000
+0200
+++ new/python-canonicaljson-1.2.0/tox.ini 2020-07-27 17:42:49.000000000
+0200
@@ -1,5 +1,5 @@
[tox]
-envlist = packaging, pep8, py3pep8, py26, py27, py33, py34, py35, py36, pypy
+envlist = packaging, pep8, py35, py36, py37, py38, pypy3
[testenv]
deps =
@@ -16,12 +16,6 @@
commands = check-manifest
[testenv:pep8]
-basepython = python2.7
-deps =
- flake8
-commands = flake8 .
-
-[testenv:py3pep8]
basepython = python3.6
deps =
flake8