diff options
-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: |