]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/Lib/json/scanner.py
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 4/5.
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / json / scanner.py
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Lib/json/scanner.py b/AppPkg/Applications/Python/Python-2.7.10/Lib/json/scanner.py
new file mode 100644 (file)
index 0000000..259e955
--- /dev/null
@@ -0,0 +1,67 @@
+"""JSON token scanner\r
+"""\r
+import re\r
+try:\r
+    from _json import make_scanner as c_make_scanner\r
+except ImportError:\r
+    c_make_scanner = None\r
+\r
+__all__ = ['make_scanner']\r
+\r
+NUMBER_RE = re.compile(\r
+    r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',\r
+    (re.VERBOSE | re.MULTILINE | re.DOTALL))\r
+\r
+def py_make_scanner(context):\r
+    parse_object = context.parse_object\r
+    parse_array = context.parse_array\r
+    parse_string = context.parse_string\r
+    match_number = NUMBER_RE.match\r
+    encoding = context.encoding\r
+    strict = context.strict\r
+    parse_float = context.parse_float\r
+    parse_int = context.parse_int\r
+    parse_constant = context.parse_constant\r
+    object_hook = context.object_hook\r
+    object_pairs_hook = context.object_pairs_hook\r
+\r
+    def _scan_once(string, idx):\r
+        try:\r
+            nextchar = string[idx]\r
+        except IndexError:\r
+            raise StopIteration\r
+\r
+        if nextchar == '"':\r
+            return parse_string(string, idx + 1, encoding, strict)\r
+        elif nextchar == '{':\r
+            return parse_object((string, idx + 1), encoding, strict,\r
+                _scan_once, object_hook, object_pairs_hook)\r
+        elif nextchar == '[':\r
+            return parse_array((string, idx + 1), _scan_once)\r
+        elif nextchar == 'n' and string[idx:idx + 4] == 'null':\r
+            return None, idx + 4\r
+        elif nextchar == 't' and string[idx:idx + 4] == 'true':\r
+            return True, idx + 4\r
+        elif nextchar == 'f' and string[idx:idx + 5] == 'false':\r
+            return False, idx + 5\r
+\r
+        m = match_number(string, idx)\r
+        if m is not None:\r
+            integer, frac, exp = m.groups()\r
+            if frac or exp:\r
+                res = parse_float(integer + (frac or '') + (exp or ''))\r
+            else:\r
+                res = parse_int(integer)\r
+            return res, m.end()\r
+        elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':\r
+            return parse_constant('NaN'), idx + 3\r
+        elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':\r
+            return parse_constant('Infinity'), idx + 8\r
+        elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':\r
+            return parse_constant('-Infinity'), idx + 9\r
+        else:\r
+            raise StopIteration\r
+\r
+    return _scan_once\r
+\r
+make_scanner = c_make_scanner or py_make_scanner\r