Skip to content

Commit

Permalink
Fix string encoding for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Nov 23, 2017
1 parent 47bb995 commit d53d0c6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions simplejson/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit d53d0c6

Please sign in to comment.