diff options
author | Bob Ippolito <bob@redivi.com> | 2017-11-23 13:52:00 -0800 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2017-11-23 13:52:00 -0800 |
commit | 47bb9950941aed34aef4fcad3fd20a2585c696f2 (patch) | |
tree | dda702219b4e599c445aa74c1074cb237ff9d409 | |
parent | 0fd73bc8c6ad200754cce837ba8c97715e95ee25 (diff) | |
download | simplejson-47bb9950941aed34aef4fcad3fd20a2585c696f2.tar.gz |
Ensure that encoding text subtypes is consistent with or without speedups. Fixes #185
-rw-r--r-- | CHANGES.txt | 4 | ||||
-rw-r--r-- | conf.py | 4 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | simplejson/__init__.py | 2 | ||||
-rw-r--r-- | simplejson/encoder.py | 8 | ||||
-rw-r--r-- | simplejson/tests/test_dump.py | 14 |
6 files changed, 24 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 03c2ab1..1efe494 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,8 +1,10 @@ -Version 3.12.2 released 2017-11-23 +Version 3.13.0 released 2017-11-23 * Workarounds for NamedTemporaryFile issues with Windows for tool tests * Make TypeError messages contain type name instead of a repr. https://github.com/simplejson/simplejson/pull/191 +* Ensure that encoding of text subtypes is consistent with or without speedups + https://github.com/simplejson/simplejson/issues/185 Version 3.12.1 released 2017-11-23 @@ -42,9 +42,9 @@ copyright = '2017, Bob Ippolito' # other places throughout the built documents. # # The short X.Y version. -version = '3.12' +version = '3.13' # The full version, including alpha/beta/rc tags. -release = '3.12.2' +release = '3.13.0' # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: @@ -11,7 +11,7 @@ from distutils.errors import CCompilerError, DistutilsExecError, \ DistutilsPlatformError IS_PYPY = hasattr(sys, 'pypy_translation_info') -VERSION = '3.12.2' +VERSION = '3.13.0' DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python" with open('README.rst', 'r') as f: diff --git a/simplejson/__init__.py b/simplejson/__init__.py index ca8e7b5..8a67437 100644 --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -98,7 +98,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.12.2' +__version__ = '3.13.0' __all__ = [ 'dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 25ddf25..d3ea3d6 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -48,12 +48,12 @@ def encode_basestring(s, _PY3=PY3, _q=u('"')): if isinstance(s, binary_type): s = s.decode('utf-8') if type(s) is not text_type: - s = text_type(s) + s = text_type.__str__(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) + s = text_type.__str__(s) def replace(match): return ESCAPE_DCT[match.group(0)] return _q + ESCAPE.sub(replace, s) + _q @@ -67,12 +67,12 @@ def py_encode_basestring_ascii(s, _PY3=PY3): if isinstance(s, binary_type): s = s.decode('utf-8') if type(s) is not text_type: - s = text_type(s) + s = text_type.__str__(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) + s = text_type.__str__(s) def replace(match): s = match.group(0) try: diff --git a/simplejson/tests/test_dump.py b/simplejson/tests/test_dump.py index 3661de0..f5f4c1f 100644 --- a/simplejson/tests/test_dump.py +++ b/simplejson/tests/test_dump.py @@ -1,7 +1,11 @@ from unittest import TestCase -from simplejson.compat import StringIO, long_type, b, binary_type, PY3 +from simplejson.compat import StringIO, long_type, b, binary_type, text_type, PY3 import simplejson as json +class MisbehavingTextSubtype(text_type): + def __str__(self): + return "FAIL!" + def as_text_type(s): if PY3 and isinstance(s, binary_type): return s.decode('ascii') @@ -128,3 +132,11 @@ class TestDump(TestCase): json.dump(p, sio, sort_keys=True) self.assertEqual(sio.getvalue(), json.dumps(p, sort_keys=True)) self.assertEqual(json.loads(sio.getvalue()), p) + + def test_misbehaving_text_subtype(self): + # https://github.com/simplejson/simplejson/issues/185 + text = "this is some text" + self.assertEqual( + json.dumps(MisbehavingTextSubtype(text)), + json.dumps(text) + ) |