Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: merge-2.7.2 Changeset: r51665:c000c3332cb0 Date: 2012-01-22 20:56 +0100 http://bitbucket.org/pypy/pypy/changeset/c000c3332cb0/
Log: json: Rename some functions in our pure-python implementation: in CPython, encode_basestring() is supposed to add double quotes. diff --git a/lib-python/modified-2.7/json/encoder.py b/lib-python/modified-2.7/json/encoder.py --- a/lib-python/modified-2.7/json/encoder.py +++ b/lib-python/modified-2.7/json/encoder.py @@ -23,15 +23,16 @@ INFINITY = float('1e66666') FLOAT_REPR = repr -def encode_basestring(s): +def raw_encode_basestring(s): """Return a JSON representation of a Python string """ def replace(match): return ESCAPE_DCT[match.group(0)] return ESCAPE.sub(replace, s) +encode_basestring = lambda s: '"' + raw_encode_basestring(s) + '"' -def encode_basestring_ascii(s): +def raw_encode_basestring_ascii(s): """Return an ASCII-only JSON representation of a Python string """ @@ -54,8 +55,8 @@ if ESCAPE_ASCII.search(s): return str(ESCAPE_ASCII.sub(replace, s)) return s -py_encode_basestring_ascii = lambda s: '"' + encode_basestring_ascii(s) + '"' -c_encode_basestring_ascii = None +encode_basestring_ascii = lambda s: '"' + raw_encode_basestring_ascii(s) + '"' + class JSONEncoder(object): """Extensible JSON <http://json.org> encoder for Python data structures. @@ -137,9 +138,9 @@ self.skipkeys = skipkeys self.ensure_ascii = ensure_ascii if ensure_ascii: - self.encoder = encode_basestring_ascii + self.encoder = raw_encode_basestring_ascii else: - self.encoder = encode_basestring + self.encoder = raw_encode_basestring if encoding != 'utf-8': orig_encoder = self.encoder def encoder(o): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit