summaryrefslogtreecommitdiff
path: root/simplejson/scanner.py
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2008-09-24 21:50:30 +0000
committerBob Ippolito <bob@redivi.com>2008-09-24 21:50:30 +0000
commiteea5ce424cfda0e7ffcc95f2bd1a86d26bc82dfc (patch)
treed197367bff0eb16c671bdd804f6f11e82d0c938a /simplejson/scanner.py
parent6896523285b550fe6a1f0293ad36dcc396514c68 (diff)
downloadsimplejson-eea5ce424cfda0e7ffcc95f2bd1a86d26bc82dfc.tar.gz
more decoding perf enhancements, this time with lots of C code (TODO: check for ref leaks)
git-svn-id: http://simplejson.googlecode.com/svn/trunk@105 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'simplejson/scanner.py')
-rw-r--r--simplejson/scanner.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/simplejson/scanner.py b/simplejson/scanner.py
index e090bc4..1bcbcdd 100644
--- a/simplejson/scanner.py
+++ b/simplejson/scanner.py
@@ -1,21 +1,23 @@
"""
-Iterator based sre token scanner
+JSON token scanner
"""
import re
-from re import VERBOSE, MULTILINE, DOTALL
+try:
+ from simplejson._speedups import make_scanner as c_make_scanner
+except ImportError:
+ c_make_scanner = None
__all__ = ['make_scanner']
-FLAGS = (VERBOSE | MULTILINE | DOTALL)
+NUMBER_RE = re.compile(
+ r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
+ (re.VERBOSE | re.MULTILINE | re.DOTALL))
-
-NUMBER_PATTERN = r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?'
-
-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
+def py_make_scanner(context):
+ parse_object = context.parse_object
+ parse_array = context.parse_array
+ parse_string = context.parse_string
+ match_number = NUMBER_RE.match
encoding = context.encoding
strict = context.strict
parse_float = context.parse_float
@@ -59,4 +61,6 @@ def make_scanner(lexicon, context):
else:
raise StopIteration
- return _scan_once \ No newline at end of file
+ return _scan_once
+
+make_scanner = c_make_scanner or py_make_scanner \ No newline at end of file