summaryrefslogtreecommitdiffstats
path: root/Lib/json/encoder.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-01-11 15:41:01 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-01-11 15:41:01 (GMT)
commitdc3eaa80d493cd23a5589f16a2ead559b0fd376c (patch)
tree31c141587230c00bdd02003f4e9719ea6fc60c37 /Lib/json/encoder.py
parent2cae11e87eac4a086b3188112f08ee9ed6269556 (diff)
downloadcpython-dc3eaa80d493cd23a5589f16a2ead559b0fd376c.zip
cpython-dc3eaa80d493cd23a5589f16a2ead559b0fd376c.tar.gz
cpython-dc3eaa80d493cd23a5589f16a2ead559b0fd376c.tar.bz2
Issue #23206: Make ``json.dumps(..., ensure_ascii=False)`` as fast as the default case of ``ensure_ascii=True``. Patch by Naoki Inada.
Diffstat (limited to 'Lib/json/encoder.py')
-rw-r--r--Lib/json/encoder.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 0513838..26e9eb2 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -7,6 +7,10 @@ try:
except ImportError:
c_encode_basestring_ascii = None
try:
+ from _json import encode_basestring as c_encode_basestring
+except ImportError:
+ c_encode_basestring = None
+try:
from _json import make_encoder as c_make_encoder
except ImportError:
c_make_encoder = None
@@ -30,7 +34,7 @@ for i in range(0x20):
INFINITY = float('inf')
FLOAT_REPR = repr
-def encode_basestring(s):
+def py_encode_basestring(s):
"""Return a JSON representation of a Python string
"""
@@ -39,6 +43,9 @@ def encode_basestring(s):
return '"' + ESCAPE.sub(replace, s) + '"'
+encode_basestring = (c_encode_basestring or py_encode_basestring)
+
+
def py_encode_basestring_ascii(s):
"""Return an ASCII-only JSON representation of a Python string