diff options
author | Bob Ippolito <bob@redivi.com> | 2018-03-27 16:04:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-27 16:04:35 -0700 |
commit | d6b29ef522df2c3f7e26718e8578c89e9d733d83 (patch) | |
tree | e3bf9abcdb362685c73d728212b3588c7fe8055a | |
parent | 6ffddbe5ed6e4e72fbc7f6023439227970139159 (diff) | |
parent | 4e4ee05652472acb3bde31c5ad138b35d6c7dce9 (diff) | |
download | simplejson-d6b29ef522df2c3f7e26718e8578c89e9d733d83.tar.gz |
Merge pull request #210 from richvdh/rav/avoid_string_copy
Avoid copying strings when encoding
-rw-r--r-- | simplejson/encoder.py | 4 | ||||
-rw-r--r-- | simplejson/tests/test_str_subclass.py | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 831527b..ae76ae3 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -52,7 +52,7 @@ def encode_basestring(s, _PY3=PY3, _q=u('"')): 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: + if type(s) not in (str, unicode): if isinstance(s, str): s = str.__str__(s) else: @@ -74,7 +74,7 @@ def py_encode_basestring_ascii(s, _PY3=PY3): 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: + if type(s) not in (str, unicode): if isinstance(s, str): s = str.__str__(s) else: diff --git a/simplejson/tests/test_str_subclass.py b/simplejson/tests/test_str_subclass.py index 771eb67..dc87904 100644 --- a/simplejson/tests/test_str_subclass.py +++ b/simplejson/tests/test_str_subclass.py @@ -14,3 +14,8 @@ class TestStrSubclass(TestCase): self.assertEqual( s, simplejson.loads(simplejson.dumps(WonkyTextSubclass(s)))) + + self.assertEqual( + s, + simplejson.loads(simplejson.dumps(WonkyTextSubclass(s), + ensure_ascii=False))) |