summaryrefslogtreecommitdiff
path: root/simplejson
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2009-02-22 21:44:12 +0000
committerBob Ippolito <bob@redivi.com>2009-02-22 21:44:12 +0000
commitfbcdcec4059c87693cb662c8766324ec4e9727c8 (patch)
tree5f0c5f1513e3c46421155b424027317581c612af /simplejson
parent173ebd91f223afef30aebbc3da58fdafc935c3cc (diff)
downloadsimplejson-fbcdcec4059c87693cb662c8766324ec4e9727c8.tar.gz
fix long lines, make py2.6+ porting a bit easier
git-svn-id: http://simplejson.googlecode.com/svn/trunk@173 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'simplejson')
-rw-r--r--simplejson/__init__.py11
-rw-r--r--simplejson/decoder.py10
-rw-r--r--simplejson/encoder.py20
-rw-r--r--simplejson/scanner.py3
-rw-r--r--simplejson/tests/test_encode_basestring_ascii.py3
-rw-r--r--simplejson/tests/test_fail.py1
-rw-r--r--simplejson/tests/test_unicode.py5
7 files changed, 34 insertions, 19 deletions
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index d5b4d39..93adadb 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -68,8 +68,8 @@ Specializing JSON object decoding::
>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
... object_hook=as_complex)
(1+2j)
- >>> import decimal
- >>> json.loads('1.1', parse_float=decimal.Decimal) == decimal.Decimal('1.1')
+ >>> from decimal import Decimal
+ >>> json.loads('1.1', parse_float=Decimal) == Decimal('1.1')
True
Specializing JSON object encoding::
@@ -144,9 +144,10 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
in strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
- If ``indent`` is a non-negative integer, then JSON array elements and object
- members will be pretty-printed with that indent level. An indent level
- of 0 will only insert newlines. ``None`` is the most compact representation.
+ If ``indent`` is a non-negative integer, then JSON array elements and
+ object members will be pretty-printed with that indent level. An indent
+ level of 0 will only insert newlines. ``None`` is the most compact
+ representation.
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
then it will be used instead of the default ``(', ', ': ')`` separators.
diff --git a/simplejson/decoder.py b/simplejson/decoder.py
index b769ea4..abdc585 100644
--- a/simplejson/decoder.py
+++ b/simplejson/decoder.py
@@ -62,7 +62,8 @@ BACKSLASH = {
DEFAULT_ENCODING = "utf-8"
-def py_scanstring(s, end, encoding=None, strict=True, _b=BACKSLASH, _m=STRINGCHUNK.match):
+def py_scanstring(s, end, encoding=None, strict=True,
+ _b=BACKSLASH, _m=STRINGCHUNK.match):
"""Scan the string s for a JSON string. End is the index of the
character in s after the quote that started the JSON string.
Unescapes all valid JSON string escape sequences and raises ValueError
@@ -145,7 +146,8 @@ scanstring = c_scanstring or py_scanstring
WHITESPACE = re.compile(r'[ \t\n\r]*', FLAGS)
WHITESPACE_STR = ' \t\n\r'
-def JSONObject((s, end), encoding, strict, scan_once, object_hook, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+def JSONObject((s, end), encoding, strict, scan_once, object_hook,
+ _w=WHITESPACE.match, _ws=WHITESPACE_STR):
pairs = {}
# Use a slice to prevent IndexError from being raised, the following
# check will raise a more specific ValueError if the string is empty
@@ -339,8 +341,8 @@ class JSONDecoder(object):
return obj
def raw_decode(self, s, idx=0):
- """Decode a JSON document from ``s`` (a ``str`` or ``unicode`` beginning
- with a JSON document) and return a 2-tuple of the Python
+ """Decode a JSON document from ``s`` (a ``str`` or ``unicode``
+ beginning with a JSON document) and return a 2-tuple of the Python
representation and the index in ``s`` where the document ended.
This can be used to decode a JSON document from a string that may
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index cf58290..1d60eca 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -3,7 +3,8 @@
import re
try:
- from simplejson._speedups import encode_basestring_ascii as c_encode_basestring_ascii
+ from simplejson._speedups import encode_basestring_ascii as \
+ c_encode_basestring_ascii
except ImportError:
c_encode_basestring_ascii = None
try:
@@ -65,7 +66,8 @@ def py_encode_basestring_ascii(s):
return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
-encode_basestring_ascii = c_encode_basestring_ascii or py_encode_basestring_ascii
+encode_basestring_ascii = (
+ c_encode_basestring_ascii or py_encode_basestring_ascii)
class JSONEncoder(object):
"""Extensible JSON <http://json.org> encoder for Python data structures.
@@ -226,9 +228,11 @@ class JSONEncoder(object):
o = o.decode(_encoding)
return _orig_encoder(o)
- def floatstr(o, allow_nan=self.allow_nan, _repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):
- # Check for specials. Note that this type of test is processor- and/or
- # platform-specific, so do tests which don't depend on the internals.
+ def floatstr(o, allow_nan=self.allow_nan,
+ _repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):
+ # Check for specials. Note that this type of test is processor
+ # and/or platform-specific, so do tests which don't depend on
+ # the internals.
if o != o:
text = 'NaN'
@@ -247,7 +251,8 @@ class JSONEncoder(object):
return text
- if _one_shot and c_make_encoder is not None and not self.indent and not self.sort_keys:
+ if (_one_shot and c_make_encoder is not None
+ and not self.indent and not self.sort_keys):
_iterencode = c_make_encoder(
markers, self.default, _encoder, self.indent,
self.key_separator, self.item_separator, self.sort_keys,
@@ -259,7 +264,8 @@ class JSONEncoder(object):
self.skipkeys, _one_shot)
return _iterencode(o, 0)
-def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
+def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
+ _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
## HACK: hand-optimized bytecode; turn globals into locals
False=False,
True=True,
diff --git a/simplejson/scanner.py b/simplejson/scanner.py
index adbc6ec..0f26a6d 100644
--- a/simplejson/scanner.py
+++ b/simplejson/scanner.py
@@ -33,7 +33,8 @@ def py_make_scanner(context):
if nextchar == '"':
return parse_string(string, idx + 1, encoding, strict)
elif nextchar == '{':
- return parse_object((string, idx + 1), encoding, strict, _scan_once, object_hook)
+ return parse_object((string, idx + 1), encoding, strict,
+ _scan_once, object_hook)
elif nextchar == '[':
return parse_array((string, idx + 1), _scan_once)
elif nextchar == 'n' and string[idx:idx + 4] == 'null':
diff --git a/simplejson/tests/test_encode_basestring_ascii.py b/simplejson/tests/test_encode_basestring_ascii.py
index 7128495..b19631a 100644
--- a/simplejson/tests/test_encode_basestring_ascii.py
+++ b/simplejson/tests/test_encode_basestring_ascii.py
@@ -34,5 +34,8 @@ class TestEncodeBaseStringAscii(TestCase):
fname = encode_basestring_ascii.__name__
for input_string, expect in CASES:
result = encode_basestring_ascii(input_string)
+ #self.assertEquals(result, expect,
+ # '{0!r} != {1!r} for {2}({3!r})'.format(
+ # result, expect, fname, input_string))
self.assertEquals(result, expect,
'%r != %r for %s(%r)' % (result, expect, fname, input_string))
diff --git a/simplejson/tests/test_fail.py b/simplejson/tests/test_fail.py
index 002eea0..bd7a99e 100644
--- a/simplejson/tests/test_fail.py
+++ b/simplejson/tests/test_fail.py
@@ -73,4 +73,5 @@ class TestFail(TestCase):
except ValueError:
pass
else:
+ #self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
self.fail("Expected failure for fail%d.json: %r" % (idx, doc))
diff --git a/simplejson/tests/test_unicode.py b/simplejson/tests/test_unicode.py
index 6f4384a..edf9264 100644
--- a/simplejson/tests/test_unicode.py
+++ b/simplejson/tests/test_unicode.py
@@ -31,12 +31,12 @@ class TestUnicode(TestCase):
def test_encoding5(self):
u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
j = json.dumps(u, ensure_ascii=False)
- self.assertEquals(j, u'"%s"' % (u,))
+ self.assertEquals(j, u'"' + u + u'"')
def test_encoding6(self):
u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
j = json.dumps([u], ensure_ascii=False)
- self.assertEquals(j, u'["%s"]' % (u,))
+ self.assertEquals(j, u'["' + u + u'"]')
def test_big_unicode_encode(self):
u = u'\U0001d120'
@@ -51,6 +51,7 @@ class TestUnicode(TestCase):
def test_unicode_decode(self):
for i in range(0, 0xd7ff):
u = unichr(i)
+ #s = '"\\u{0:04x}"'.format(i)
s = '"\\u%04x"' % (i,)
self.assertEquals(json.loads(s), u)