mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
944423d6ec
--HG-- rename : other-licenses/simplejson-2.1.1/CHANGES.txt => python/simplejson-2.1.1/CHANGES.txt rename : other-licenses/simplejson-2.1.1/LICENSE.txt => python/simplejson-2.1.1/LICENSE.txt rename : other-licenses/simplejson-2.1.1/PKG-INFO => python/simplejson-2.1.1/PKG-INFO rename : other-licenses/simplejson-2.1.1/conf.py => python/simplejson-2.1.1/conf.py rename : other-licenses/simplejson-2.1.1/docs/_sources/index.txt => python/simplejson-2.1.1/docs/_sources/index.txt rename : other-licenses/simplejson-2.1.1/docs/_static/contents.png => python/simplejson-2.1.1/docs/_static/contents.png rename : other-licenses/simplejson-2.1.1/docs/_static/default.css => python/simplejson-2.1.1/docs/_static/default.css rename : other-licenses/simplejson-2.1.1/docs/_static/doctools.js => python/simplejson-2.1.1/docs/_static/doctools.js rename : other-licenses/simplejson-2.1.1/docs/_static/file.png => python/simplejson-2.1.1/docs/_static/file.png rename : other-licenses/simplejson-2.1.1/docs/_static/interface.js => python/simplejson-2.1.1/docs/_static/interface.js rename : other-licenses/simplejson-2.1.1/docs/_static/jquery.js => python/simplejson-2.1.1/docs/_static/jquery.js rename : other-licenses/simplejson-2.1.1/docs/_static/minus.png => python/simplejson-2.1.1/docs/_static/minus.png rename : other-licenses/simplejson-2.1.1/docs/_static/navigation.png => python/simplejson-2.1.1/docs/_static/navigation.png rename : other-licenses/simplejson-2.1.1/docs/_static/plus.png => python/simplejson-2.1.1/docs/_static/plus.png rename : other-licenses/simplejson-2.1.1/docs/_static/pygments.css => python/simplejson-2.1.1/docs/_static/pygments.css rename : other-licenses/simplejson-2.1.1/docs/_static/rightsidebar.css => python/simplejson-2.1.1/docs/_static/rightsidebar.css rename : other-licenses/simplejson-2.1.1/docs/_static/searchtools.js => python/simplejson-2.1.1/docs/_static/searchtools.js rename : other-licenses/simplejson-2.1.1/docs/_static/sphinxdoc.css => python/simplejson-2.1.1/docs/_static/sphinxdoc.css rename : other-licenses/simplejson-2.1.1/docs/_static/stickysidebar.css => python/simplejson-2.1.1/docs/_static/stickysidebar.css rename : other-licenses/simplejson-2.1.1/docs/_static/traditional.css => python/simplejson-2.1.1/docs/_static/traditional.css rename : other-licenses/simplejson-2.1.1/docs/genindex.html => python/simplejson-2.1.1/docs/genindex.html rename : other-licenses/simplejson-2.1.1/docs/index.html => python/simplejson-2.1.1/docs/index.html rename : other-licenses/simplejson-2.1.1/docs/objects.inv => python/simplejson-2.1.1/docs/objects.inv rename : other-licenses/simplejson-2.1.1/docs/search.html => python/simplejson-2.1.1/docs/search.html rename : other-licenses/simplejson-2.1.1/docs/searchindex.js => python/simplejson-2.1.1/docs/searchindex.js rename : other-licenses/simplejson-2.1.1/docs/searchindex.json => python/simplejson-2.1.1/docs/searchindex.json rename : other-licenses/simplejson-2.1.1/ez_setup.py => python/simplejson-2.1.1/ez_setup.py rename : other-licenses/simplejson-2.1.1/index.rst => python/simplejson-2.1.1/index.rst rename : other-licenses/simplejson-2.1.1/scripts/make_docs.py => python/simplejson-2.1.1/scripts/make_docs.py rename : other-licenses/simplejson-2.1.1/setup.cfg => python/simplejson-2.1.1/setup.cfg rename : other-licenses/simplejson-2.1.1/setup.py => python/simplejson-2.1.1/setup.py rename : other-licenses/simplejson-2.1.1/simplejson/__init__.py => python/simplejson-2.1.1/simplejson/__init__.py rename : other-licenses/simplejson-2.1.1/simplejson/_speedups.c => python/simplejson-2.1.1/simplejson/_speedups.c rename : other-licenses/simplejson-2.1.1/simplejson/decoder.py => python/simplejson-2.1.1/simplejson/decoder.py rename : other-licenses/simplejson-2.1.1/simplejson/encoder.py => python/simplejson-2.1.1/simplejson/encoder.py rename : other-licenses/simplejson-2.1.1/simplejson/ordered_dict.py => python/simplejson-2.1.1/simplejson/ordered_dict.py rename : other-licenses/simplejson-2.1.1/simplejson/scanner.py => python/simplejson-2.1.1/simplejson/scanner.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/__init__.py => python/simplejson-2.1.1/simplejson/tests/__init__.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_check_circular.py => python/simplejson-2.1.1/simplejson/tests/test_check_circular.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_decimal.py => python/simplejson-2.1.1/simplejson/tests/test_decimal.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_decode.py => python/simplejson-2.1.1/simplejson/tests/test_decode.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_default.py => python/simplejson-2.1.1/simplejson/tests/test_default.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_dump.py => python/simplejson-2.1.1/simplejson/tests/test_dump.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_encode_basestring_ascii.py => python/simplejson-2.1.1/simplejson/tests/test_encode_basestring_ascii.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_encode_for_html.py => python/simplejson-2.1.1/simplejson/tests/test_encode_for_html.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_fail.py => python/simplejson-2.1.1/simplejson/tests/test_fail.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_float.py => python/simplejson-2.1.1/simplejson/tests/test_float.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_indent.py => python/simplejson-2.1.1/simplejson/tests/test_indent.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_pass1.py => python/simplejson-2.1.1/simplejson/tests/test_pass1.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_pass2.py => python/simplejson-2.1.1/simplejson/tests/test_pass2.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_pass3.py => python/simplejson-2.1.1/simplejson/tests/test_pass3.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_recursion.py => python/simplejson-2.1.1/simplejson/tests/test_recursion.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_scanstring.py => python/simplejson-2.1.1/simplejson/tests/test_scanstring.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_separators.py => python/simplejson-2.1.1/simplejson/tests/test_separators.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_speedups.py => python/simplejson-2.1.1/simplejson/tests/test_speedups.py rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_unicode.py => python/simplejson-2.1.1/simplejson/tests/test_unicode.py rename : other-licenses/simplejson-2.1.1/simplejson/tool.py => python/simplejson-2.1.1/simplejson/tool.py
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
"""JSON token scanner
|
|
"""
|
|
import re
|
|
def _import_c_make_scanner():
|
|
try:
|
|
from simplejson._speedups import make_scanner
|
|
return make_scanner
|
|
except ImportError:
|
|
return None
|
|
c_make_scanner = _import_c_make_scanner()
|
|
|
|
__all__ = ['make_scanner']
|
|
|
|
NUMBER_RE = re.compile(
|
|
r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
|
|
(re.VERBOSE | re.MULTILINE | re.DOTALL))
|
|
|
|
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
|
|
parse_int = context.parse_int
|
|
parse_constant = context.parse_constant
|
|
object_hook = context.object_hook
|
|
object_pairs_hook = context.object_pairs_hook
|
|
memo = context.memo
|
|
|
|
def _scan_once(string, idx):
|
|
try:
|
|
nextchar = string[idx]
|
|
except IndexError:
|
|
raise StopIteration
|
|
|
|
if nextchar == '"':
|
|
return parse_string(string, idx + 1, encoding, strict)
|
|
elif nextchar == '{':
|
|
return parse_object((string, idx + 1), encoding, strict,
|
|
_scan_once, object_hook, object_pairs_hook, memo)
|
|
elif nextchar == '[':
|
|
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':
|
|
return True, idx + 4
|
|
elif nextchar == 'f' and string[idx:idx + 5] == 'false':
|
|
return False, idx + 5
|
|
|
|
m = match_number(string, idx)
|
|
if m is not None:
|
|
integer, frac, exp = m.groups()
|
|
if frac or exp:
|
|
res = parse_float(integer + (frac or '') + (exp or ''))
|
|
else:
|
|
res = parse_int(integer)
|
|
return res, m.end()
|
|
elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':
|
|
return parse_constant('NaN'), idx + 3
|
|
elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':
|
|
return parse_constant('Infinity'), idx + 8
|
|
elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
|
|
return parse_constant('-Infinity'), idx + 9
|
|
else:
|
|
raise StopIteration
|
|
|
|
def scan_once(string, idx):
|
|
try:
|
|
return _scan_once(string, idx)
|
|
finally:
|
|
memo.clear()
|
|
|
|
return scan_once
|
|
|
|
make_scanner = c_make_scanner or py_make_scanner
|