[Python-modules-commits] [simplejson] 01/06: Import simplejson_3.10.0.orig.tar.gz

Piotr Ożarowski piotr at moszumanska.debian.org
Sat Nov 5 21:00:41 UTC 2016


This is an automated email from the git hooks/post-receive script.

piotr pushed a commit to branch master
in repository simplejson.

commit bde323c3b6be4d4a636c4050389953ba6d8cd260
Author: Piotr Ożarowski <piotr at debian.org>
Date:   Sat Nov 5 21:50:26 2016 +0100

    Import simplejson_3.10.0.orig.tar.gz
---
 CHANGES.txt                           | 18 +++++++++++++-
 PKG-INFO                              | 12 ++++++---
 README.rst                            |  8 +++++-
 conf.py                               |  6 ++---
 scripts/artifacts.py                  | 35 +++++++++++++++++++++++++-
 setup.py                              |  2 +-
 simplejson.egg-info/PKG-INFO          | 12 ++++++---
 simplejson.egg-info/SOURCES.txt       |  2 ++
 simplejson/__init__.py                |  4 +--
 simplejson/_speedups.c                | 22 ++++++++++++++++
 simplejson/compat.py                  |  6 -----
 simplejson/decoder.py                 | 18 ++++++++------
 simplejson/encoder.py                 | 24 +++++++++++++++++-
 simplejson/tests/__init__.py          |  2 ++
 simplejson/tests/test_raw_json.py     | 47 +++++++++++++++++++++++++++++++++++
 simplejson/tests/test_str_subclass.py | 16 ++++++++++++
 16 files changed, 205 insertions(+), 29 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index e657176..bd01fe8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,19 @@
+Version 3.10.0 released 2016-10-28
+
+* Add RawJSON class to allow a faster path for already encoded JSON.
+  https://github.com/simplejson/simplejson/pull/143
+
+Version 3.9.0 released 2016-10-21
+
+* Workaround for bad behavior in string subclasses
+  https://github.com/simplejson/simplejson/issues/144
+* Fix warnings flagged by -3
+  https://github.com/simplejson/simplejson/pull/146
+* Update readthedocs documentation links
+  https://github.com/simplejson/simplejson/pull/137
+* Add build status badge to README
+  https://github.com/simplejson/simplejson/pull/134
+
 Version 3.8.2 released 2016-02-14
 
 * Fix implicit cast compiler warning in _speedups.c
@@ -318,7 +334,7 @@ Version 2.2.0 released 2011-09-04
 * Force unicode linebreak characters to be escaped (U+2028 and U+2029)
   http://timelessrepo.com/json-isnt-a-javascript-subset
 * Moved documentation from a git submodule to
-  http://simplejson.readthedocs.org/
+  https://simplejson.readthedocs.io/
 
 Version 2.1.6 released 2011-05-08
 
diff --git a/PKG-INFO b/PKG-INFO
index 87a3dbc..1097ad3 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,18 +1,24 @@
 Metadata-Version: 1.1
 Name: simplejson
-Version: 3.8.2
+Version: 3.10.0
 Summary: Simple, fast, extensible JSON encoder/decoder for Python
 Home-page: http://github.com/simplejson/simplejson
 Author: Bob Ippolito
 Author-email: bob at redivi.com
 License: MIT License
-Description: simplejson is a simple, fast, complete, correct and extensible
+Description: simplejson
+        ----------
+        
+        .. image:: https://travis-ci.org/simplejson/simplejson.svg?branch=master
+            :target: https://travis-ci.org/simplejson/simplejson
+        
+        simplejson is a simple, fast, complete, correct and extensible
         JSON <http://json.org> encoder and decoder for Python 2.5+
         and Python 3.3+.  It is pure Python code with no dependencies,
         but includes an optional C extension for a serious speed boost.
         
         The latest documentation for simplejson can be read online here:
-        http://simplejson.readthedocs.org/
+        https://simplejson.readthedocs.io/
         
         simplejson is the externally maintained development version of the
         json library included with Python 2.6 and Python 3.0, but maintains
diff --git a/README.rst b/README.rst
index e4b47fb..196148f 100644
--- a/README.rst
+++ b/README.rst
@@ -1,10 +1,16 @@
+simplejson
+----------
+
+.. image:: https://travis-ci.org/simplejson/simplejson.svg?branch=master
+    :target: https://travis-ci.org/simplejson/simplejson
+
 simplejson is a simple, fast, complete, correct and extensible
 JSON <http://json.org> encoder and decoder for Python 2.5+
 and Python 3.3+.  It is pure Python code with no dependencies,
 but includes an optional C extension for a serious speed boost.
 
 The latest documentation for simplejson can be read online here:
-http://simplejson.readthedocs.org/
+https://simplejson.readthedocs.io/
 
 simplejson is the externally maintained development version of the
 json library included with Python 2.6 and Python 3.0, but maintains
diff --git a/conf.py b/conf.py
index 8a6a391..c7ea050 100644
--- a/conf.py
+++ b/conf.py
@@ -36,15 +36,15 @@ master_doc = 'index'
 
 # General substitutions.
 project = 'simplejson'
-copyright = '2015, Bob Ippolito'
+copyright = '2016, Bob Ippolito'
 
 # The default replacements for |version| and |release|, also used in various
 # other places throughout the built documents.
 #
 # The short X.Y version.
-version = '3.8'
+version = '3.10'
 # The full version, including alpha/beta/rc tags.
-release = '3.8.2'
+release = '3.10.0'
 
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
diff --git a/scripts/artifacts.py b/scripts/artifacts.py
index 4be1ea3..2aed12d 100644
--- a/scripts/artifacts.py
+++ b/scripts/artifacts.py
@@ -3,9 +3,13 @@ try:
 except ImportError:
     from urllib import urlopen
 
+import glob
 import io
 import json
+import os
+import re
 import subprocess
+import sys
 
 
 def get_json(url):
@@ -36,12 +40,41 @@ def download_github_artifacts():
     release = get_json(
         'https://api.github.com/repos/simplejson/simplejson/releases/latest')
     for asset in release['assets']:
-        download_file(asset['url'], 'dist/{name}'.format(**asset))
+        download_file(asset['browser_download_url'], 'dist/{name}'.format(**asset))
 
+def get_version():
+    return subprocess.check_output([sys.executable, 'setup.py', '--version']).strip()
+
+def artifact_matcher(version):
+    return re.compile('^simplejson-{}.*\\.(exe|whl)$'.format(re.escape(version)))
+
+def sign_artifacts(version):
+    artifacts = set(os.listdir('dist'))
+    pattern = artifact_matcher(version)
+    for fn in artifacts:
+        if pattern.search(fn) and '{}.asc'.format(fn) not in artifacts:
+            sign_artifact(os.path.join('dist', fn))
+
+def sign_artifact(path):
+    print(' '.join(['gpg', '--detach-sign', '-a', path]))
+    subprocess.check_call(['gpg', '--detach-sign', '-a', path])
+
+def upload_artifacts(version):
+    artifacts = set(os.listdir('dist'))
+    pattern = artifact_matcher(version)
+    args = ['twine', 'upload']
+    for fn in artifacts:
+        if pattern.search(fn):
+            filename = os.path.join('dist', fn)
+            args.extend([filename, filename + '.asc'])
+    subprocess.check_call(args)
 
 def main():
     download_appveyor_artifacts()
     download_github_artifacts()
+    version = get_version()
+    sign_artifacts(version)
+    upload_artifacts(version)
 
 
 if __name__ == '__main__':
diff --git a/setup.py b/setup.py
index 1a92c2f..ade96fa 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ from distutils.errors import CCompilerError, DistutilsExecError, \
     DistutilsPlatformError
 
 IS_PYPY = hasattr(sys, 'pypy_translation_info')
-VERSION = '3.8.2'
+VERSION = '3.10.0'
 DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
 
 with open('README.rst', 'r') as f:
diff --git a/simplejson.egg-info/PKG-INFO b/simplejson.egg-info/PKG-INFO
index 87a3dbc..1097ad3 100644
--- a/simplejson.egg-info/PKG-INFO
+++ b/simplejson.egg-info/PKG-INFO
@@ -1,18 +1,24 @@
 Metadata-Version: 1.1
 Name: simplejson
-Version: 3.8.2
+Version: 3.10.0
 Summary: Simple, fast, extensible JSON encoder/decoder for Python
 Home-page: http://github.com/simplejson/simplejson
 Author: Bob Ippolito
 Author-email: bob at redivi.com
 License: MIT License
-Description: simplejson is a simple, fast, complete, correct and extensible
+Description: simplejson
+        ----------
+        
+        .. image:: https://travis-ci.org/simplejson/simplejson.svg?branch=master
+            :target: https://travis-ci.org/simplejson/simplejson
+        
+        simplejson is a simple, fast, complete, correct and extensible
         JSON <http://json.org> encoder and decoder for Python 2.5+
         and Python 3.3+.  It is pure Python code with no dependencies,
         but includes an optional C extension for a serious speed boost.
         
         The latest documentation for simplejson can be read online here:
-        http://simplejson.readthedocs.org/
+        https://simplejson.readthedocs.io/
         
         simplejson is the externally maintained development version of the
         json library included with Python 2.6 and Python 3.0, but maintains
diff --git a/simplejson.egg-info/SOURCES.txt b/simplejson.egg-info/SOURCES.txt
index 305d038..286280a 100644
--- a/simplejson.egg-info/SOURCES.txt
+++ b/simplejson.egg-info/SOURCES.txt
@@ -40,10 +40,12 @@ simplejson/tests/test_namedtuple.py
 simplejson/tests/test_pass1.py
 simplejson/tests/test_pass2.py
 simplejson/tests/test_pass3.py
+simplejson/tests/test_raw_json.py
 simplejson/tests/test_recursion.py
 simplejson/tests/test_scanstring.py
 simplejson/tests/test_separators.py
 simplejson/tests/test_speedups.py
+simplejson/tests/test_str_subclass.py
 simplejson/tests/test_subclass.py
 simplejson/tests/test_tool.py
 simplejson/tests/test_tuple.py
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index b7fe828..d4876cd 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -97,7 +97,7 @@ Using simplejson.tool from the shell to validate and pretty-print::
     Expecting property name: line 1 column 3 (char 2)
 """
 from __future__ import absolute_import
-__version__ = '3.8.2'
+__version__ = '3.10.0'
 __all__ = [
     'dump', 'dumps', 'load', 'loads',
     'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
@@ -110,7 +110,7 @@ from decimal import Decimal
 
 from .scanner import JSONDecodeError
 from .decoder import JSONDecoder
-from .encoder import JSONEncoder, JSONEncoderForHTML
+from .encoder import JSONEncoder, JSONEncoderForHTML, RawJSON
 def _import_OrderedDict():
     import collections
     try:
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index 9976464..2d81063 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -245,6 +245,8 @@ static void
 encoder_dealloc(PyObject *self);
 static int
 encoder_clear(PyObject *self);
+static int
+is_raw_json(PyObject *obj);
 static PyObject *
 encoder_stringify_key(PyEncoderObject *s, PyObject *key);
 static int
@@ -277,6 +279,20 @@ moduleinit(void);
 
 #define MIN_EXPANSION 6
 
+static PyObject* RawJSONType;
+static int
+is_raw_json(PyObject *obj)
+{
+    if (RawJSONType == NULL) {
+        PyObject *encoder_module = PyImport_ImportModule("simplejson.encoder");
+        RawJSONType = PyObject_GetAttrString(encoder_module, "RawJSON");
+        Py_DECREF(encoder_module);
+        if (RawJSONType == NULL)
+            return 0;
+    }
+    return PyObject_IsInstance(obj, RawJSONType) ? 1 : 0;
+}
+
 static int
 JSON_Accu_Init(JSON_Accu *acc)
 {
@@ -2868,6 +2884,12 @@ encoder_listencode_obj(PyEncoderObject *s, JSON_Accu *rval, PyObject *obj, Py_ss
             if (encoded != NULL)
                 rv = _steal_accumulate(rval, encoded);
         }
+        else if (is_raw_json(obj))
+        {
+            PyObject *encoded = PyObject_GetAttrString(obj, "encoded_json");
+            if (encoded != NULL)
+                rv = _steal_accumulate(rval, encoded);
+        }
         else if (PyInt_Check(obj) || PyLong_Check(obj)) {
             PyObject *encoded;
             if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)) {
diff --git a/simplejson/compat.py b/simplejson/compat.py
index a0af4a1..6f945cc 100644
--- a/simplejson/compat.py
+++ b/simplejson/compat.py
@@ -15,9 +15,6 @@ if sys.version_info[0] < 3:
     integer_types = (int, long)
     unichr = unichr
     reload_module = reload
-    def fromhex(s):
-        return s.decode('hex')
-
 else:
     PY3 = True
     if sys.version_info[:2] >= (3, 4):
@@ -40,7 +37,4 @@ else:
     def unichr(s):
         return u(chr(s))
 
-    def fromhex(s):
-        return bytes.fromhex(s)
-
 long_type = integer_types[-1]
diff --git a/simplejson/decoder.py b/simplejson/decoder.py
index 545e658..29de124 100644
--- a/simplejson/decoder.py
+++ b/simplejson/decoder.py
@@ -4,7 +4,7 @@ from __future__ import absolute_import
 import re
 import sys
 import struct
-from .compat import fromhex, b, u, text_type, binary_type, PY3, unichr
+from .compat import b, u, text_type, binary_type, PY3, unichr
 from .scanner import make_scanner, JSONDecodeError
 
 def _import_c_scanstring():
@@ -22,12 +22,16 @@ __all__ = ['JSONDecoder']
 FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
 
 def _floatconstants():
-    _BYTES = fromhex('7FF80000000000007FF0000000000000')
-    # The struct module in Python 2.4 would get frexp() out of range here
-    # when an endian is specified in the format string. Fixed in Python 2.5+
-    if sys.byteorder != 'big':
-        _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
-    nan, inf = struct.unpack('dd', _BYTES)
+    if sys.version_info < (2, 6):
+        _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
+        # The struct module in Python 2.4 would get frexp() out of range here
+        # when an endian is specified in the format string. Fixed in Python 2.5+
+        if sys.byteorder != 'big':
+            _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
+        nan, inf = struct.unpack('dd', _BYTES)
+    else:
+        nan = float('nan')
+        inf = float('inf')
     return nan, inf, -inf
 
 NaN, PosInf, NegInf = _floatconstants()
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index 5b9bda7..226480f 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -5,7 +5,7 @@ import re
 from operator import itemgetter
 # Do not import Decimal directly to avoid reload issues
 import decimal
-from .compat import u, unichr, binary_type, string_types, integer_types, PY3
+from .compat import u, unichr, binary_type, text_type, string_types, integer_types, PY3
 def _import_speedups():
     try:
         from . import _speedups
@@ -39,6 +39,14 @@ for i in [0x2028, 0x2029]:
 
 FLOAT_REPR = repr
 
+class RawJSON(object):
+    """Wrap an encoded JSON document for direct embedding in the output
+
+    """
+    def __init__(self, encoded_json):
+        self.encoded_json = encoded_json
+
+
 def encode_basestring(s, _PY3=PY3, _q=u('"')):
     """Return a JSON representation of a Python string
 
@@ -46,9 +54,13 @@ def encode_basestring(s, _PY3=PY3, _q=u('"')):
     if _PY3:
         if isinstance(s, binary_type):
             s = s.decode('utf-8')
+        if type(s) is not text_type:
+            s = text_type(s)
     else:
         if isinstance(s, str) and HAS_UTF8.search(s) is not None:
             s = s.decode('utf-8')
+        if type(s) not in string_types:
+            s = text_type(s)
     def replace(match):
         return ESCAPE_DCT[match.group(0)]
     return _q + ESCAPE.sub(replace, s) + _q
@@ -61,9 +73,13 @@ def py_encode_basestring_ascii(s, _PY3=PY3):
     if _PY3:
         if isinstance(s, binary_type):
             s = s.decode('utf-8')
+        if type(s) is not text_type:
+            s = text_type(s)
     else:
         if isinstance(s, str) and HAS_UTF8.search(s) is not None:
             s = s.decode('utf-8')
+        if type(s) not in string_types:
+            s = text_type(s)
     def replace(match):
         s = match.group(0)
         try:
@@ -464,6 +480,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
             if (isinstance(value, string_types) or
                 (_PY3 and isinstance(value, binary_type))):
                 yield buf + _encoder(value)
+            elif isinstance(value, RawJSON):
+                yield buf + value.encoded_json
             elif value is None:
                 yield buf + 'null'
             elif value is True:
@@ -582,6 +600,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
             if (isinstance(value, string_types) or
                 (_PY3 and isinstance(value, binary_type))):
                 yield _encoder(value)
+            elif isinstance(value, RawJSON):
+                yield value.encoded_json
             elif value is None:
                 yield 'null'
             elif value is True:
@@ -624,6 +644,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
         if (isinstance(o, string_types) or
             (_PY3 and isinstance(o, binary_type))):
             yield _encoder(o)
+        elif isinstance(o, RawJSON):
+            yield o.encoded_json
         elif o is None:
             yield 'null'
         elif o is True:
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
index 88249d1..95e98e5 100644
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -57,6 +57,7 @@ def all_tests_suite():
                 'simplejson.tests.test_scanstring',
                 'simplejson.tests.test_separators',
                 'simplejson.tests.test_speedups',
+                'simplejson.tests.test_str_subclass',
                 'simplejson.tests.test_unicode',
                 'simplejson.tests.test_decimal',
                 'simplejson.tests.test_tuple',
@@ -64,6 +65,7 @@ def all_tests_suite():
                 'simplejson.tests.test_tool',
                 'simplejson.tests.test_for_json',
                 'simplejson.tests.test_subclass',
+                'simplejson.tests.test_raw_json',
             ]))
     suite = get_suite()
     import simplejson
diff --git a/simplejson/tests/test_raw_json.py b/simplejson/tests/test_raw_json.py
new file mode 100644
index 0000000..1dfcc2c
--- /dev/null
+++ b/simplejson/tests/test_raw_json.py
@@ -0,0 +1,47 @@
+import unittest
+import simplejson as json
+
+dct1 = {
+    'key1': 'value1'
+}
+
+dct2 = {
+    'key2': 'value2',
+    'd1': dct1
+}
+
+dct3 = {
+    'key2': 'value2',
+    'd1': json.dumps(dct1)
+}
+
+dct4 = {
+    'key2': 'value2',
+    'd1': json.RawJSON(json.dumps(dct1))
+}
+
+
+class TestRawJson(unittest.TestCase):
+
+    def test_normal_str(self):
+        self.assertNotEqual(json.dumps(dct2), json.dumps(dct3))
+
+    def test_raw_json_str(self):
+        self.assertEqual(json.dumps(dct2), json.dumps(dct4))
+        self.assertEqual(dct2, json.loads(json.dumps(dct4)))
+
+    def test_list(self):
+        self.assertEqual(
+            json.dumps([dct2]),
+            json.dumps([json.RawJSON(json.dumps(dct2))]))
+        self.assertEqual(
+            [dct2],
+            json.loads(json.dumps([json.RawJSON(json.dumps(dct2))])))
+
+    def test_direct(self):
+        self.assertEqual(
+            json.dumps(dct2),
+            json.dumps(json.RawJSON(json.dumps(dct2))))
+        self.assertEqual(
+            dct2,
+            json.loads(json.dumps(json.RawJSON(json.dumps(dct2)))))
diff --git a/simplejson/tests/test_str_subclass.py b/simplejson/tests/test_str_subclass.py
new file mode 100644
index 0000000..771eb67
--- /dev/null
+++ b/simplejson/tests/test_str_subclass.py
@@ -0,0 +1,16 @@
+from unittest import TestCase
+
+import simplejson
+from simplejson.compat import text_type, u
+
+# Tests for issue demonstrated in https://github.com/simplejson/simplejson/issues/144
+class WonkyTextSubclass(text_type):
+    def __getslice__(self, start, end):
+        return self.__class__('not what you wanted!')
+
+class TestStrSubclass(TestCase):
+    def test_dump_load(self):
+        for s in ['', '"hello"', 'text', u('\u005c')]:
+            self.assertEqual(
+                s,
+                simplejson.loads(simplejson.dumps(WonkyTextSubclass(s))))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/simplejson.git



More information about the Python-modules-commits mailing list