diff options
author | Bob Ippolito <bob@redivi.com> | 2017-11-23 14:06:58 -0800 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2017-11-23 14:28:44 -0800 |
commit | d53d0c6e23171a62f4a26094b2f23f36eb4d3fe4 (patch) | |
tree | 95b7c25e585da4678cd1f9a38c45c8624cda26fb | |
parent | 47bb9950941aed34aef4fcad3fd20a2585c696f2 (diff) | |
download | simplejson-d53d0c6e23171a62f4a26094b2f23f36eb4d3fe4.tar.gz |
Fix string encoding for Python 2
-rw-r--r-- | simplejson/encoder.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py index d3ea3d6..831527b 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -53,7 +53,10 @@ def encode_basestring(s, _PY3=PY3, _q=u('"')): 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.__str__(s) + if isinstance(s, str): + s = str.__str__(s) + else: + s = unicode.__getnewargs__(s)[0] def replace(match): return ESCAPE_DCT[match.group(0)] return _q + ESCAPE.sub(replace, s) + _q @@ -72,7 +75,10 @@ def py_encode_basestring_ascii(s, _PY3=PY3): 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.__str__(s) + if isinstance(s, str): + s = str.__str__(s) + else: + s = unicode.__getnewargs__(s)[0] def replace(match): s = match.group(0) try: |