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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import absolute_import
|
2 |
+
|
3 |
+
import functools
|
4 |
+
import itertools
|
5 |
+
import operator
|
6 |
+
import sys
|
7 |
+
import types
|
8 |
+
|
9 |
+
__author__ = "Benjamin Peterson <benjamin@python.org>"
|
10 |
+
__version__ = "1.9.0"
|
11 |
+
|
12 |
+
|
13 |
+
# Useful for very coarse version differentiation.
|
14 |
+
PY2 = sys.version_info[0] == 2
|
15 |
+
PY3 = sys.version_info[0] == 3
|
16 |
+
|
17 |
+
if PY3:
|
18 |
+
string_types = str,
|
19 |
+
integer_types = int,
|
20 |
+
class_types = type,
|
21 |
+
text_type = str
|
22 |
+
binary_type = bytes
|
23 |
+
|
24 |
+
MAXSIZE = sys.maxsize
|
25 |
+
else:
|
26 |
+
string_types = basestring,
|
27 |
+
integer_types = (int, long)
|
28 |
+
class_types = (type, types.ClassType)
|
29 |
+
text_type = unicode
|
30 |
+
binary_type = str
|
31 |
+
|
32 |
+
if sys.platform.startswith("java"):
|
33 |
+
# Jython always uses 32 bits.
|
34 |
+
MAXSIZE = int((1 << 31) - 1)
|
35 |
+
else:
|
36 |
+
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
|
37 |
+
class X(object):
|
38 |
+
def __len__(self):
|
39 |
+
return 1 << 31
|
40 |
+
try:
|
41 |
+
len(X())
|
42 |
+
except OverflowError:
|
43 |
+
# 32-bit
|
44 |
+
MAXSIZE = int((1 << 31) - 1)
|
45 |
+
else:
|
46 |
+
# 64-bit
|
47 |
+
MAXSIZE = int((1 << 63) - 1)
|
48 |
+
del X
|
49 |
+
|
50 |
+
|
51 |
+
def _add_doc(func, doc):
|
52 |
+
"""Add documentation to a function."""
|
53 |
+
func.__doc__ = doc
|
54 |
+
|
55 |
+
|
56 |
+
def _import_module(name):
|
57 |
+
"""Import module, returning the module after the last dot."""
|
58 |
+
__import__(name)
|
59 |
+
return sys.modules[name]
|
60 |
+
|
61 |
+
|
62 |
+
class _LazyDescr(object):
|
63 |
+
|
64 |
+
def __init__(self, name):
|
65 |
+
self.name = name
|
66 |
+
|
67 |
+
def __get__(self, obj, tp):
|
68 |
+
result = self._resolve()
|
69 |
+
setattr(obj, self.name, result) # Invokes __set__.
|
70 |
+
try:
|
71 |
+
# This is a bit ugly, but it avoids running this again by
|
72 |
+
# removing this descriptor.
|
73 |
+
delattr(obj.__class__, self.name)
|
74 |
+
except AttributeError:
|
75 |
+
pass
|
76 |
+
return result
|
77 |
+
|
78 |
+
|
79 |
+
class MovedModule(_LazyDescr):
|
80 |
+
|
81 |
+
def __init__(self, name, old, new=None):
|
82 |
+
super(MovedModule, self).__init__(name)
|
83 |
+
if PY3:
|
84 |
+
if new is None:
|
85 |
+
new = name
|
86 |
+
self.mod = new
|
87 |
+
else:
|
88 |
+
self.mod = old
|
89 |
+
|
90 |
+
def _resolve(self):
|
91 |
+
return _import_module(self.mod)
|
92 |
+
|
93 |
+
def __getattr__(self, attr):
|
94 |
+
_module = self._resolve()
|
95 |
+
value = getattr(_module, attr)
|
96 |
+
setattr(self, attr, value)
|
97 |
+
return value
|
98 |
+
|
99 |
+
|
100 |
+
class _LazyModule(types.ModuleType):
|
101 |
+
|
102 |
+
def __init__(self, name):
|
103 |
+
super(_LazyModule, self).__init__(name)
|
104 |
+
self.__doc__ = self.__class__.__doc__
|
105 |
+
|
106 |
+
def __dir__(self):
|
107 |
+
attrs = ["__doc__", "__name__"]
|
108 |
+
attrs += [attr.name for attr in self._moved_attributes]
|
109 |
+
return attrs
|
110 |
+
|
111 |
+
# Subclasses should override this
|
112 |
+
_moved_attributes = []
|
113 |
+
|
114 |
+
|
115 |
+
class MovedAttribute(_LazyDescr):
|
116 |
+
|
117 |
+
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
|
118 |
+
super(MovedAttribute, self).__init__(name)
|
119 |
+
if PY3:
|
120 |
+
if new_mod is None:
|
121 |
+
new_mod = name
|
122 |
+
self.mod = new_mod
|
123 |
+
if new_attr is None:
|
124 |
+
if old_attr is None:
|
125 |
+
new_attr = name
|
126 |
+
else:
|
127 |
+
new_attr = old_attr
|
128 |
+
self.attr = new_attr
|
129 |
+
else:
|
130 |
+
self.mod = old_mod
|
131 |
+
if old_attr is None:
|
132 |
+
old_attr = name
|
133 |
+
self.attr = old_attr
|
134 |
+
|
135 |
+
def _resolve(self):
|
136 |
+
module = _import_module(self.mod)
|
137 |
+
return getattr(module, self.attr)
|
138 |
+
|
139 |
+
|
140 |
+
class _SixMetaPathImporter(object):
|
141 |
+
"""
|
142 |
+
A meta path importer to import six.moves and its submodules.
|
143 |
+
|
144 |
+
This class implements a PEP302 finder and loader. It should be compatible
|
145 |
+
with Python 2.5 and all existing versions of Python3
|
146 |
+
"""
|
147 |
+
|
148 |
+
def __init__(self, six_module_name):
|
149 |
+
self.name = six_module_name
|
150 |
+
self.known_modules = {}
|
151 |
+
|
152 |
+
def _add_module(self, mod, *fullnames):
|
153 |
+
for fullname in fullnames:
|
154 |
+
self.known_modules[self.name + "." + fullname] = mod
|
155 |
+
|
156 |
+
def _get_module(self, fullname):
|
157 |
+
return self.known_modules[self.name + "." + fullname]
|
158 |
+
|
159 |
+
def find_module(self, fullname, path=None):
|
160 |
+
if fullname in self.known_modules:
|
161 |
+
return self
|
162 |
+
return None
|
163 |
+
|
164 |
+
def __get_module(self, fullname):
|
165 |
+
try:
|
166 |
+
return self.known_modules[fullname]
|
167 |
+
except KeyError:
|
168 |
+
raise ImportError("This loader does not know module " + fullname)
|
169 |
+
|
170 |
+
def load_module(self, fullname):
|
171 |
+
try:
|
172 |
+
# in case of a reload
|
173 |
+
return sys.modules[fullname]
|
174 |
+
except KeyError:
|
175 |
+
pass
|
176 |
+
mod = self.__get_module(fullname)
|
177 |
+
if isinstance(mod, MovedModule):
|
178 |
+
mod = mod._resolve()
|
179 |
+
else:
|
180 |
+
mod.__loader__ = self
|
181 |
+
sys.modules[fullname] = mod
|
182 |
+
return mod
|
183 |
+
|
184 |
+
def is_package(self, fullname):
|
185 |
+
"""
|
186 |
+
Return true, if the named module is a package.
|
187 |
+
|
188 |
+
We need this method to get correct spec objects with
|
189 |
+
Python 3.4 (see PEP451)
|
190 |
+
"""
|
191 |
+
return hasattr(self.__get_module(fullname), "__path__")
|
192 |
+
|
193 |
+
def get_code(self, fullname):
|
194 |
+
"""Return None
|
195 |
+
|
196 |
+
Required, if is_package is implemented"""
|
197 |
+
self.__get_module(fullname) # eventually raises ImportError
|
198 |
+
return None
|
199 |
+
get_source = get_code # same as get_code
|
200 |
+
|
201 |
+
|
202 |
+
_importer = _SixMetaPathImporter(__name__)
|
203 |
+
|
204 |
+
|
205 |
+
class _MovedItems(_LazyModule):
|
206 |
+
"""Lazy loading of moved objects"""
|
207 |
+
__path__ = [] # mark as package
|
208 |
+
|
209 |
+
|
210 |
+
_moved_attributes = [
|
211 |
+
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
|
212 |
+
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
|
213 |
+
MovedAttribute("filterfalse", "itertools", "itertools",
|
214 |
+
"ifilterfalse", "filterfalse"),
|
215 |
+
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
|
216 |
+
MovedAttribute("intern", "__builtin__", "sys"),
|
217 |
+
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
|
218 |
+
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
|
219 |
+
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
|
220 |
+
MovedAttribute("reduce", "__builtin__", "functools"),
|
221 |
+
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
|
222 |
+
MovedAttribute("StringIO", "StringIO", "io"),
|
223 |
+
MovedAttribute("UserDict", "UserDict", "collections"),
|
224 |
+
MovedAttribute("UserList", "UserList", "collections"),
|
225 |
+
MovedAttribute("UserString", "UserString", "collections"),
|
226 |
+
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
|
227 |
+
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
|
228 |
+
MovedAttribute("zip_longest", "itertools", "itertools",
|
229 |
+
"izip_longest", "zip_longest"),
|
230 |
+
|
231 |
+
MovedModule("builtins", "__builtin__"),
|
232 |
+
MovedModule("configparser", "ConfigParser"),
|
233 |
+
MovedModule("copyreg", "copy_reg"),
|
234 |
+
MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
|
235 |
+
MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"),
|
236 |
+
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
|
237 |
+
MovedModule("http_cookies", "Cookie", "http.cookies"),
|
238 |
+
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
|
239 |
+
MovedModule("html_parser", "HTMLParser", "html.parser"),
|
240 |
+
MovedModule("http_client", "httplib", "http.client"),
|
241 |
+
MovedModule("email_mime_multipart", "email.MIMEMultipart",
|
242 |
+
"email.mime.multipart"),
|
243 |
+
MovedModule("email_mime_nonmultipart",
|
244 |
+
"email.MIMENonMultipart", "email.mime.nonmultipart"),
|
245 |
+
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
|
246 |
+
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
|
247 |
+
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
|
248 |
+
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
|
249 |
+
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
|
250 |
+
MovedModule("cPickle", "cPickle", "pickle"),
|
251 |
+
MovedModule("queue", "Queue"),
|
252 |
+
MovedModule("reprlib", "repr"),
|
253 |
+
MovedModule("socketserver", "SocketServer"),
|
254 |
+
MovedModule("_thread", "thread", "_thread"),
|
255 |
+
MovedModule("tkinter", "Tkinter"),
|
256 |
+
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
|
257 |
+
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
|
258 |
+
MovedModule("tkinter_scrolledtext", "ScrolledText",
|
259 |
+
"tkinter.scrolledtext"),
|
260 |
+
MovedModule("tkinter_simpledialog", "SimpleDialog",
|
261 |
+
"tkinter.simpledialog"),
|
262 |
+
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
|
263 |
+
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
|
264 |
+
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
|
265 |
+
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
|
266 |
+
MovedModule("tkinter_colorchooser", "tkColorChooser",
|
267 |
+
"tkinter.colorchooser"),
|
268 |
+
MovedModule("tkinter_commondialog", "tkCommonDialog",
|
269 |
+
"tkinter.commondialog"),
|
270 |
+
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
|
271 |
+
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
|
272 |
+
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
|
273 |
+
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
|
274 |
+
"tkinter.simpledialog"),
|
275 |
+
MovedModule("urllib_parse", __name__ +
|
276 |
+
".moves.urllib_parse", "urllib.parse"),
|
277 |
+
MovedModule("urllib_error", __name__ +
|
278 |
+
".moves.urllib_error", "urllib.error"),
|
279 |
+
MovedModule("urllib", __name__ + ".moves.urllib",
|
280 |
+
__name__ + ".moves.urllib"),
|
281 |
+
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
|
282 |
+
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
|
283 |
+
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
|
284 |
+
MovedModule("winreg", "_winreg"),
|
285 |
+
]
|
286 |
+
for attr in _moved_attributes:
|
287 |
+
setattr(_MovedItems, attr.name, attr)
|
288 |
+
if isinstance(attr, MovedModule):
|
289 |
+
_importer._add_module(attr, "moves." + attr.name)
|
290 |
+
del attr
|
291 |
+
|
292 |
+
_MovedItems._moved_attributes = _moved_attributes
|
293 |
+
|
294 |
+
moves = _MovedItems(__name__ + ".moves")
|
295 |
+
_importer._add_module(moves, "moves")
|
296 |
+
|
297 |
+
|
298 |
+
class Module_six_moves_urllib_parse(_LazyModule):
|
299 |
+
"""Lazy loading of moved objects in six.moves.urllib_parse"""
|
300 |
+
|
301 |
+
|
302 |
+
_urllib_parse_moved_attributes = [
|
303 |
+
MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
|
304 |
+
MovedAttribute("SplitResult", "urlparse", "urllib.parse"),
|
305 |
+
MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
|
306 |
+
MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
|
307 |
+
MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
|
308 |
+
MovedAttribute("urljoin", "urlparse", "urllib.parse"),
|
309 |
+
MovedAttribute("urlparse", "urlparse", "urllib.parse"),
|
310 |
+
MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
|
311 |
+
MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
|
312 |
+
MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
|
313 |
+
MovedAttribute("quote", "urllib", "urllib.parse"),
|
314 |
+
MovedAttribute("quote_plus", "urllib", "urllib.parse"),
|
315 |
+
MovedAttribute("unquote", "urllib", "urllib.parse"),
|
316 |
+
MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
|
317 |
+
MovedAttribute("urlencode", "urllib", "urllib.parse"),
|
318 |
+
MovedAttribute("splitquery", "urllib", "urllib.parse"),
|
319 |
+
MovedAttribute("splittag", "urllib", "urllib.parse"),
|
320 |
+
MovedAttribute("splituser", "urllib", "urllib.parse"),
|
321 |
+
MovedAttribute("uses_fragment", "urlparse", "urllib.parse"),
|
322 |
+
MovedAttribute("uses_netloc", "urlparse", "urllib.parse"),
|
323 |
+
MovedAttribute("uses_params", "urlparse", "urllib.parse"),
|
324 |
+
MovedAttribute("uses_query", "urlparse", "urllib.parse"),
|
325 |
+
MovedAttribute("uses_relative", "urlparse", "urllib.parse"),
|
326 |
+
]
|
327 |
+
for attr in _urllib_parse_moved_attributes:
|
328 |
+
setattr(Module_six_moves_urllib_parse, attr.name, attr)
|
329 |
+
del attr
|
330 |
+
|
331 |
+
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
|
332 |
+
|
333 |
+
_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"),
|
334 |
+
"moves.urllib_parse", "moves.urllib.parse")
|
335 |
+
|
336 |
+
|
337 |
+
class Module_six_moves_urllib_error(_LazyModule):
|
338 |
+
"""Lazy loading of moved objects in six.moves.urllib_error"""
|
339 |
+
|
340 |
+
|
341 |
+
_urllib_error_moved_attributes = [
|
342 |
+
MovedAttribute("URLError", "urllib2", "urllib.error"),
|
343 |
+
MovedAttribute("HTTPError", "urllib2", "urllib.error"),
|
344 |
+
MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
|
345 |
+
]
|
346 |
+
for attr in _urllib_error_moved_attributes:
|
347 |
+
setattr(Module_six_moves_urllib_error, attr.name, attr)
|
348 |
+
del attr
|
349 |
+
|
350 |
+
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
|
351 |
+
|
352 |
+
_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"),
|
353 |
+
"moves.urllib_error", "moves.urllib.error")
|
354 |
+
|
355 |
+
|
356 |
+
class Module_six_moves_urllib_request(_LazyModule):
|
357 |
+
"""Lazy loading of moved objects in six.moves.urllib_request"""
|
358 |
+
|
359 |
+
|
360 |
+
_urllib_request_moved_attributes = [
|
361 |
+
MovedAttribute("urlopen", "urllib2", "urllib.request"),
|
362 |
+
MovedAttribute("install_opener", "urllib2", "urllib.request"),
|
363 |
+
MovedAttribute("build_opener", "urllib2", "urllib.request"),
|
364 |
+
MovedAttribute("pathname2url", "urllib", "urllib.request"),
|
365 |
+
MovedAttribute("url2pathname", "urllib", "urllib.request"),
|
366 |
+
MovedAttribute("getproxies", "urllib", "urllib.request"),
|
367 |
+
MovedAttribute("Request", "urllib2", "urllib.request"),
|
368 |
+
MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
|
369 |
+
MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
|
370 |
+
MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
|
371 |
+
MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
|
372 |
+
MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
|
373 |
+
MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
|
374 |
+
MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
|
375 |
+
MovedAttribute("HTTPPasswordMgrWithDefaultRealm",
|
376 |
+
"urllib2", "urllib.request"),
|
377 |
+
MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
|
378 |
+
MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
|
379 |
+
MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
|
380 |
+
MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
|
381 |
+
MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
|
382 |
+
MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
|
383 |
+
MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
|
384 |
+
MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
|
385 |
+
MovedAttribute("FileHandler", "urllib2", "urllib.request"),
|
386 |
+
MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
|
387 |
+
MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
|
388 |
+
MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
|
389 |
+
MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
|
390 |
+
MovedAttribute("urlretrieve", "urllib", "urllib.request"),
|
391 |
+
MovedAttribute("urlcleanup", "urllib", "urllib.request"),
|
392 |
+
MovedAttribute("URLopener", "urllib", "urllib.request"),
|
393 |
+
MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
|
394 |
+
MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
|
395 |
+
]
|
396 |
+
for attr in _urllib_request_moved_attributes:
|
397 |
+
setattr(Module_six_moves_urllib_request, attr.name, attr)
|
398 |
+
del attr
|
399 |
+
|
400 |
+
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
|
401 |
+
|
402 |
+
_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"),
|
403 |
+
"moves.urllib_request", "moves.urllib.request")
|
404 |
+
|
405 |
+
|
406 |
+
class Module_six_moves_urllib_response(_LazyModule):
|
407 |
+
"""Lazy loading of moved objects in six.moves.urllib_response"""
|
408 |
+
|
409 |
+
|
410 |
+
_urllib_response_moved_attributes = [
|
411 |
+
MovedAttribute("addbase", "urllib", "urllib.response"),
|
412 |
+
MovedAttribute("addclosehook", "urllib", "urllib.response"),
|
413 |
+
MovedAttribute("addinfo", "urllib", "urllib.response"),
|
414 |
+
MovedAttribute("addinfourl", "urllib", "urllib.response"),
|
415 |
+
]
|
416 |
+
for attr in _urllib_response_moved_attributes:
|
417 |
+
setattr(Module_six_moves_urllib_response, attr.name, attr)
|
418 |
+
del attr
|
419 |
+
|
420 |
+
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
|
421 |
+
|
422 |
+
_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"),
|
423 |
+
"moves.urllib_response", "moves.urllib.response")
|
424 |
+
|
425 |
+
|
426 |
+
class Module_six_moves_urllib_robotparser(_LazyModule):
|
427 |
+
"""Lazy loading of moved objects in six.moves.urllib_robotparser"""
|
428 |
+
|
429 |
+
|
430 |
+
_urllib_robotparser_moved_attributes = [
|
431 |
+
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
|
432 |
+
]
|
433 |
+
for attr in _urllib_robotparser_moved_attributes:
|
434 |
+
setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
|
435 |
+
del attr
|
436 |
+
|
437 |
+
Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
|
438 |
+
|
439 |
+
_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"),
|
440 |
+
"moves.urllib_robotparser", "moves.urllib.robotparser")
|
441 |
+
|
442 |
+
|
443 |
+
class Module_six_moves_urllib(types.ModuleType):
|
444 |
+
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
|
445 |
+
__path__ = [] # mark as package
|
446 |
+
parse = _importer._get_module("moves.urllib_parse")
|
447 |
+
error = _importer._get_module("moves.urllib_error")
|
448 |
+
request = _importer._get_module("moves.urllib_request")
|
449 |
+
response = _importer._get_module("moves.urllib_response")
|
450 |
+
robotparser = _importer._get_module("moves.urllib_robotparser")
|
451 |
+
|
452 |
+
def __dir__(self):
|
453 |
+
return ['parse', 'error', 'request', 'response', 'robotparser']
|
454 |
+
|
455 |
+
|
456 |
+
_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"),
|
457 |
+
"moves.urllib")
|
458 |
+
|
459 |
+
|
460 |
+
def add_move(move):
|
461 |
+
"""Add an item to six.moves."""
|
462 |
+
setattr(_MovedItems, move.name, move)
|
463 |
+
|
464 |
+
|
465 |
+
def remove_move(name):
|
466 |
+
"""Remove item from six.moves."""
|
467 |
+
try:
|
468 |
+
delattr(_MovedItems, name)
|
469 |
+
except AttributeError:
|
470 |
+
try:
|
471 |
+
del moves.__dict__[name]
|
472 |
+
except KeyError:
|
473 |
+
raise AttributeError("no such move, %r" % (name,))
|
474 |
+
|
475 |
+
|
476 |
+
if PY3:
|
477 |
+
_meth_func = "__func__"
|
478 |
+
_meth_self = "__self__"
|
479 |
+
|
480 |
+
_func_closure = "__closure__"
|
481 |
+
_func_code = "__code__"
|
482 |
+
_func_defaults = "__defaults__"
|
483 |
+
_func_globals = "__globals__"
|
484 |
+
else:
|
485 |
+
_meth_func = "im_func"
|
486 |
+
_meth_self = "im_self"
|
487 |
+
|
488 |
+
_func_closure = "func_closure"
|
489 |
+
_func_code = "func_code"
|
490 |
+
_func_defaults = "func_defaults"
|
491 |
+
_func_globals = "func_globals"
|
492 |
+
|
493 |
+
|
494 |
+
try:
|
495 |
+
advance_iterator = next
|
496 |
+
except NameError:
|
497 |
+
def advance_iterator(it):
|
498 |
+
return it.next()
|
499 |
+
next = advance_iterator
|
500 |
+
|
501 |
+
|
502 |
+
try:
|
503 |
+
callable = callable
|
504 |
+
except NameError:
|
505 |
+
def callable(obj):
|
506 |
+
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
|
507 |
+
|
508 |
+
|
509 |
+
if PY3:
|
510 |
+
def get_unbound_function(unbound):
|
511 |
+
return unbound
|
512 |
+
|
513 |
+
create_bound_method = types.MethodType
|
514 |
+
|
515 |
+
Iterator = object
|
516 |
+
else:
|
517 |
+
def get_unbound_function(unbound):
|
518 |
+
return unbound.im_func
|
519 |
+
|
520 |
+
def create_bound_method(func, obj):
|
521 |
+
return types.MethodType(func, obj, obj.__class__)
|
522 |
+
|
523 |
+
class Iterator(object):
|
524 |
+
|
525 |
+
def next(self):
|
526 |
+
return type(self).__next__(self)
|
527 |
+
|
528 |
+
callable = callable
|
529 |
+
_add_doc(get_unbound_function,
|
530 |
+
"""Get the function out of a possibly unbound function""")
|
531 |
+
|
532 |
+
|
533 |
+
get_method_function = operator.attrgetter(_meth_func)
|
534 |
+
get_method_self = operator.attrgetter(_meth_self)
|
535 |
+
get_function_closure = operator.attrgetter(_func_closure)
|
536 |
+
get_function_code = operator.attrgetter(_func_code)
|
537 |
+
get_function_defaults = operator.attrgetter(_func_defaults)
|
538 |
+
get_function_globals = operator.attrgetter(_func_globals)
|
539 |
+
|
540 |
+
|
541 |
+
if PY3:
|
542 |
+
def iterkeys(d, **kw):
|
543 |
+
return iter(d.keys(**kw))
|
544 |
+
|
545 |
+
def itervalues(d, **kw):
|
546 |
+
return iter(d.values(**kw))
|
547 |
+
|
548 |
+
def iteritems(d, **kw):
|
549 |
+
return iter(d.items(**kw))
|
550 |
+
|
551 |
+
def iterlists(d, **kw):
|
552 |
+
return iter(d.lists(**kw))
|
553 |
+
|
554 |
+
viewkeys = operator.methodcaller("keys")
|
555 |
+
|
556 |
+
viewvalues = operator.methodcaller("values")
|
557 |
+
|
558 |
+
viewitems = operator.methodcaller("items")
|
559 |
+
else:
|
560 |
+
def iterkeys(d, **kw):
|
561 |
+
return iter(d.iterkeys(**kw))
|
562 |
+
|
563 |
+
def itervalues(d, **kw):
|
564 |
+
return iter(d.itervalues(**kw))
|
565 |
+
|
566 |
+
def iteritems(d, **kw):
|
567 |
+
return iter(d.iteritems(**kw))
|
568 |
+
|
569 |
+
def iterlists(d, **kw):
|
570 |
+
return iter(d.iterlists(**kw))
|
571 |
+
|
572 |
+
viewkeys = operator.methodcaller("viewkeys")
|
573 |
+
|
574 |
+
viewvalues = operator.methodcaller("viewvalues")
|
575 |
+
|
576 |
+
viewitems = operator.methodcaller("viewitems")
|
577 |
+
|
578 |
+
_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.")
|
579 |
+
_add_doc(itervalues, "Return an iterator over the values of a dictionary.")
|
580 |
+
_add_doc(iteritems,
|
581 |
+
"Return an iterator over the (key, value) pairs of a dictionary.")
|
582 |
+
_add_doc(iterlists,
|
583 |
+
"Return an iterator over the (key, [values]) pairs of a dictionary.")
|
584 |
+
|
585 |
+
|
586 |
+
if PY3:
|
587 |
+
def b(s):
|
588 |
+
return s.encode("latin-1")
|
589 |
+
|
590 |
+
def u(s):
|
591 |
+
return s
|
592 |
+
unichr = chr
|
593 |
+
if sys.version_info[1] <= 1:
|
594 |
+
def int2byte(i):
|
595 |
+
return bytes((i,))
|
596 |
+
else:
|
597 |
+
# This is about 2x faster than the implementation above on 3.2+
|
598 |
+
int2byte = operator.methodcaller("to_bytes", 1, "big")
|
599 |
+
byte2int = operator.itemgetter(0)
|
600 |
+
indexbytes = operator.getitem
|
601 |
+
iterbytes = iter
|
602 |
+
import io
|
603 |
+
StringIO = io.StringIO
|
604 |
+
BytesIO = io.BytesIO
|
605 |
+
_assertCountEqual = "assertCountEqual"
|
606 |
+
_assertRaisesRegex = "assertRaisesRegex"
|
607 |
+
_assertRegex = "assertRegex"
|
608 |
+
else:
|
609 |
+
def b(s):
|
610 |
+
return s
|
611 |
+
# Workaround for standalone backslash
|
612 |
+
|
613 |
+
def u(s):
|
614 |
+
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
|
615 |
+
unichr = unichr
|
616 |
+
int2byte = chr
|
617 |
+
|
618 |
+
def byte2int(bs):
|
619 |
+
return ord(bs[0])
|
620 |
+
|
621 |
+
def indexbytes(buf, i):
|
622 |
+
return ord(buf[i])
|
623 |
+
iterbytes = functools.partial(itertools.imap, ord)
|
624 |
+
import StringIO
|
625 |
+
StringIO = BytesIO = StringIO.StringIO
|
626 |
+
_assertCountEqual = "assertItemsEqual"
|
627 |
+
_assertRaisesRegex = "assertRaisesRegexp"
|
628 |
+
_assertRegex = "assertRegexpMatches"
|
629 |
+
_add_doc(b, """Byte literal""")
|
630 |
+
_add_doc(u, """Text literal""")
|
631 |
+
|
632 |
+
|
633 |
+
def assertCountEqual(self, *args, **kwargs):
|
634 |
+
return getattr(self, _assertCountEqual)(*args, **kwargs)
|
635 |
+
|
636 |
+
|
637 |
+
def assertRaisesRegex(self, *args, **kwargs):
|
638 |
+
return getattr(self, _assertRaisesRegex)(*args, **kwargs)
|
639 |
+
|
640 |
+
|
641 |
+
def assertRegex(self, *args, **kwargs):
|
642 |
+
return getattr(self, _assertRegex)(*args, **kwargs)
|
643 |
+
|
644 |
+
|
645 |
+
if PY3:
|
646 |
+
exec_ = getattr(moves.builtins, "exec")
|
647 |
+
|
648 |
+
def reraise(tp, value, tb=None):
|
649 |
+
if value is None:
|
650 |
+
value = tp()
|
651 |
+
if value.__traceback__ is not tb:
|
652 |
+
raise value.with_traceback(tb)
|
653 |
+
raise value
|
654 |
+
|
655 |
+
else:
|
656 |
+
def exec_(_code_, _globs_=None, _locs_=None):
|
657 |
+
"""Execute code in a namespace."""
|
658 |
+
if _globs_ is None:
|
659 |
+
frame = sys._getframe(1)
|
660 |
+
_globs_ = frame.f_globals
|
661 |
+
if _locs_ is None:
|
662 |
+
_locs_ = frame.f_locals
|
663 |
+
del frame
|
664 |
+
elif _locs_ is None:
|
665 |
+
_locs_ = _globs_
|
666 |
+
exec("""exec _code_ in _globs_, _locs_""")
|
667 |
+
|
668 |
+
exec_("""def reraise(tp, value, tb=None):
|
669 |
+
raise tp, value, tb
|
670 |
+
""")
|
671 |
+
|
672 |
+
|
673 |
+
if sys.version_info[:2] == (3, 2):
|
674 |
+
exec_("""def raise_from(value, from_value):
|
675 |
+
if from_value is None:
|
676 |
+
raise value
|
677 |
+
raise value from from_value
|
678 |
+
""")
|
679 |
+
elif sys.version_info[:2] > (3, 2):
|
680 |
+
exec_("""def raise_from(value, from_value):
|
681 |
+
raise value from from_value
|
682 |
+
""")
|
683 |
+
else:
|
684 |
+
def raise_from(value, from_value):
|
685 |
+
raise value
|
686 |
+
|
687 |
+
|
688 |
+
print_ = getattr(moves.builtins, "print", None)
|
689 |
+
if print_ is None:
|
690 |
+
def print_(*args, **kwargs):
|
691 |
+
"""The new-style print function for Python 2.4 and 2.5."""
|
692 |
+
fp = kwargs.pop("file", sys.stdout)
|
693 |
+
if fp is None:
|
694 |
+
return
|
695 |
+
|
696 |
+
def write(data):
|
697 |
+
if not isinstance(data, basestring):
|
698 |
+
data = str(data)
|
699 |
+
# If the file has an encoding, encode unicode with it.
|
700 |
+
if (isinstance(fp, file) and
|
701 |
+
isinstance(data, unicode) and
|
702 |
+
fp.encoding is not None):
|
703 |
+
errors = getattr(fp, "errors", None)
|
704 |
+
if errors is None:
|
705 |
+
errors = "strict"
|
706 |
+
data = data.encode(fp.encoding, errors)
|
707 |
+
fp.write(data)
|
708 |
+
want_unicode = False
|
709 |
+
sep = kwargs.pop("sep", None)
|
710 |
+
if sep is not None:
|
711 |
+
if isinstance(sep, unicode):
|
712 |
+
want_unicode = True
|
713 |
+
elif not isinstance(sep, str):
|
714 |
+
raise TypeError("sep must be None or a string")
|
715 |
+
end = kwargs.pop("end", None)
|
716 |
+
if end is not None:
|
717 |
+
if isinstance(end, unicode):
|
718 |
+
want_unicode = True
|
719 |
+
elif not isinstance(end, str):
|
720 |
+
raise TypeError("end must be None or a string")
|
721 |
+
if kwargs:
|
722 |
+
raise TypeError("invalid keyword arguments to print()")
|
723 |
+
if not want_unicode:
|
724 |
+
for arg in args:
|
725 |
+
if isinstance(arg, unicode):
|
726 |
+
want_unicode = True
|
727 |
+
break
|
728 |
+
if want_unicode:
|
729 |
+
newline = unicode("\n")
|
730 |
+
space = unicode(" ")
|
731 |
+
else:
|
732 |
+
newline = "\n"
|
733 |
+
space = " "
|
734 |
+
if sep is None:
|
735 |
+
sep = space
|
736 |
+
if end is None:
|
737 |
+
end = newline
|
738 |
+
for i, arg in enumerate(args):
|
739 |
+
if i:
|
740 |
+
write(sep)
|
741 |
+
write(arg)
|
742 |
+
write(end)
|
743 |
+
if sys.version_info[:2] < (3, 3):
|
744 |
+
_print = print_
|
745 |
+
|
746 |
+
def print_(*args, **kwargs):
|
747 |
+
fp = kwargs.get("file", sys.stdout)
|
748 |
+
flush = kwargs.pop("flush", False)
|
749 |
+
_print(*args, **kwargs)
|
750 |
+
if flush and fp is not None:
|
751 |
+
fp.flush()
|
752 |
+
|
753 |
+
_add_doc(reraise, """Reraise an exception.""")
|
754 |
+
|
755 |
+
if sys.version_info[0:2] < (3, 4):
|
756 |
+
def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
|
757 |
+
updated=functools.WRAPPER_UPDATES):
|
758 |
+
def wrapper(f):
|
759 |
+
f = functools.wraps(wrapped, assigned, updated)(f)
|
760 |
+
f.__wrapped__ = wrapped
|
761 |
+
return f
|
762 |
+
return wrapper
|
763 |
+
else:
|
764 |
+
wraps = functools.wraps
|
765 |
+
|
766 |
+
|
767 |
+
def with_metaclass(meta, *bases):
|
768 |
+
"""Create a base class with a metaclass."""
|
769 |
+
# This requires a bit of explanation: the basic idea is to make a dummy
|
770 |
+
# metaclass for one level of class instantiation that replaces itself with
|
771 |
+
# the actual metaclass.
|
772 |
+
class metaclass(meta):
|
773 |
+
def __new__(cls, name, this_bases, d):
|
774 |
+
return meta(name, bases, d)
|
775 |
+
return type.__new__(metaclass, 'temporary_class', (), {})
|
776 |
+
|
777 |
+
|
778 |
+
def add_metaclass(metaclass):
|
779 |
+
"""Class decorator for creating a class with a metaclass."""
|
780 |
+
def wrapper(cls):
|
781 |
+
orig_vars = cls.__dict__.copy()
|
782 |
+
slots = orig_vars.get('__slots__')
|
783 |
+
if slots is not None:
|
784 |
+
if isinstance(slots, str):
|
785 |
+
slots = [slots]
|
786 |
+
for slots_var in slots:
|
787 |
+
orig_vars.pop(slots_var)
|
788 |
+
orig_vars.pop('__dict__', None)
|
789 |
+
orig_vars.pop('__weakref__', None)
|
790 |
+
return metaclass(cls.__name__, cls.__bases__, orig_vars)
|
791 |
+
return wrapper
|
792 |
+
|
793 |
+
|
794 |
+
def python_2_unicode_compatible(klass):
|
795 |
+
"""
|
796 |
+
A decorator that defines __unicode__ and __str__ methods under Python 2.
|
797 |
+
Under Python 3 it does nothing.
|
798 |
+
|
799 |
+
To support Python 2 and 3 with a single code base, define a __str__ method
|
800 |
+
returning text and apply this decorator to the class.
|
801 |
+
"""
|
802 |
+
if PY2:
|
803 |
+
if '__str__' not in klass.__dict__:
|
804 |
+
raise ValueError("@python_2_unicode_compatible cannot be applied "
|
805 |
+
"to %s because it doesn't define __str__()." %
|
806 |
+
klass.__name__)
|
807 |
+
klass.__unicode__ = klass.__str__
|
808 |
+
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
|
809 |
+
return klass
|
810 |
+
|
811 |
+
|
812 |
+
# Complete the moves implementation.
|
813 |
+
# This code is at the end of this module to speed up module loading.
|
814 |
+
# Turn this module into a package.
|
815 |
+
__path__ = [] # required for PEP 302 and PEP 451
|
816 |
+
__package__ = __name__ # see PEP 366 @ReservedAssignment
|
817 |
+
if globals().get("__spec__") is not None:
|
818 |
+
__spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable
|
819 |
+
# Remove other six meta path importers, since they cause problems. This can
|
820 |
+
# happen if six is removed from sys.modules and then reloaded. (Setuptools does
|
821 |
+
# this for some reason.)
|
822 |
+
if sys.meta_path:
|
823 |
+
for i, importer in enumerate(sys.meta_path):
|
824 |
+
# Here's some real nastiness: Another "instance" of the six module might
|
825 |
+
# be floating around. Therefore, we can't use isinstance() to check for
|
826 |
+
# the six meta path importer, since the other six instance will have
|
827 |
+
# inserted an importer with different class.
|
828 |
+
if (type(importer).__name__ == "_SixMetaPathImporter" and
|
829 |
+
importer.name == __name__):
|
830 |
+
del sys.meta_path[i]
|
831 |
+
break
|
832 |
+
del i, importer
|
833 |
+
# Finally, add the importer to the meta path import hook.
|
834 |
+
sys.meta_path.append(_importer)
|