diff --git a/README.md b/README.md new file mode 100644 index 00000000..ceeb2992 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +simplejson +========== + +simplejson is a simple, fast, extensible JSON encoder/decoder for Python + +This branch is for use in extreme situations where you cannot upgrade from Python 2.2, expect to get your hands dirty! + +There is no release of this egg, you will rather want to check it out: + + git clone https://github.com/simplejson/simplejson.git --branch python2.2 + +Add install it in your old python: + + python2.2 setup.py install + +Any features missing from the mainline version need to be coded in by hand. +I hope this is useful, it should be better than starting from scratch! diff --git a/setup.py b/setup.py index 21b0be01..1da0d16b 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,15 @@ #!/usr/bin/env python +import sys +if sys.version_info < (2, 3): + from distutils.core import setup -import ez_setup -ez_setup.use_setuptools() + def find_packages(exclude=None): + return ['simplejson', 'simplejson.tests'] +else: + import ez_setup + ez_setup.use_setuptools() -from setuptools import setup, find_packages + from setuptools import setup, find_packages VERSION = '1.1' DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python" diff --git a/simplejson/decoder.py b/simplejson/decoder.py index cd8ef630..bfffa723 100644 --- a/simplejson/decoder.py +++ b/simplejson/decoder.py @@ -12,7 +12,9 @@ def _floatconstants(): import sys _BYTES = '7FF80000000000007FF0000000000000'.decode('hex') if sys.byteorder != 'big': - _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1] + # slicing not available in Python 2.2 + #_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1] + _BYTES = '000000000000f87f000000000000f07f'.decode('hex') nan, inf = struct.unpack('dd', _BYTES) return nan, inf, -inf diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 5b4b7cd3..3a06f905 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -1,6 +1,7 @@ """ Implementation of JSONEncoder """ +from __future__ import generators import re # this should match any kind of infinity @@ -158,7 +159,7 @@ def _iterencode_dict(self, dct, markers=None): encoder = encode_basestring allow_nan = self.allow_nan for key, value in dct.iteritems(): - if isinstance(key, basestring): + if isinstance(key, (str, unicode)): pass # JavaScript is weakly typed for these, so it makes sense to # also allow them. Many encoders seem to do something like this. @@ -189,7 +190,7 @@ def _iterencode_dict(self, dct, markers=None): del markers[markerid] def _iterencode(self, o, markers=None): - if isinstance(o, basestring): + if isinstance(o, (str, unicode)): if self.ensure_ascii: encoder = encode_basestring_ascii else: diff --git a/simplejson/scanner.py b/simplejson/scanner.py index 95d3f2bb..fc88885c 100644 --- a/simplejson/scanner.py +++ b/simplejson/scanner.py @@ -1,6 +1,10 @@ """ Iterator based sre token scanner """ +from __future__ import generators +import __builtin__ +__builtin__.enumerate = lambda seq: zip(xrange(len(seq)), seq) + import sre_parse, sre_compile, sre_constants from sre_constants import BRANCH, SUBPATTERN from sre import VERBOSE, MULTILINE, DOTALL