home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / simplejson / scanner.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  2.1 KB  |  73 lines

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