summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2019-08-05 08:32:33 +0000
committerShubham Saini <shubham6405@gmail.com>2019-08-05 08:32:33 +0000
commit227b2d30a8675b44918f9d9ca89b24144a938215 (patch)
tree9f8e6a28724514b6fdf463a9ab2067a7ef309b72 /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py
parent842a8cfbbbdb1f92889d892e4859dbd5d40c5be8 (diff)
removing venv files
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py124
1 files changed, 0 insertions, 124 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py
deleted file mode 100644
index a559fa0..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/_utils.py
+++ /dev/null
@@ -1,124 +0,0 @@
1from __future__ import absolute_import, division, unicode_literals
2
3from types import ModuleType
4
5from pip._vendor.six import text_type
6
7try:
8 import xml.etree.cElementTree as default_etree
9except ImportError:
10 import xml.etree.ElementTree as default_etree
11
12
13__all__ = ["default_etree", "MethodDispatcher", "isSurrogatePair",
14 "surrogatePairToCodepoint", "moduleFactoryFactory",
15 "supports_lone_surrogates"]
16
17
18# Platforms not supporting lone surrogates (\uD800-\uDFFF) should be
19# caught by the below test. In general this would be any platform
20# using UTF-16 as its encoding of unicode strings, such as
21# Jython. This is because UTF-16 itself is based on the use of such
22# surrogates, and there is no mechanism to further escape such
23# escapes.
24try:
25 _x = eval('"\\uD800"') # pylint:disable=eval-used
26 if not isinstance(_x, text_type):
27 # We need this with u"" because of http://bugs.jython.org/issue2039
28 _x = eval('u"\\uD800"') # pylint:disable=eval-used
29 assert isinstance(_x, text_type)
30except: # pylint:disable=bare-except
31 supports_lone_surrogates = False
32else:
33 supports_lone_surrogates = True
34
35
36class MethodDispatcher(dict):
37 """Dict with 2 special properties:
38
39 On initiation, keys that are lists, sets or tuples are converted to
40 multiple keys so accessing any one of the items in the original
41 list-like object returns the matching value
42
43 md = MethodDispatcher({("foo", "bar"):"baz"})
44 md["foo"] == "baz"
45
46 A default value which can be set through the default attribute.
47 """
48
49 def __init__(self, items=()):
50 # Using _dictEntries instead of directly assigning to self is about
51 # twice as fast. Please do careful performance testing before changing
52 # anything here.
53 _dictEntries = []
54 for name, value in items:
55 if isinstance(name, (list, tuple, frozenset, set)):
56 for item in name:
57 _dictEntries.append((item, value))
58 else:
59 _dictEntries.append((name, value))
60 dict.__init__(self, _dictEntries)
61 assert len(self) == len(_dictEntries)
62 self.default = None
63
64 def __getitem__(self, key):
65 return dict.get(self, key, self.default)
66
67
68# Some utility functions to deal with weirdness around UCS2 vs UCS4
69# python builds
70
71def isSurrogatePair(data):
72 return (len(data) == 2 and
73 ord(data[0]) >= 0xD800 and ord(data[0]) <= 0xDBFF and
74 ord(data[1]) >= 0xDC00 and ord(data[1]) <= 0xDFFF)
75
76
77def surrogatePairToCodepoint(data):
78 char_val = (0x10000 + (ord(data[0]) - 0xD800) * 0x400 +
79 (ord(data[1]) - 0xDC00))
80 return char_val
81
82# Module Factory Factory (no, this isn't Java, I know)
83# Here to stop this being duplicated all over the place.
84
85
86def moduleFactoryFactory(factory):
87 moduleCache = {}
88
89 def moduleFactory(baseModule, *args, **kwargs):
90 if isinstance(ModuleType.__name__, type("")):
91 name = "_%s_factory" % baseModule.__name__
92 else:
93 name = b"_%s_factory" % baseModule.__name__
94
95 kwargs_tuple = tuple(kwargs.items())
96
97 try:
98 return moduleCache[name][args][kwargs_tuple]
99 except KeyError:
100 mod = ModuleType(name)
101 objs = factory(baseModule, *args, **kwargs)
102 mod.__dict__.update(objs)
103 if "name" not in moduleCache:
104 moduleCache[name] = {}
105 if "args" not in moduleCache[name]:
106 moduleCache[name][args] = {}
107 if "kwargs" not in moduleCache[name][args]:
108 moduleCache[name][args][kwargs_tuple] = {}
109 moduleCache[name][args][kwargs_tuple] = mod
110 return mod
111
112 return moduleFactory
113
114
115def memoize(func):
116 cache = {}
117
118 def wrapped(*args, **kwargs):
119 key = (tuple(args), tuple(kwargs.items()))
120 if key not in cache:
121 cache[key] = func(*args, **kwargs)
122 return cache[key]
123
124 return wrapped