Back to index

python3.2  3.2.2
Functions | Variables
json.scanner Namespace Reference

Functions

def py_make_scanner

Variables

 c_make_scanner = None
list __all__ = ['make_scanner']
tuple NUMBER_RE
 make_scanner = c_make_scannerorpy_make_scanner

Detailed Description

JSON token scanner

Function Documentation

def json.scanner.py_make_scanner (   context)

Definition at line 15 of file scanner.py.

00015 
00016 def py_make_scanner(context):
00017     parse_object = context.parse_object
00018     parse_array = context.parse_array
00019     parse_string = context.parse_string
00020     match_number = NUMBER_RE.match
00021     strict = context.strict
00022     parse_float = context.parse_float
00023     parse_int = context.parse_int
00024     parse_constant = context.parse_constant
00025     object_hook = context.object_hook
00026     object_pairs_hook = context.object_pairs_hook
00027     memo = context.memo
00028 
00029     def _scan_once(string, idx):
00030         try:
00031             nextchar = string[idx]
00032         except IndexError:
00033             raise StopIteration
00034 
00035         if nextchar == '"':
00036             return parse_string(string, idx + 1, strict)
00037         elif nextchar == '{':
00038             return parse_object((string, idx + 1), strict,
00039                 _scan_once, object_hook, object_pairs_hook, memo)
00040         elif nextchar == '[':
00041             return parse_array((string, idx + 1), _scan_once)
00042         elif nextchar == 'n' and string[idx:idx + 4] == 'null':
00043             return None, idx + 4
00044         elif nextchar == 't' and string[idx:idx + 4] == 'true':
00045             return True, idx + 4
00046         elif nextchar == 'f' and string[idx:idx + 5] == 'false':
00047             return False, idx + 5
00048 
00049         m = match_number(string, idx)
00050         if m is not None:
00051             integer, frac, exp = m.groups()
00052             if frac or exp:
00053                 res = parse_float(integer + (frac or '') + (exp or ''))
00054             else:
00055                 res = parse_int(integer)
00056             return res, m.end()
00057         elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':
00058             return parse_constant('NaN'), idx + 3
00059         elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':
00060             return parse_constant('Infinity'), idx + 8
00061         elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
00062             return parse_constant('-Infinity'), idx + 9
00063         else:
00064             raise StopIteration
00065 
00066     def scan_once(string, idx):
00067         try:
00068             return _scan_once(string, idx)
00069         finally:
00070             memo.clear()
00071 
00072     return _scan_once

Here is the call graph for this function:


Variable Documentation

Definition at line 9 of file scanner.py.

Definition at line 7 of file scanner.py.

json.scanner.make_scanner = c_make_scannerorpy_make_scanner

Definition at line 73 of file scanner.py.

Initial value:
00001 re.compile(
00002     r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
00003     (re.VERBOSE | re.MULTILINE | re.DOTALL))

Definition at line 11 of file scanner.py.