diff options
author | Bob Ippolito <bob@redivi.com> | 2008-09-24 07:46:18 +0000 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2008-09-24 07:46:18 +0000 |
commit | 6896523285b550fe6a1f0293ad36dcc396514c68 (patch) | |
tree | 58f93d9a05cfaa4a7396235a7f0221bb3d40204e /simplejson/scanner.py | |
parent | a8165ef80b2390951619bb199e6defe9b6cafd9a (diff) | |
download | simplejson-6896523285b550fe6a1f0293ad36dcc396514c68.tar.gz |
even more decoder optimizations
git-svn-id: http://simplejson.googlecode.com/svn/trunk@104 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'simplejson/scanner.py')
-rw-r--r-- | simplejson/scanner.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/simplejson/scanner.py b/simplejson/scanner.py index 338d2a8..e090bc4 100644 --- a/simplejson/scanner.py +++ b/simplejson/scanner.py @@ -11,24 +11,30 @@ FLAGS = (VERBOSE | MULTILINE | DOTALL) NUMBER_PATTERN = r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?' -def make_scanner(lexicon): +def make_scanner(lexicon, context): parse_object = lexicon['object'] parse_array = lexicon['array'] parse_string = lexicon['string'] match_number = re.compile(NUMBER_PATTERN, FLAGS).match + encoding = context.encoding + strict = context.strict + parse_float = context.parse_float + parse_int = context.parse_int + parse_constant = context.parse_constant + object_hook = context.object_hook - def _scan_once(string, idx, context): + def _scan_once(string, idx): try: nextchar = string[idx] except IndexError: raise StopIteration if nextchar == '"': - return parse_string(string, idx + 1, context.encoding, context.strict) + return parse_string(string, idx + 1, encoding, strict) elif nextchar == '{': - return parse_object((string, idx + 1), context) + return parse_object((string, idx + 1), encoding, strict, _scan_once, object_hook) elif nextchar == '[': - return parse_array((string, idx + 1), context) + return parse_array((string, idx + 1), _scan_once) elif nextchar == 'n' and string[idx:idx + 4] == 'null': return None, idx + 4 elif nextchar == 't' and string[idx:idx + 4] == 'true': @@ -40,16 +46,16 @@ def make_scanner(lexicon): if m is not None: integer, frac, exp = m.groups() if frac or exp: - res = context.parse_float(integer + (frac or '') + (exp or '')) + res = parse_float(integer + (frac or '') + (exp or '')) else: - res = context.parse_int(integer) + res = parse_int(integer) return res, m.end() elif nextchar == 'N' and string[idx:idx + 3] == 'NaN': - return context.parse_constant('NaN'), idx + 3 + return parse_constant('NaN'), idx + 3 elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity': - return context.parse_constant('Infinity'), idx + 8 + return parse_constant('Infinity'), idx + 8 elif nextchar == '-' and string[idx:idx + 9] == '-Infinity': - return context.parse_constant('-Infinity'), idx + 9 + return parse_constant('-Infinity'), idx + 9 else: raise StopIteration |