home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 May / maximum-cd-2010-05.iso / DiscContents / boxee-0.9.20.10711.exe / system / python / local / simplejson / scanner.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-11-02  |  2.3 KB  |  75 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. '''JSON token scanner
  5. '''
  6. import re
  7.  
  8. try:
  9.     from simplejson._speedups import make_scanner as c_make_scanner
  10. except ImportError:
  11.     c_make_scanner = None
  12.  
  13. __all__ = [
  14.     'make_scanner']
  15. NUMBER_RE = re.compile('(-?(?:0|[1-9]\\d*))(\\.\\d+)?([eE][-+]?\\d+)?', re.VERBOSE | re.MULTILINE | re.DOTALL)
  16.  
  17. def py_make_scanner(context):
  18.     parse_object = context.parse_object
  19.     parse_array = context.parse_array
  20.     parse_string = context.parse_string
  21.     match_number = NUMBER_RE.match
  22.     encoding = context.encoding
  23.     strict = context.strict
  24.     parse_float = context.parse_float
  25.     parse_int = context.parse_int
  26.     parse_constant = context.parse_constant
  27.     object_hook = context.object_hook
  28.     
  29.     def _scan_once(string, idx):
  30.         
  31.         try:
  32.             nextchar = string[idx]
  33.         except IndexError:
  34.             raise StopIteration
  35.  
  36.         if nextchar == '"':
  37.             return parse_string(string, idx + 1, encoding, strict)
  38.         elif nextchar == '{':
  39.             return parse_object((string, idx + 1), encoding, strict, _scan_once, object_hook)
  40.         elif nextchar == '[':
  41.             return parse_array((string, idx + 1), _scan_once)
  42.         elif nextchar == 'n' and string[idx:idx + 4] == 'null':
  43.             return (None, idx + 4)
  44.         elif nextchar == 't' and string[idx:idx + 4] == 'true':
  45.             return (True, idx + 4)
  46.         elif nextchar == 'f' and string[idx:idx + 5] == 'false':
  47.             return (False, idx + 5)
  48.         
  49.         m = match_number(string, idx)
  50.         if m is not None:
  51.             (integer, frac, exp) = m.groups()
  52.             if frac or exp:
  53.                 if not frac:
  54.                     pass
  55.                 if not exp:
  56.                     pass
  57.                 res = parse_float(integer + '' + '')
  58.             else:
  59.                 res = parse_int(integer)
  60.             return (res, m.end())
  61.         elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':
  62.             return (parse_constant('NaN'), idx + 3)
  63.         elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':
  64.             return (parse_constant('Infinity'), idx + 8)
  65.         elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
  66.             return (parse_constant('-Infinity'), idx + 9)
  67.         else:
  68.             raise StopIteration
  69.  
  70.     return _scan_once
  71.  
  72. if not c_make_scanner:
  73.     pass
  74. make_scanner = py_make_scanner
  75.