1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,34 @@ |
0 |
+#!/usr/bin/python2 -tt |
|
1 |
+ |
|
2 |
+import glob |
|
3 |
+import json |
|
4 |
+import os.path |
|
5 |
+from distutils.version import LooseVersion |
|
6 |
+ |
|
7 |
+from ansible.module_utils.urls import open_url |
|
8 |
+ |
|
9 |
+basedir = os.path.dirname(__file__) |
|
10 |
+ |
|
11 |
+for filename in glob.glob(os.path.join(basedir, '../lib/ansible/compat/*/__init__.py')): |
|
12 |
+ if 'compat/tests' in filename: |
|
13 |
+ # compat/tests doesn't bundle any code |
|
14 |
+ continue |
|
15 |
+ |
|
16 |
+ filename = os.path.normpath(filename) |
|
17 |
+ with open(filename, 'r') as module: |
|
18 |
+ for line in module: |
|
19 |
+ if line.strip().startswith('_BUNDLED_METADATA'): |
|
20 |
+ data = line[line.index('{'):].strip() |
|
21 |
+ break |
|
22 |
+ else: |
|
23 |
+ print('WARNING: {0} contained no metadata. Could not check for updates'.format(filename)) |
|
24 |
+ continue |
|
25 |
+ metadata = json.loads(data) |
|
26 |
+ pypi_fh = open_url('https://pypi.python.org/pypi/{0}/json'.format(metadata['pypi_name'])) |
|
27 |
+ pypi_data = json.loads(pypi_fh.read()) |
|
28 |
+ if LooseVersion(metadata['version']) < LooseVersion(pypi_data['info']['version']): |
|
29 |
+ print('UPDATE: {0} from {1} to {2} {3}'.format( |
|
30 |
+ metadata['pypi_name'], |
|
31 |
+ metadata['version'], |
|
32 |
+ pypi_data['info']['version'], |
|
33 |
+ 'https://pypi.python.org/pypi/{0}/'.format(metadata['pypi_name']))) |
... | ... |
@@ -24,9 +24,8 @@ import termios |
24 | 24 |
import traceback |
25 | 25 |
import textwrap |
26 | 26 |
|
27 |
-from six import iteritems |
|
27 |
+from ansible.compat.six import iteritems |
|
28 | 28 |
|
29 |
-from ansible import constants as C |
|
30 | 29 |
from ansible.errors import AnsibleError, AnsibleOptionsError |
31 | 30 |
from ansible.plugins import module_loader |
32 | 31 |
from ansible.cli import CLI |
33 | 32 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,54 @@ |
0 |
+# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> |
|
1 |
+# |
|
2 |
+# This file is part of Ansible |
|
3 |
+# |
|
4 |
+# Ansible is free software: you can redistribute it and/or modify |
|
5 |
+# it under the terms of the GNU General Public License as published by |
|
6 |
+# the Free Software Foundation, either version 3 of the License, or |
|
7 |
+# (at your option) any later version. |
|
8 |
+# |
|
9 |
+# Ansible is distributed in the hope that it will be useful, |
|
10 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
+# GNU General Public License for more details. |
|
13 |
+# |
|
14 |
+# You should have received a copy of the GNU General Public License |
|
15 |
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
+ |
|
17 |
+# Make coding more python3-ish |
|
18 |
+from __future__ import (absolute_import, division, print_function) |
|
19 |
+__metaclass__ = type |
|
20 |
+ |
|
21 |
+''' |
|
22 |
+Compat six library. RHEL7 has python-six 1.3.0 which is too old |
|
23 |
+''' |
|
24 |
+# The following makes it easier for us to script updates of the bundled code |
|
25 |
+_BUNDLED_METADATA = { "pypi_name": "six", "version": "1.10.0" } |
|
26 |
+ |
|
27 |
+import os.path |
|
28 |
+ |
|
29 |
+try: |
|
30 |
+ import six as _system_six |
|
31 |
+except ImportError: |
|
32 |
+ _system_six = None |
|
33 |
+ |
|
34 |
+if _system_six: |
|
35 |
+ # If we need some things from even newer versions of six, then we need to |
|
36 |
+ # use our bundled copy instead |
|
37 |
+ |
|
38 |
+ if ( # Added in six-1.8.0 |
|
39 |
+ not hasattr(_system_six.moves, 'shlex_quote') or |
|
40 |
+ # Added in six-1.4.0 |
|
41 |
+ not hasattr(_system_six, 'byte2int') or |
|
42 |
+ not hasattr(_system_six, 'add_metaclass') or |
|
43 |
+ not hasattr(_system_six.moves, 'urllib') |
|
44 |
+ ): |
|
45 |
+ |
|
46 |
+ _system_six = False |
|
47 |
+ |
|
48 |
+if _system_six: |
|
49 |
+ six = _system_six |
|
50 |
+else: |
|
51 |
+ from . import _six as six |
|
52 |
+six_py_file = '{0}.py'.format(os.path.splitext(six.__file__)[0]) |
|
53 |
+exec(open(six_py_file, 'rb').read()) |
0 | 54 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,868 @@ |
0 |
+"""Utilities for writing code that runs on Python 2 and 3""" |
|
1 |
+ |
|
2 |
+# Copyright (c) 2010-2015 Benjamin Peterson |
|
3 |
+# |
|
4 |
+# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
5 |
+# of this software and associated documentation files (the "Software"), to deal |
|
6 |
+# in the Software without restriction, including without limitation the rights |
|
7 |
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
8 |
+# copies of the Software, and to permit persons to whom the Software is |
|
9 |
+# furnished to do so, subject to the following conditions: |
|
10 |
+# |
|
11 |
+# The above copyright notice and this permission notice shall be included in all |
|
12 |
+# copies or substantial portions of the Software. |
|
13 |
+# |
|
14 |
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
15 |
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
16 |
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
17 |
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
18 |
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
19 |
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
20 |
+# SOFTWARE. |
|
21 |
+ |
|
22 |
+from __future__ import absolute_import |
|
23 |
+ |
|
24 |
+import functools |
|
25 |
+import itertools |
|
26 |
+import operator |
|
27 |
+import sys |
|
28 |
+import types |
|
29 |
+ |
|
30 |
+__author__ = "Benjamin Peterson <benjamin@python.org>" |
|
31 |
+__version__ = "1.10.0" |
|
32 |
+ |
|
33 |
+ |
|
34 |
+# Useful for very coarse version differentiation. |
|
35 |
+PY2 = sys.version_info[0] == 2 |
|
36 |
+PY3 = sys.version_info[0] == 3 |
|
37 |
+PY34 = sys.version_info[0:2] >= (3, 4) |
|
38 |
+ |
|
39 |
+if PY3: |
|
40 |
+ string_types = str, |
|
41 |
+ integer_types = int, |
|
42 |
+ class_types = type, |
|
43 |
+ text_type = str |
|
44 |
+ binary_type = bytes |
|
45 |
+ |
|
46 |
+ MAXSIZE = sys.maxsize |
|
47 |
+else: |
|
48 |
+ string_types = basestring, |
|
49 |
+ integer_types = (int, long) |
|
50 |
+ class_types = (type, types.ClassType) |
|
51 |
+ text_type = unicode |
|
52 |
+ binary_type = str |
|
53 |
+ |
|
54 |
+ if sys.platform.startswith("java"): |
|
55 |
+ # Jython always uses 32 bits. |
|
56 |
+ MAXSIZE = int((1 << 31) - 1) |
|
57 |
+ else: |
|
58 |
+ # It's possible to have sizeof(long) != sizeof(Py_ssize_t). |
|
59 |
+ class X(object): |
|
60 |
+ |
|
61 |
+ def __len__(self): |
|
62 |
+ return 1 << 31 |
|
63 |
+ try: |
|
64 |
+ len(X()) |
|
65 |
+ except OverflowError: |
|
66 |
+ # 32-bit |
|
67 |
+ MAXSIZE = int((1 << 31) - 1) |
|
68 |
+ else: |
|
69 |
+ # 64-bit |
|
70 |
+ MAXSIZE = int((1 << 63) - 1) |
|
71 |
+ del X |
|
72 |
+ |
|
73 |
+ |
|
74 |
+def _add_doc(func, doc): |
|
75 |
+ """Add documentation to a function.""" |
|
76 |
+ func.__doc__ = doc |
|
77 |
+ |
|
78 |
+ |
|
79 |
+def _import_module(name): |
|
80 |
+ """Import module, returning the module after the last dot.""" |
|
81 |
+ __import__(name) |
|
82 |
+ return sys.modules[name] |
|
83 |
+ |
|
84 |
+ |
|
85 |
+class _LazyDescr(object): |
|
86 |
+ |
|
87 |
+ def __init__(self, name): |
|
88 |
+ self.name = name |
|
89 |
+ |
|
90 |
+ def __get__(self, obj, tp): |
|
91 |
+ result = self._resolve() |
|
92 |
+ setattr(obj, self.name, result) # Invokes __set__. |
|
93 |
+ try: |
|
94 |
+ # This is a bit ugly, but it avoids running this again by |
|
95 |
+ # removing this descriptor. |
|
96 |
+ delattr(obj.__class__, self.name) |
|
97 |
+ except AttributeError: |
|
98 |
+ pass |
|
99 |
+ return result |
|
100 |
+ |
|
101 |
+ |
|
102 |
+class MovedModule(_LazyDescr): |
|
103 |
+ |
|
104 |
+ def __init__(self, name, old, new=None): |
|
105 |
+ super(MovedModule, self).__init__(name) |
|
106 |
+ if PY3: |
|
107 |
+ if new is None: |
|
108 |
+ new = name |
|
109 |
+ self.mod = new |
|
110 |
+ else: |
|
111 |
+ self.mod = old |
|
112 |
+ |
|
113 |
+ def _resolve(self): |
|
114 |
+ return _import_module(self.mod) |
|
115 |
+ |
|
116 |
+ def __getattr__(self, attr): |
|
117 |
+ _module = self._resolve() |
|
118 |
+ value = getattr(_module, attr) |
|
119 |
+ setattr(self, attr, value) |
|
120 |
+ return value |
|
121 |
+ |
|
122 |
+ |
|
123 |
+class _LazyModule(types.ModuleType): |
|
124 |
+ |
|
125 |
+ def __init__(self, name): |
|
126 |
+ super(_LazyModule, self).__init__(name) |
|
127 |
+ self.__doc__ = self.__class__.__doc__ |
|
128 |
+ |
|
129 |
+ def __dir__(self): |
|
130 |
+ attrs = ["__doc__", "__name__"] |
|
131 |
+ attrs += [attr.name for attr in self._moved_attributes] |
|
132 |
+ return attrs |
|
133 |
+ |
|
134 |
+ # Subclasses should override this |
|
135 |
+ _moved_attributes = [] |
|
136 |
+ |
|
137 |
+ |
|
138 |
+class MovedAttribute(_LazyDescr): |
|
139 |
+ |
|
140 |
+ def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): |
|
141 |
+ super(MovedAttribute, self).__init__(name) |
|
142 |
+ if PY3: |
|
143 |
+ if new_mod is None: |
|
144 |
+ new_mod = name |
|
145 |
+ self.mod = new_mod |
|
146 |
+ if new_attr is None: |
|
147 |
+ if old_attr is None: |
|
148 |
+ new_attr = name |
|
149 |
+ else: |
|
150 |
+ new_attr = old_attr |
|
151 |
+ self.attr = new_attr |
|
152 |
+ else: |
|
153 |
+ self.mod = old_mod |
|
154 |
+ if old_attr is None: |
|
155 |
+ old_attr = name |
|
156 |
+ self.attr = old_attr |
|
157 |
+ |
|
158 |
+ def _resolve(self): |
|
159 |
+ module = _import_module(self.mod) |
|
160 |
+ return getattr(module, self.attr) |
|
161 |
+ |
|
162 |
+ |
|
163 |
+class _SixMetaPathImporter(object): |
|
164 |
+ |
|
165 |
+ """ |
|
166 |
+ A meta path importer to import six.moves and its submodules. |
|
167 |
+ |
|
168 |
+ This class implements a PEP302 finder and loader. It should be compatible |
|
169 |
+ with Python 2.5 and all existing versions of Python3 |
|
170 |
+ """ |
|
171 |
+ |
|
172 |
+ def __init__(self, six_module_name): |
|
173 |
+ self.name = six_module_name |
|
174 |
+ self.known_modules = {} |
|
175 |
+ |
|
176 |
+ def _add_module(self, mod, *fullnames): |
|
177 |
+ for fullname in fullnames: |
|
178 |
+ self.known_modules[self.name + "." + fullname] = mod |
|
179 |
+ |
|
180 |
+ def _get_module(self, fullname): |
|
181 |
+ return self.known_modules[self.name + "." + fullname] |
|
182 |
+ |
|
183 |
+ def find_module(self, fullname, path=None): |
|
184 |
+ if fullname in self.known_modules: |
|
185 |
+ return self |
|
186 |
+ return None |
|
187 |
+ |
|
188 |
+ def __get_module(self, fullname): |
|
189 |
+ try: |
|
190 |
+ return self.known_modules[fullname] |
|
191 |
+ except KeyError: |
|
192 |
+ raise ImportError("This loader does not know module " + fullname) |
|
193 |
+ |
|
194 |
+ def load_module(self, fullname): |
|
195 |
+ try: |
|
196 |
+ # in case of a reload |
|
197 |
+ return sys.modules[fullname] |
|
198 |
+ except KeyError: |
|
199 |
+ pass |
|
200 |
+ mod = self.__get_module(fullname) |
|
201 |
+ if isinstance(mod, MovedModule): |
|
202 |
+ mod = mod._resolve() |
|
203 |
+ else: |
|
204 |
+ mod.__loader__ = self |
|
205 |
+ sys.modules[fullname] = mod |
|
206 |
+ return mod |
|
207 |
+ |
|
208 |
+ def is_package(self, fullname): |
|
209 |
+ """ |
|
210 |
+ Return true, if the named module is a package. |
|
211 |
+ |
|
212 |
+ We need this method to get correct spec objects with |
|
213 |
+ Python 3.4 (see PEP451) |
|
214 |
+ """ |
|
215 |
+ return hasattr(self.__get_module(fullname), "__path__") |
|
216 |
+ |
|
217 |
+ def get_code(self, fullname): |
|
218 |
+ """Return None |
|
219 |
+ |
|
220 |
+ Required, if is_package is implemented""" |
|
221 |
+ self.__get_module(fullname) # eventually raises ImportError |
|
222 |
+ return None |
|
223 |
+ get_source = get_code # same as get_code |
|
224 |
+ |
|
225 |
+_importer = _SixMetaPathImporter(__name__) |
|
226 |
+ |
|
227 |
+ |
|
228 |
+class _MovedItems(_LazyModule): |
|
229 |
+ |
|
230 |
+ """Lazy loading of moved objects""" |
|
231 |
+ __path__ = [] # mark as package |
|
232 |
+ |
|
233 |
+ |
|
234 |
+_moved_attributes = [ |
|
235 |
+ MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), |
|
236 |
+ MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), |
|
237 |
+ MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"), |
|
238 |
+ MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), |
|
239 |
+ MovedAttribute("intern", "__builtin__", "sys"), |
|
240 |
+ MovedAttribute("map", "itertools", "builtins", "imap", "map"), |
|
241 |
+ MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"), |
|
242 |
+ MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"), |
|
243 |
+ MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"), |
|
244 |
+ MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"), |
|
245 |
+ MovedAttribute("reduce", "__builtin__", "functools"), |
|
246 |
+ MovedAttribute("shlex_quote", "pipes", "shlex", "quote"), |
|
247 |
+ MovedAttribute("StringIO", "StringIO", "io"), |
|
248 |
+ MovedAttribute("UserDict", "UserDict", "collections"), |
|
249 |
+ MovedAttribute("UserList", "UserList", "collections"), |
|
250 |
+ MovedAttribute("UserString", "UserString", "collections"), |
|
251 |
+ MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), |
|
252 |
+ MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), |
|
253 |
+ MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"), |
|
254 |
+ MovedModule("builtins", "__builtin__"), |
|
255 |
+ MovedModule("configparser", "ConfigParser"), |
|
256 |
+ MovedModule("copyreg", "copy_reg"), |
|
257 |
+ MovedModule("dbm_gnu", "gdbm", "dbm.gnu"), |
|
258 |
+ MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"), |
|
259 |
+ MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), |
|
260 |
+ MovedModule("http_cookies", "Cookie", "http.cookies"), |
|
261 |
+ MovedModule("html_entities", "htmlentitydefs", "html.entities"), |
|
262 |
+ MovedModule("html_parser", "HTMLParser", "html.parser"), |
|
263 |
+ MovedModule("http_client", "httplib", "http.client"), |
|
264 |
+ MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"), |
|
265 |
+ MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"), |
|
266 |
+ MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"), |
|
267 |
+ MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"), |
|
268 |
+ MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), |
|
269 |
+ MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"), |
|
270 |
+ MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"), |
|
271 |
+ MovedModule("cPickle", "cPickle", "pickle"), |
|
272 |
+ MovedModule("queue", "Queue"), |
|
273 |
+ MovedModule("reprlib", "repr"), |
|
274 |
+ MovedModule("socketserver", "SocketServer"), |
|
275 |
+ MovedModule("_thread", "thread", "_thread"), |
|
276 |
+ MovedModule("tkinter", "Tkinter"), |
|
277 |
+ MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"), |
|
278 |
+ MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"), |
|
279 |
+ MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"), |
|
280 |
+ MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"), |
|
281 |
+ MovedModule("tkinter_tix", "Tix", "tkinter.tix"), |
|
282 |
+ MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"), |
|
283 |
+ MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), |
|
284 |
+ MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), |
|
285 |
+ MovedModule("tkinter_colorchooser", "tkColorChooser", |
|
286 |
+ "tkinter.colorchooser"), |
|
287 |
+ MovedModule("tkinter_commondialog", "tkCommonDialog", |
|
288 |
+ "tkinter.commondialog"), |
|
289 |
+ MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), |
|
290 |
+ MovedModule("tkinter_font", "tkFont", "tkinter.font"), |
|
291 |
+ MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), |
|
292 |
+ MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", |
|
293 |
+ "tkinter.simpledialog"), |
|
294 |
+ MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"), |
|
295 |
+ MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"), |
|
296 |
+ MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"), |
|
297 |
+ MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), |
|
298 |
+ MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"), |
|
299 |
+ MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"), |
|
300 |
+] |
|
301 |
+# Add windows specific modules. |
|
302 |
+if sys.platform == "win32": |
|
303 |
+ _moved_attributes += [ |
|
304 |
+ MovedModule("winreg", "_winreg"), |
|
305 |
+ ] |
|
306 |
+ |
|
307 |
+for attr in _moved_attributes: |
|
308 |
+ setattr(_MovedItems, attr.name, attr) |
|
309 |
+ if isinstance(attr, MovedModule): |
|
310 |
+ _importer._add_module(attr, "moves." + attr.name) |
|
311 |
+del attr |
|
312 |
+ |
|
313 |
+_MovedItems._moved_attributes = _moved_attributes |
|
314 |
+ |
|
315 |
+moves = _MovedItems(__name__ + ".moves") |
|
316 |
+_importer._add_module(moves, "moves") |
|
317 |
+ |
|
318 |
+ |
|
319 |
+class Module_six_moves_urllib_parse(_LazyModule): |
|
320 |
+ |
|
321 |
+ """Lazy loading of moved objects in six.moves.urllib_parse""" |
|
322 |
+ |
|
323 |
+ |
|
324 |
+_urllib_parse_moved_attributes = [ |
|
325 |
+ MovedAttribute("ParseResult", "urlparse", "urllib.parse"), |
|
326 |
+ MovedAttribute("SplitResult", "urlparse", "urllib.parse"), |
|
327 |
+ MovedAttribute("parse_qs", "urlparse", "urllib.parse"), |
|
328 |
+ MovedAttribute("parse_qsl", "urlparse", "urllib.parse"), |
|
329 |
+ MovedAttribute("urldefrag", "urlparse", "urllib.parse"), |
|
330 |
+ MovedAttribute("urljoin", "urlparse", "urllib.parse"), |
|
331 |
+ MovedAttribute("urlparse", "urlparse", "urllib.parse"), |
|
332 |
+ MovedAttribute("urlsplit", "urlparse", "urllib.parse"), |
|
333 |
+ MovedAttribute("urlunparse", "urlparse", "urllib.parse"), |
|
334 |
+ MovedAttribute("urlunsplit", "urlparse", "urllib.parse"), |
|
335 |
+ MovedAttribute("quote", "urllib", "urllib.parse"), |
|
336 |
+ MovedAttribute("quote_plus", "urllib", "urllib.parse"), |
|
337 |
+ MovedAttribute("unquote", "urllib", "urllib.parse"), |
|
338 |
+ MovedAttribute("unquote_plus", "urllib", "urllib.parse"), |
|
339 |
+ MovedAttribute("urlencode", "urllib", "urllib.parse"), |
|
340 |
+ MovedAttribute("splitquery", "urllib", "urllib.parse"), |
|
341 |
+ MovedAttribute("splittag", "urllib", "urllib.parse"), |
|
342 |
+ MovedAttribute("splituser", "urllib", "urllib.parse"), |
|
343 |
+ MovedAttribute("uses_fragment", "urlparse", "urllib.parse"), |
|
344 |
+ MovedAttribute("uses_netloc", "urlparse", "urllib.parse"), |
|
345 |
+ MovedAttribute("uses_params", "urlparse", "urllib.parse"), |
|
346 |
+ MovedAttribute("uses_query", "urlparse", "urllib.parse"), |
|
347 |
+ MovedAttribute("uses_relative", "urlparse", "urllib.parse"), |
|
348 |
+] |
|
349 |
+for attr in _urllib_parse_moved_attributes: |
|
350 |
+ setattr(Module_six_moves_urllib_parse, attr.name, attr) |
|
351 |
+del attr |
|
352 |
+ |
|
353 |
+Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes |
|
354 |
+ |
|
355 |
+_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"), |
|
356 |
+ "moves.urllib_parse", "moves.urllib.parse") |
|
357 |
+ |
|
358 |
+ |
|
359 |
+class Module_six_moves_urllib_error(_LazyModule): |
|
360 |
+ |
|
361 |
+ """Lazy loading of moved objects in six.moves.urllib_error""" |
|
362 |
+ |
|
363 |
+ |
|
364 |
+_urllib_error_moved_attributes = [ |
|
365 |
+ MovedAttribute("URLError", "urllib2", "urllib.error"), |
|
366 |
+ MovedAttribute("HTTPError", "urllib2", "urllib.error"), |
|
367 |
+ MovedAttribute("ContentTooShortError", "urllib", "urllib.error"), |
|
368 |
+] |
|
369 |
+for attr in _urllib_error_moved_attributes: |
|
370 |
+ setattr(Module_six_moves_urllib_error, attr.name, attr) |
|
371 |
+del attr |
|
372 |
+ |
|
373 |
+Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes |
|
374 |
+ |
|
375 |
+_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"), |
|
376 |
+ "moves.urllib_error", "moves.urllib.error") |
|
377 |
+ |
|
378 |
+ |
|
379 |
+class Module_six_moves_urllib_request(_LazyModule): |
|
380 |
+ |
|
381 |
+ """Lazy loading of moved objects in six.moves.urllib_request""" |
|
382 |
+ |
|
383 |
+ |
|
384 |
+_urllib_request_moved_attributes = [ |
|
385 |
+ MovedAttribute("urlopen", "urllib2", "urllib.request"), |
|
386 |
+ MovedAttribute("install_opener", "urllib2", "urllib.request"), |
|
387 |
+ MovedAttribute("build_opener", "urllib2", "urllib.request"), |
|
388 |
+ MovedAttribute("pathname2url", "urllib", "urllib.request"), |
|
389 |
+ MovedAttribute("url2pathname", "urllib", "urllib.request"), |
|
390 |
+ MovedAttribute("getproxies", "urllib", "urllib.request"), |
|
391 |
+ MovedAttribute("Request", "urllib2", "urllib.request"), |
|
392 |
+ MovedAttribute("OpenerDirector", "urllib2", "urllib.request"), |
|
393 |
+ MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"), |
|
394 |
+ MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"), |
|
395 |
+ MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"), |
|
396 |
+ MovedAttribute("ProxyHandler", "urllib2", "urllib.request"), |
|
397 |
+ MovedAttribute("BaseHandler", "urllib2", "urllib.request"), |
|
398 |
+ MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"), |
|
399 |
+ MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"), |
|
400 |
+ MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"), |
|
401 |
+ MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"), |
|
402 |
+ MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"), |
|
403 |
+ MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"), |
|
404 |
+ MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"), |
|
405 |
+ MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"), |
|
406 |
+ MovedAttribute("HTTPHandler", "urllib2", "urllib.request"), |
|
407 |
+ MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"), |
|
408 |
+ MovedAttribute("FileHandler", "urllib2", "urllib.request"), |
|
409 |
+ MovedAttribute("FTPHandler", "urllib2", "urllib.request"), |
|
410 |
+ MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"), |
|
411 |
+ MovedAttribute("UnknownHandler", "urllib2", "urllib.request"), |
|
412 |
+ MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"), |
|
413 |
+ MovedAttribute("urlretrieve", "urllib", "urllib.request"), |
|
414 |
+ MovedAttribute("urlcleanup", "urllib", "urllib.request"), |
|
415 |
+ MovedAttribute("URLopener", "urllib", "urllib.request"), |
|
416 |
+ MovedAttribute("FancyURLopener", "urllib", "urllib.request"), |
|
417 |
+ MovedAttribute("proxy_bypass", "urllib", "urllib.request"), |
|
418 |
+] |
|
419 |
+for attr in _urllib_request_moved_attributes: |
|
420 |
+ setattr(Module_six_moves_urllib_request, attr.name, attr) |
|
421 |
+del attr |
|
422 |
+ |
|
423 |
+Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes |
|
424 |
+ |
|
425 |
+_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"), |
|
426 |
+ "moves.urllib_request", "moves.urllib.request") |
|
427 |
+ |
|
428 |
+ |
|
429 |
+class Module_six_moves_urllib_response(_LazyModule): |
|
430 |
+ |
|
431 |
+ """Lazy loading of moved objects in six.moves.urllib_response""" |
|
432 |
+ |
|
433 |
+ |
|
434 |
+_urllib_response_moved_attributes = [ |
|
435 |
+ MovedAttribute("addbase", "urllib", "urllib.response"), |
|
436 |
+ MovedAttribute("addclosehook", "urllib", "urllib.response"), |
|
437 |
+ MovedAttribute("addinfo", "urllib", "urllib.response"), |
|
438 |
+ MovedAttribute("addinfourl", "urllib", "urllib.response"), |
|
439 |
+] |
|
440 |
+for attr in _urllib_response_moved_attributes: |
|
441 |
+ setattr(Module_six_moves_urllib_response, attr.name, attr) |
|
442 |
+del attr |
|
443 |
+ |
|
444 |
+Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes |
|
445 |
+ |
|
446 |
+_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"), |
|
447 |
+ "moves.urllib_response", "moves.urllib.response") |
|
448 |
+ |
|
449 |
+ |
|
450 |
+class Module_six_moves_urllib_robotparser(_LazyModule): |
|
451 |
+ |
|
452 |
+ """Lazy loading of moved objects in six.moves.urllib_robotparser""" |
|
453 |
+ |
|
454 |
+ |
|
455 |
+_urllib_robotparser_moved_attributes = [ |
|
456 |
+ MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"), |
|
457 |
+] |
|
458 |
+for attr in _urllib_robotparser_moved_attributes: |
|
459 |
+ setattr(Module_six_moves_urllib_robotparser, attr.name, attr) |
|
460 |
+del attr |
|
461 |
+ |
|
462 |
+Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes |
|
463 |
+ |
|
464 |
+_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"), |
|
465 |
+ "moves.urllib_robotparser", "moves.urllib.robotparser") |
|
466 |
+ |
|
467 |
+ |
|
468 |
+class Module_six_moves_urllib(types.ModuleType): |
|
469 |
+ |
|
470 |
+ """Create a six.moves.urllib namespace that resembles the Python 3 namespace""" |
|
471 |
+ __path__ = [] # mark as package |
|
472 |
+ parse = _importer._get_module("moves.urllib_parse") |
|
473 |
+ error = _importer._get_module("moves.urllib_error") |
|
474 |
+ request = _importer._get_module("moves.urllib_request") |
|
475 |
+ response = _importer._get_module("moves.urllib_response") |
|
476 |
+ robotparser = _importer._get_module("moves.urllib_robotparser") |
|
477 |
+ |
|
478 |
+ def __dir__(self): |
|
479 |
+ return ['parse', 'error', 'request', 'response', 'robotparser'] |
|
480 |
+ |
|
481 |
+_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"), |
|
482 |
+ "moves.urllib") |
|
483 |
+ |
|
484 |
+ |
|
485 |
+def add_move(move): |
|
486 |
+ """Add an item to six.moves.""" |
|
487 |
+ setattr(_MovedItems, move.name, move) |
|
488 |
+ |
|
489 |
+ |
|
490 |
+def remove_move(name): |
|
491 |
+ """Remove item from six.moves.""" |
|
492 |
+ try: |
|
493 |
+ delattr(_MovedItems, name) |
|
494 |
+ except AttributeError: |
|
495 |
+ try: |
|
496 |
+ del moves.__dict__[name] |
|
497 |
+ except KeyError: |
|
498 |
+ raise AttributeError("no such move, %r" % (name,)) |
|
499 |
+ |
|
500 |
+ |
|
501 |
+if PY3: |
|
502 |
+ _meth_func = "__func__" |
|
503 |
+ _meth_self = "__self__" |
|
504 |
+ |
|
505 |
+ _func_closure = "__closure__" |
|
506 |
+ _func_code = "__code__" |
|
507 |
+ _func_defaults = "__defaults__" |
|
508 |
+ _func_globals = "__globals__" |
|
509 |
+else: |
|
510 |
+ _meth_func = "im_func" |
|
511 |
+ _meth_self = "im_self" |
|
512 |
+ |
|
513 |
+ _func_closure = "func_closure" |
|
514 |
+ _func_code = "func_code" |
|
515 |
+ _func_defaults = "func_defaults" |
|
516 |
+ _func_globals = "func_globals" |
|
517 |
+ |
|
518 |
+ |
|
519 |
+try: |
|
520 |
+ advance_iterator = next |
|
521 |
+except NameError: |
|
522 |
+ def advance_iterator(it): |
|
523 |
+ return it.next() |
|
524 |
+next = advance_iterator |
|
525 |
+ |
|
526 |
+ |
|
527 |
+try: |
|
528 |
+ callable = callable |
|
529 |
+except NameError: |
|
530 |
+ def callable(obj): |
|
531 |
+ return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) |
|
532 |
+ |
|
533 |
+ |
|
534 |
+if PY3: |
|
535 |
+ def get_unbound_function(unbound): |
|
536 |
+ return unbound |
|
537 |
+ |
|
538 |
+ create_bound_method = types.MethodType |
|
539 |
+ |
|
540 |
+ def create_unbound_method(func, cls): |
|
541 |
+ return func |
|
542 |
+ |
|
543 |
+ Iterator = object |
|
544 |
+else: |
|
545 |
+ def get_unbound_function(unbound): |
|
546 |
+ return unbound.im_func |
|
547 |
+ |
|
548 |
+ def create_bound_method(func, obj): |
|
549 |
+ return types.MethodType(func, obj, obj.__class__) |
|
550 |
+ |
|
551 |
+ def create_unbound_method(func, cls): |
|
552 |
+ return types.MethodType(func, None, cls) |
|
553 |
+ |
|
554 |
+ class Iterator(object): |
|
555 |
+ |
|
556 |
+ def next(self): |
|
557 |
+ return type(self).__next__(self) |
|
558 |
+ |
|
559 |
+ callable = callable |
|
560 |
+_add_doc(get_unbound_function, |
|
561 |
+ """Get the function out of a possibly unbound function""") |
|
562 |
+ |
|
563 |
+ |
|
564 |
+get_method_function = operator.attrgetter(_meth_func) |
|
565 |
+get_method_self = operator.attrgetter(_meth_self) |
|
566 |
+get_function_closure = operator.attrgetter(_func_closure) |
|
567 |
+get_function_code = operator.attrgetter(_func_code) |
|
568 |
+get_function_defaults = operator.attrgetter(_func_defaults) |
|
569 |
+get_function_globals = operator.attrgetter(_func_globals) |
|
570 |
+ |
|
571 |
+ |
|
572 |
+if PY3: |
|
573 |
+ def iterkeys(d, **kw): |
|
574 |
+ return iter(d.keys(**kw)) |
|
575 |
+ |
|
576 |
+ def itervalues(d, **kw): |
|
577 |
+ return iter(d.values(**kw)) |
|
578 |
+ |
|
579 |
+ def iteritems(d, **kw): |
|
580 |
+ return iter(d.items(**kw)) |
|
581 |
+ |
|
582 |
+ def iterlists(d, **kw): |
|
583 |
+ return iter(d.lists(**kw)) |
|
584 |
+ |
|
585 |
+ viewkeys = operator.methodcaller("keys") |
|
586 |
+ |
|
587 |
+ viewvalues = operator.methodcaller("values") |
|
588 |
+ |
|
589 |
+ viewitems = operator.methodcaller("items") |
|
590 |
+else: |
|
591 |
+ def iterkeys(d, **kw): |
|
592 |
+ return d.iterkeys(**kw) |
|
593 |
+ |
|
594 |
+ def itervalues(d, **kw): |
|
595 |
+ return d.itervalues(**kw) |
|
596 |
+ |
|
597 |
+ def iteritems(d, **kw): |
|
598 |
+ return d.iteritems(**kw) |
|
599 |
+ |
|
600 |
+ def iterlists(d, **kw): |
|
601 |
+ return d.iterlists(**kw) |
|
602 |
+ |
|
603 |
+ viewkeys = operator.methodcaller("viewkeys") |
|
604 |
+ |
|
605 |
+ viewvalues = operator.methodcaller("viewvalues") |
|
606 |
+ |
|
607 |
+ viewitems = operator.methodcaller("viewitems") |
|
608 |
+ |
|
609 |
+_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.") |
|
610 |
+_add_doc(itervalues, "Return an iterator over the values of a dictionary.") |
|
611 |
+_add_doc(iteritems, |
|
612 |
+ "Return an iterator over the (key, value) pairs of a dictionary.") |
|
613 |
+_add_doc(iterlists, |
|
614 |
+ "Return an iterator over the (key, [values]) pairs of a dictionary.") |
|
615 |
+ |
|
616 |
+ |
|
617 |
+if PY3: |
|
618 |
+ def b(s): |
|
619 |
+ return s.encode("latin-1") |
|
620 |
+ |
|
621 |
+ def u(s): |
|
622 |
+ return s |
|
623 |
+ unichr = chr |
|
624 |
+ import struct |
|
625 |
+ int2byte = struct.Struct(">B").pack |
|
626 |
+ del struct |
|
627 |
+ byte2int = operator.itemgetter(0) |
|
628 |
+ indexbytes = operator.getitem |
|
629 |
+ iterbytes = iter |
|
630 |
+ import io |
|
631 |
+ StringIO = io.StringIO |
|
632 |
+ BytesIO = io.BytesIO |
|
633 |
+ _assertCountEqual = "assertCountEqual" |
|
634 |
+ if sys.version_info[1] <= 1: |
|
635 |
+ _assertRaisesRegex = "assertRaisesRegexp" |
|
636 |
+ _assertRegex = "assertRegexpMatches" |
|
637 |
+ else: |
|
638 |
+ _assertRaisesRegex = "assertRaisesRegex" |
|
639 |
+ _assertRegex = "assertRegex" |
|
640 |
+else: |
|
641 |
+ def b(s): |
|
642 |
+ return s |
|
643 |
+ # Workaround for standalone backslash |
|
644 |
+ |
|
645 |
+ def u(s): |
|
646 |
+ return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") |
|
647 |
+ unichr = unichr |
|
648 |
+ int2byte = chr |
|
649 |
+ |
|
650 |
+ def byte2int(bs): |
|
651 |
+ return ord(bs[0]) |
|
652 |
+ |
|
653 |
+ def indexbytes(buf, i): |
|
654 |
+ return ord(buf[i]) |
|
655 |
+ iterbytes = functools.partial(itertools.imap, ord) |
|
656 |
+ import StringIO |
|
657 |
+ StringIO = BytesIO = StringIO.StringIO |
|
658 |
+ _assertCountEqual = "assertItemsEqual" |
|
659 |
+ _assertRaisesRegex = "assertRaisesRegexp" |
|
660 |
+ _assertRegex = "assertRegexpMatches" |
|
661 |
+_add_doc(b, """Byte literal""") |
|
662 |
+_add_doc(u, """Text literal""") |
|
663 |
+ |
|
664 |
+ |
|
665 |
+def assertCountEqual(self, *args, **kwargs): |
|
666 |
+ return getattr(self, _assertCountEqual)(*args, **kwargs) |
|
667 |
+ |
|
668 |
+ |
|
669 |
+def assertRaisesRegex(self, *args, **kwargs): |
|
670 |
+ return getattr(self, _assertRaisesRegex)(*args, **kwargs) |
|
671 |
+ |
|
672 |
+ |
|
673 |
+def assertRegex(self, *args, **kwargs): |
|
674 |
+ return getattr(self, _assertRegex)(*args, **kwargs) |
|
675 |
+ |
|
676 |
+ |
|
677 |
+if PY3: |
|
678 |
+ exec_ = getattr(moves.builtins, "exec") |
|
679 |
+ |
|
680 |
+ def reraise(tp, value, tb=None): |
|
681 |
+ if value is None: |
|
682 |
+ value = tp() |
|
683 |
+ if value.__traceback__ is not tb: |
|
684 |
+ raise value.with_traceback(tb) |
|
685 |
+ raise value |
|
686 |
+ |
|
687 |
+else: |
|
688 |
+ def exec_(_code_, _globs_=None, _locs_=None): |
|
689 |
+ """Execute code in a namespace.""" |
|
690 |
+ if _globs_ is None: |
|
691 |
+ frame = sys._getframe(1) |
|
692 |
+ _globs_ = frame.f_globals |
|
693 |
+ if _locs_ is None: |
|
694 |
+ _locs_ = frame.f_locals |
|
695 |
+ del frame |
|
696 |
+ elif _locs_ is None: |
|
697 |
+ _locs_ = _globs_ |
|
698 |
+ exec("""exec _code_ in _globs_, _locs_""") |
|
699 |
+ |
|
700 |
+ exec_("""def reraise(tp, value, tb=None): |
|
701 |
+ raise tp, value, tb |
|
702 |
+""") |
|
703 |
+ |
|
704 |
+ |
|
705 |
+if sys.version_info[:2] == (3, 2): |
|
706 |
+ exec_("""def raise_from(value, from_value): |
|
707 |
+ if from_value is None: |
|
708 |
+ raise value |
|
709 |
+ raise value from from_value |
|
710 |
+""") |
|
711 |
+elif sys.version_info[:2] > (3, 2): |
|
712 |
+ exec_("""def raise_from(value, from_value): |
|
713 |
+ raise value from from_value |
|
714 |
+""") |
|
715 |
+else: |
|
716 |
+ def raise_from(value, from_value): |
|
717 |
+ raise value |
|
718 |
+ |
|
719 |
+ |
|
720 |
+print_ = getattr(moves.builtins, "print", None) |
|
721 |
+if print_ is None: |
|
722 |
+ def print_(*args, **kwargs): |
|
723 |
+ """The new-style print function for Python 2.4 and 2.5.""" |
|
724 |
+ fp = kwargs.pop("file", sys.stdout) |
|
725 |
+ if fp is None: |
|
726 |
+ return |
|
727 |
+ |
|
728 |
+ def write(data): |
|
729 |
+ if not isinstance(data, basestring): |
|
730 |
+ data = str(data) |
|
731 |
+ # If the file has an encoding, encode unicode with it. |
|
732 |
+ if (isinstance(fp, file) and |
|
733 |
+ isinstance(data, unicode) and |
|
734 |
+ fp.encoding is not None): |
|
735 |
+ errors = getattr(fp, "errors", None) |
|
736 |
+ if errors is None: |
|
737 |
+ errors = "strict" |
|
738 |
+ data = data.encode(fp.encoding, errors) |
|
739 |
+ fp.write(data) |
|
740 |
+ want_unicode = False |
|
741 |
+ sep = kwargs.pop("sep", None) |
|
742 |
+ if sep is not None: |
|
743 |
+ if isinstance(sep, unicode): |
|
744 |
+ want_unicode = True |
|
745 |
+ elif not isinstance(sep, str): |
|
746 |
+ raise TypeError("sep must be None or a string") |
|
747 |
+ end = kwargs.pop("end", None) |
|
748 |
+ if end is not None: |
|
749 |
+ if isinstance(end, unicode): |
|
750 |
+ want_unicode = True |
|
751 |
+ elif not isinstance(end, str): |
|
752 |
+ raise TypeError("end must be None or a string") |
|
753 |
+ if kwargs: |
|
754 |
+ raise TypeError("invalid keyword arguments to print()") |
|
755 |
+ if not want_unicode: |
|
756 |
+ for arg in args: |
|
757 |
+ if isinstance(arg, unicode): |
|
758 |
+ want_unicode = True |
|
759 |
+ break |
|
760 |
+ if want_unicode: |
|
761 |
+ newline = unicode("\n") |
|
762 |
+ space = unicode(" ") |
|
763 |
+ else: |
|
764 |
+ newline = "\n" |
|
765 |
+ space = " " |
|
766 |
+ if sep is None: |
|
767 |
+ sep = space |
|
768 |
+ if end is None: |
|
769 |
+ end = newline |
|
770 |
+ for i, arg in enumerate(args): |
|
771 |
+ if i: |
|
772 |
+ write(sep) |
|
773 |
+ write(arg) |
|
774 |
+ write(end) |
|
775 |
+if sys.version_info[:2] < (3, 3): |
|
776 |
+ _print = print_ |
|
777 |
+ |
|
778 |
+ def print_(*args, **kwargs): |
|
779 |
+ fp = kwargs.get("file", sys.stdout) |
|
780 |
+ flush = kwargs.pop("flush", False) |
|
781 |
+ _print(*args, **kwargs) |
|
782 |
+ if flush and fp is not None: |
|
783 |
+ fp.flush() |
|
784 |
+ |
|
785 |
+_add_doc(reraise, """Reraise an exception.""") |
|
786 |
+ |
|
787 |
+if sys.version_info[0:2] < (3, 4): |
|
788 |
+ def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, |
|
789 |
+ updated=functools.WRAPPER_UPDATES): |
|
790 |
+ def wrapper(f): |
|
791 |
+ f = functools.wraps(wrapped, assigned, updated)(f) |
|
792 |
+ f.__wrapped__ = wrapped |
|
793 |
+ return f |
|
794 |
+ return wrapper |
|
795 |
+else: |
|
796 |
+ wraps = functools.wraps |
|
797 |
+ |
|
798 |
+ |
|
799 |
+def with_metaclass(meta, *bases): |
|
800 |
+ """Create a base class with a metaclass.""" |
|
801 |
+ # This requires a bit of explanation: the basic idea is to make a dummy |
|
802 |
+ # metaclass for one level of class instantiation that replaces itself with |
|
803 |
+ # the actual metaclass. |
|
804 |
+ class metaclass(meta): |
|
805 |
+ |
|
806 |
+ def __new__(cls, name, this_bases, d): |
|
807 |
+ return meta(name, bases, d) |
|
808 |
+ return type.__new__(metaclass, 'temporary_class', (), {}) |
|
809 |
+ |
|
810 |
+ |
|
811 |
+def add_metaclass(metaclass): |
|
812 |
+ """Class decorator for creating a class with a metaclass.""" |
|
813 |
+ def wrapper(cls): |
|
814 |
+ orig_vars = cls.__dict__.copy() |
|
815 |
+ slots = orig_vars.get('__slots__') |
|
816 |
+ if slots is not None: |
|
817 |
+ if isinstance(slots, str): |
|
818 |
+ slots = [slots] |
|
819 |
+ for slots_var in slots: |
|
820 |
+ orig_vars.pop(slots_var) |
|
821 |
+ orig_vars.pop('__dict__', None) |
|
822 |
+ orig_vars.pop('__weakref__', None) |
|
823 |
+ return metaclass(cls.__name__, cls.__bases__, orig_vars) |
|
824 |
+ return wrapper |
|
825 |
+ |
|
826 |
+ |
|
827 |
+def python_2_unicode_compatible(klass): |
|
828 |
+ """ |
|
829 |
+ A decorator that defines __unicode__ and __str__ methods under Python 2. |
|
830 |
+ Under Python 3 it does nothing. |
|
831 |
+ |
|
832 |
+ To support Python 2 and 3 with a single code base, define a __str__ method |
|
833 |
+ returning text and apply this decorator to the class. |
|
834 |
+ """ |
|
835 |
+ if PY2: |
|
836 |
+ if '__str__' not in klass.__dict__: |
|
837 |
+ raise ValueError("@python_2_unicode_compatible cannot be applied " |
|
838 |
+ "to %s because it doesn't define __str__()." % |
|
839 |
+ klass.__name__) |
|
840 |
+ klass.__unicode__ = klass.__str__ |
|
841 |
+ klass.__str__ = lambda self: self.__unicode__().encode('utf-8') |
|
842 |
+ return klass |
|
843 |
+ |
|
844 |
+ |
|
845 |
+# Complete the moves implementation. |
|
846 |
+# This code is at the end of this module to speed up module loading. |
|
847 |
+# Turn this module into a package. |
|
848 |
+__path__ = [] # required for PEP 302 and PEP 451 |
|
849 |
+__package__ = __name__ # see PEP 366 @ReservedAssignment |
|
850 |
+if globals().get("__spec__") is not None: |
|
851 |
+ __spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable |
|
852 |
+# Remove other six meta path importers, since they cause problems. This can |
|
853 |
+# happen if six is removed from sys.modules and then reloaded. (Setuptools does |
|
854 |
+# this for some reason.) |
|
855 |
+if sys.meta_path: |
|
856 |
+ for i, importer in enumerate(sys.meta_path): |
|
857 |
+ # Here's some real nastiness: Another "instance" of the six module might |
|
858 |
+ # be floating around. Therefore, we can't use isinstance() to check for |
|
859 |
+ # the six meta path importer, since the other six instance will have |
|
860 |
+ # inserted an importer with different class. |
|
861 |
+ if (type(importer).__name__ == "_SixMetaPathImporter" and |
|
862 |
+ importer.name == __name__): |
|
863 |
+ del sys.meta_path[i] |
|
864 |
+ break |
|
865 |
+ del i, importer |
|
866 |
+# Finally, add the importer to the meta path import hook. |
|
867 |
+sys.meta_path.append(_importer) |
... | ... |
@@ -21,11 +21,10 @@ __metaclass__ = type |
21 | 21 |
|
22 | 22 |
import os |
23 | 23 |
import pwd |
24 |
-import sys |
|
25 | 24 |
from string import ascii_letters, digits |
26 | 25 |
|
27 |
-from six import string_types |
|
28 |
-from six.moves import configparser |
|
26 |
+from ansible.compat.six import string_types |
|
27 |
+from ansible.compat.six.moves import configparser |
|
29 | 28 |
|
30 | 29 |
from ansible.parsing.splitter import unquote |
31 | 30 |
from ansible.errors import AnsibleOptionsError |
... | ... |
@@ -21,7 +21,7 @@ from __future__ import (absolute_import, division, print_function) |
21 | 21 |
__metaclass__ = type |
22 | 22 |
|
23 | 23 |
# from python and deps |
24 |
-from six.moves import StringIO |
|
24 |
+from ansible.compat.six.moves import StringIO |
|
25 | 25 |
import json |
26 | 26 |
import os |
27 | 27 |
import shlex |
... | ... |
@@ -30,7 +30,6 @@ import shlex |
30 | 30 |
from ansible import __version__ |
31 | 31 |
from ansible import constants as C |
32 | 32 |
from ansible.errors import AnsibleError |
33 |
-from ansible.parsing.utils.jsonify import jsonify |
|
34 | 33 |
from ansible.utils.unicode import to_bytes |
35 | 34 |
|
36 | 35 |
REPLACER = "#<<INCLUDE_ANSIBLE_MODULE_COMMON>>" |
... | ... |
@@ -21,11 +21,11 @@ __metaclass__ = type |
21 | 21 |
|
22 | 22 |
import fnmatch |
23 | 23 |
|
24 |
-from six import iteritems |
|
24 |
+from ansible.compat.six import iteritems |
|
25 | 25 |
|
26 | 26 |
from ansible import constants as C |
27 | 27 |
|
28 |
-from ansible.errors import * |
|
28 |
+from ansible.errors import AnsibleError |
|
29 | 29 |
from ansible.playbook.block import Block |
30 | 30 |
from ansible.playbook.task import Task |
31 | 31 |
|
... | ... |
@@ -25,7 +25,7 @@ import os |
25 | 25 |
import signal |
26 | 26 |
import sys |
27 | 27 |
|
28 |
-from six import string_types |
|
28 |
+from ansible.compat.six import string_types |
|
29 | 29 |
|
30 | 30 |
from ansible import constants as C |
31 | 31 |
from ansible.executor.task_queue_manager import TaskQueueManager |
... | ... |
@@ -33,7 +33,6 @@ from ansible.playbook import Playbook |
33 | 33 |
from ansible.template import Templar |
34 | 34 |
|
35 | 35 |
from ansible.utils.color import colorize, hostcolor |
36 |
-from ansible.utils.debug import debug |
|
37 | 36 |
from ansible.utils.encrypt import do_encrypt |
38 | 37 |
from ansible.utils.unicode import to_unicode |
39 | 38 |
|
... | ... |
@@ -19,13 +19,10 @@ |
19 | 19 |
from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 |
-from six.moves import queue |
|
23 |
-from six import iteritems, text_type |
|
22 |
+from ansible.compat.six.moves import queue |
|
23 |
+from ansible.compat.six import iteritems, text_type |
|
24 | 24 |
|
25 | 25 |
import multiprocessing |
26 |
-import os |
|
27 |
-import signal |
|
28 |
-import sys |
|
29 | 26 |
import time |
30 | 27 |
import traceback |
31 | 28 |
|
... | ... |
@@ -37,9 +34,6 @@ try: |
37 | 37 |
except ImportError: |
38 | 38 |
HAS_ATFORK=False |
39 | 39 |
|
40 |
-from ansible.playbook.handler import Handler |
|
41 |
-from ansible.playbook.task import Task |
|
42 |
- |
|
43 | 40 |
from ansible.utils.debug import debug |
44 | 41 |
|
45 | 42 |
__all__ = ['ResultProcess'] |
... | ... |
@@ -25,7 +25,7 @@ import subprocess |
25 | 25 |
import sys |
26 | 26 |
import time |
27 | 27 |
|
28 |
-from six import iteritems |
|
28 |
+from ansible.compat.six import iteritems |
|
29 | 29 |
|
30 | 30 |
from ansible import constants as C |
31 | 31 |
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable, AnsibleConnectionFailure |
... | ... |
@@ -26,7 +26,7 @@ import stat |
26 | 26 |
import subprocess |
27 | 27 |
|
28 | 28 |
from yaml import load, YAMLError |
29 |
-from six import text_type, string_types |
|
29 |
+from ansible.compat.six import text_type, string_types |
|
30 | 30 |
|
31 | 31 |
from ansible.errors import AnsibleFileNotFound, AnsibleParserError, AnsibleError |
32 | 32 |
from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR |
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 |
-from six import iteritems, string_types |
|
22 |
+from ansible.compat.six import iteritems, string_types |
|
23 | 23 |
|
24 | 24 |
from ansible.errors import AnsibleParserError |
25 | 25 |
from ansible.plugins import module_loader |
... | ... |
@@ -28,27 +28,11 @@ from ansible.errors import AnsibleError |
28 | 28 |
from hashlib import sha256 |
29 | 29 |
from binascii import hexlify |
30 | 30 |
from binascii import unhexlify |
31 |
-from six import PY3 |
|
32 | 31 |
|
33 | 32 |
# Note: Only used for loading obsolete VaultAES files. All files are written |
34 | 33 |
# using the newer VaultAES256 which does not require md5 |
35 | 34 |
from hashlib import md5 |
36 | 35 |
|
37 |
- |
|
38 |
-try: |
|
39 |
- from six import byte2int |
|
40 |
-except ImportError: |
|
41 |
- # bytes2int added in six-1.4.0 |
|
42 |
- if PY3: |
|
43 |
- import operator |
|
44 |
- byte2int = operator.itemgetter(0) |
|
45 |
- else: |
|
46 |
- def byte2int(bs): |
|
47 |
- return ord(bs[0]) |
|
48 |
- |
|
49 |
-from ansible.utils.unicode import to_unicode, to_bytes |
|
50 |
- |
|
51 |
- |
|
52 | 36 |
try: |
53 | 37 |
from Crypto.Hash import SHA256, HMAC |
54 | 38 |
HAS_HASH = True |
... | ... |
@@ -86,6 +70,9 @@ try: |
86 | 86 |
except ImportError: |
87 | 87 |
pass |
88 | 88 |
|
89 |
+from ansible.compat.six import PY3, byte2int |
|
90 |
+from ansible.utils.unicode import to_unicode, to_bytes |
|
91 |
+ |
|
89 | 92 |
HAS_ANY_PBKDF2HMAC = HAS_PBKDF2 or HAS_PBKDF2HMAC |
90 | 93 |
|
91 | 94 |
CRYPTO_UPGRADE = "ansible-vault requires a newer version of pycrypto than the one installed on your platform. You may fix this with OS-specific commands such as: yum install python-devel; rpm -e --nodeps python-crypto; pip install pycrypto" |
... | ... |
@@ -27,7 +27,7 @@ from functools import partial |
27 | 27 |
from inspect import getmembers |
28 | 28 |
from io import FileIO |
29 | 29 |
|
30 |
-from six import iteritems, string_types, text_type |
|
30 |
+from ansible.compat.six import iteritems, string_types, text_type |
|
31 | 31 |
|
32 | 32 |
from jinja2.exceptions import UndefinedError |
33 | 33 |
|
... | ... |
@@ -20,9 +20,9 @@ from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 | 22 |
from jinja2.exceptions import UndefinedError |
23 |
-from six import text_type |
|
24 | 23 |
|
25 |
-from ansible.errors import * |
|
24 |
+from ansible.compat.six import text_type |
|
25 |
+from ansible.errors import AnsibleError |
|
26 | 26 |
from ansible.playbook.attribute import FieldAttribute |
27 | 27 |
from ansible.template import Templar |
28 | 28 |
|
... | ... |
@@ -26,8 +26,7 @@ import random |
26 | 26 |
import re |
27 | 27 |
import string |
28 | 28 |
|
29 |
-from six import iteritems, string_types |
|
30 |
- |
|
29 |
+from ansible.compat.six import iteritems, string_types |
|
31 | 30 |
from ansible import constants as C |
32 | 31 |
from ansible.errors import AnsibleError |
33 | 32 |
from ansible.playbook.attribute import Attribute, FieldAttribute |
... | ... |
@@ -21,8 +21,7 @@ __metaclass__ = type |
21 | 21 |
|
22 | 22 |
import os |
23 | 23 |
|
24 |
-from six import iteritems |
|
25 |
- |
|
24 |
+from ansible.compat.six import iteritems |
|
26 | 25 |
from ansible.errors import AnsibleParserError |
27 | 26 |
from ansible.parsing.splitter import split_args, parse_kv |
28 | 27 |
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping |
... | ... |
@@ -21,7 +21,7 @@ __metaclass__ = type |
21 | 21 |
|
22 | 22 |
import os |
23 | 23 |
|
24 |
-from six import iteritems, string_types |
|
24 |
+from ansible.compat.six import iteritems, string_types |
|
25 | 25 |
|
26 | 26 |
from ansible.errors import AnsibleParserError |
27 | 27 |
from ansible.playbook.attribute import Attribute, FieldAttribute |
... | ... |
@@ -20,8 +20,8 @@ from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 | 22 |
import itertools |
23 |
-from six import string_types |
|
24 | 23 |
|
24 |
+from ansible.compat.six import string_types |
|
25 | 25 |
from ansible.errors import AnsibleError |
26 | 26 |
from ansible.playbook.attribute import FieldAttribute |
27 | 27 |
from ansible.template import Templar |
... | ... |
@@ -28,7 +28,7 @@ import stat |
28 | 28 |
import tempfile |
29 | 29 |
import time |
30 | 30 |
|
31 |
-from six import binary_type, text_type, iteritems |
|
31 |
+from ansible.compat.six import binary_type, text_type, iteritems |
|
32 | 32 |
|
33 | 33 |
from ansible import constants as C |
34 | 34 |
from ansible.errors import AnsibleError, AnsibleConnectionFailure |
... | ... |
@@ -18,7 +18,7 @@ |
18 | 18 |
from __future__ import (absolute_import, division, print_function) |
19 | 19 |
__metaclass__ = type |
20 | 20 |
|
21 |
-from six import iteritems |
|
21 |
+from ansible.compat.six import iteritems |
|
22 | 22 |
|
23 | 23 |
from ansible.errors import AnsibleError |
24 | 24 |
from ansible.plugins.action import ActionBase |
... | ... |
@@ -27,7 +27,7 @@ import os |
27 | 27 |
from abc import ABCMeta, abstractmethod, abstractproperty |
28 | 28 |
|
29 | 29 |
from functools import wraps |
30 |
-from six import with_metaclass |
|
30 |
+from ansible.compat.six import with_metaclass |
|
31 | 31 |
|
32 | 32 |
from ansible import constants as C |
33 | 33 |
from ansible.errors import AnsibleError |
... | ... |
@@ -39,7 +39,7 @@ import sys |
39 | 39 |
from termios import tcflush, TCIFLUSH |
40 | 40 |
from binascii import hexlify |
41 | 41 |
|
42 |
-from six import iteritems |
|
42 |
+from ansible.compat.six import iteritems |
|
43 | 43 |
|
44 | 44 |
from ansible import constants as C |
45 | 45 |
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound |
... | ... |
@@ -38,7 +38,7 @@ import uuid |
38 | 38 |
import yaml |
39 | 39 |
from jinja2.filters import environmentfilter |
40 | 40 |
from distutils.version import LooseVersion, StrictVersion |
41 |
-from six import iteritems |
|
41 |
+from ansible.compat.six import iteritems |
|
42 | 42 |
|
43 | 43 |
from ansible import errors |
44 | 44 |
from ansible.parsing.yaml.dumper import AnsibleDumper |
... | ... |
@@ -23,7 +23,7 @@ __metaclass__ = type |
23 | 23 |
|
24 | 24 |
from abc import ABCMeta, abstractmethod |
25 | 25 |
|
26 |
-from six import with_metaclass |
|
26 |
+from ansible.compat.six import with_metaclass |
|
27 | 27 |
|
28 | 28 |
class InventoryParser(with_metaclass(ABCMeta, object)): |
29 | 29 |
'''Abstract Base Class for retrieving inventory information |
... | ... |
@@ -19,8 +19,8 @@ |
19 | 19 |
from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 |
-from six.moves import queue as Queue |
|
23 |
-from six import iteritems, text_type |
|
22 |
+from ansible.compat.six.moves import queue as Queue |
|
23 |
+from ansible.compat.six import iteritems, text_type |
|
24 | 24 |
|
25 | 25 |
import time |
26 | 26 |
|
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 |
-from six import iteritems, text_type |
|
22 |
+from ansible.compat.six import iteritems, text_type |
|
23 | 23 |
|
24 | 24 |
from ansible.errors import AnsibleError |
25 | 25 |
from ansible.executor.play_iterator import PlayIterator |
... | ... |
@@ -24,7 +24,7 @@ import contextlib |
24 | 24 |
import os |
25 | 25 |
import re |
26 | 26 |
|
27 |
-from six import string_types, text_type, binary_type, StringIO |
|
27 |
+from ansible.compat.six import string_types, text_type, binary_type, StringIO |
|
28 | 28 |
from jinja2 import Environment |
29 | 29 |
from jinja2.loaders import FileSystemLoader |
30 | 30 |
from jinja2.exceptions import TemplateSyntaxError, UndefinedError |
... | ... |
@@ -20,8 +20,8 @@ __metaclass__ = type |
20 | 20 |
import ast |
21 | 21 |
import sys |
22 | 22 |
|
23 |
-from six import string_types |
|
24 |
-from six.moves import builtins |
|
23 |
+from ansible.compat.six import string_types |
|
24 |
+from ansible.compat.six.moves import builtins |
|
25 | 25 |
|
26 | 26 |
from ansible import constants as C |
27 | 27 |
from ansible.plugins import filter_loader, test_loader |
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 |
-from six import string_types, text_type, binary_type, PY3 |
|
22 |
+from ansible.compat.six import string_types, text_type, binary_type, PY3 |
|
23 | 23 |
|
24 | 24 |
# to_bytes and to_unicode were written by Toshio Kuratomi for the |
25 | 25 |
# python-kitchen library https://pypi.python.org/pypi/kitchen |
... | ... |
@@ -23,7 +23,7 @@ import ast |
23 | 23 |
from json import JSONEncoder |
24 | 24 |
from collections import MutableMapping |
25 | 25 |
|
26 |
-from six import iteritems, string_types |
|
26 |
+from ansible.compat.six import iteritems, string_types |
|
27 | 27 |
|
28 | 28 |
from ansible import constants as C |
29 | 29 |
from ansible.errors import AnsibleError |
... | ... |
@@ -20,7 +20,9 @@ setup(name='ansible', |
20 | 20 |
author_email='support@ansible.com', |
21 | 21 |
url='http://ansible.com/', |
22 | 22 |
license='GPLv3', |
23 |
- install_requires=['paramiko', 'jinja2', "PyYAML", 'setuptools', 'pycrypto >= 2.6', 'six'], |
|
23 |
+ # Ansible will also make use of a system copy of python-six if installed but use a |
|
24 |
+ # Bundled copy if it's not. |
|
25 |
+ install_requires=['paramiko', 'jinja2', "PyYAML", 'setuptools', 'pycrypto >= 2.6'], |
|
24 | 26 |
package_dir={ '': 'lib' }, |
25 | 27 |
packages=find_packages('lib'), |
26 | 28 |
package_data={ |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
BASEDIR=${1-"."} |
4 | 4 |
|
5 | 5 |
URLLIB_USERS=$(find "$BASEDIR" -name '*.py' -exec grep -H urlopen \{\} \;) |
6 |
-URLLIB_USERS=$(echo "$URLLIB_USERS" | sed '/\(\n\|lib\/ansible\/module_utils\/urls.py\)/d') |
|
6 |
+URLLIB_USERS=$(echo "$URLLIB_USERS" | sed '/\(\n\|lib\/ansible\/module_utils\/urls.py\|lib\/ansible\/compat\/six\/_six.py\)/d') |
|
7 | 7 |
if test -n "$URLLIB_USERS" ; then |
8 | 8 |
printf "$URLLIB_USERS" |
9 | 9 |
exit 1 |