projects/aports·blob master · refs

367 lines · 13.3 KiB

1From c6c63e7b7e248966503d8ff4ac2dfe9e43f1862d Mon Sep 17 00:00:00 2001
2From: Nate Prewitt <[email protected]>
3Date: Mon, 1 Nov 2021 11:32:35 -0700
4Subject: [PATCH] Update six from 1.10.0 to 1.16.0
5
6---
7 .changes/next-release/feature-six-62143.json | 5 +
8 awscli/botocore/vendored/six.py | 186 ++++++++++++++++---
9 2 files changed, 163 insertions(+), 28 deletions(-)
10 create mode 100644 .changes/next-release/feature-six-62143.json
11
12diff --git a/.changes/next-release/feature-six-62143.json b/.changes/next-release/feature-six-62143.json
13new file mode 100644
14index 0000000000..c4393201ee
15--- /dev/null
16+++ b/.changes/next-release/feature-six-62143.json
17@@ -0,0 +1,5 @@
18+{
19+ "type": "feature",
20+ "category": "``six``",
21+ "description": "Updated vendored version of ``six`` from 1.10.0 to 1.16.0"
22+}
23diff --git a/awscli/botocore/vendored/six.py b/awscli/botocore/vendored/six.py
24index 190c0239cd..4e15675d8b 100644
25--- a/awscli/botocore/vendored/six.py
26+++ b/awscli/botocore/vendored/six.py
27@@ -1,6 +1,4 @@
28-"""Utilities for writing code that runs on Python 2 and 3"""
29-
30-# Copyright (c) 2010-2015 Benjamin Peterson
31+# Copyright (c) 2010-2020 Benjamin Peterson
32 #
33 # Permission is hereby granted, free of charge, to any person obtaining a copy
34 # of this software and associated documentation files (the "Software"), to deal
35@@ -20,6 +18,8 @@
36 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 # SOFTWARE.
38
39+"""Utilities for writing code that runs on Python 2 and 3"""
40+
41 from __future__ import absolute_import
42
43 import functools
44@@ -29,7 +29,7 @@
45 import types
46
47 __author__ = "Benjamin Peterson <[email protected]>"
48-__version__ = "1.10.0"
49+__version__ = "1.16.0"
50
51
52 # Useful for very coarse version differentiation.
53@@ -71,6 +71,11 @@ def __len__(self):
54 MAXSIZE = int((1 << 63) - 1)
55 del X
56
57+if PY34:
58+ from importlib.util import spec_from_loader
59+else:
60+ spec_from_loader = None
61+
62
63 def _add_doc(func, doc):
64 """Add documentation to a function."""
65@@ -186,6 +191,11 @@ def find_module(self, fullname, path=None):
66 return self
67 return None
68
69+ def find_spec(self, fullname, path, target=None):
70+ if fullname in self.known_modules:
71+ return spec_from_loader(fullname, self)
72+ return None
73+
74 def __get_module(self, fullname):
75 try:
76 return self.known_modules[fullname]
77@@ -223,6 +233,12 @@ def get_code(self, fullname):
78 return None
79 get_source = get_code # same as get_code
80
81+ def create_module(self, spec):
82+ return self.load_module(spec.name)
83+
84+ def exec_module(self, module):
85+ pass
86+
87 _importer = _SixMetaPathImporter(__name__)
88
89
90@@ -241,6 +257,7 @@ class _MovedItems(_LazyModule):
91 MovedAttribute("map", "itertools", "builtins", "imap", "map"),
92 MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"),
93 MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"),
94+ MovedAttribute("getoutput", "commands", "subprocess"),
95 MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
96 MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
97 MovedAttribute("reduce", "__builtin__", "functools"),
98@@ -254,18 +271,21 @@ class _MovedItems(_LazyModule):
99 MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
100 MovedModule("builtins", "__builtin__"),
101 MovedModule("configparser", "ConfigParser"),
102+ MovedModule("collections_abc", "collections", "collections.abc" if sys.version_info >= (3, 3) else "collections"),
103 MovedModule("copyreg", "copy_reg"),
104 MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
105- MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"),
106+ MovedModule("dbm_ndbm", "dbm", "dbm.ndbm"),
107+ MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread" if sys.version_info < (3, 9) else "_thread"),
108 MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
109 MovedModule("http_cookies", "Cookie", "http.cookies"),
110 MovedModule("html_entities", "htmlentitydefs", "html.entities"),
111 MovedModule("html_parser", "HTMLParser", "html.parser"),
112 MovedModule("http_client", "httplib", "http.client"),
113+ MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
114+ MovedModule("email_mime_image", "email.MIMEImage", "email.mime.image"),
115 MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
116 MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"),
117 MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
118- MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
119 MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
120 MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
121 MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
122@@ -337,10 +357,12 @@ class Module_six_moves_urllib_parse(_LazyModule):
123 MovedAttribute("quote_plus", "urllib", "urllib.parse"),
124 MovedAttribute("unquote", "urllib", "urllib.parse"),
125 MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
126+ MovedAttribute("unquote_to_bytes", "urllib", "urllib.parse", "unquote", "unquote_to_bytes"),
127 MovedAttribute("urlencode", "urllib", "urllib.parse"),
128 MovedAttribute("splitquery", "urllib", "urllib.parse"),
129 MovedAttribute("splittag", "urllib", "urllib.parse"),
130 MovedAttribute("splituser", "urllib", "urllib.parse"),
131+ MovedAttribute("splitvalue", "urllib", "urllib.parse"),
132 MovedAttribute("uses_fragment", "urlparse", "urllib.parse"),
133 MovedAttribute("uses_netloc", "urlparse", "urllib.parse"),
134 MovedAttribute("uses_params", "urlparse", "urllib.parse"),
135@@ -416,6 +438,8 @@ class Module_six_moves_urllib_request(_LazyModule):
136 MovedAttribute("URLopener", "urllib", "urllib.request"),
137 MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
138 MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
139+ MovedAttribute("parse_http_list", "urllib2", "urllib.request"),
140+ MovedAttribute("parse_keqv_list", "urllib2", "urllib.request"),
141 ]
142 for attr in _urllib_request_moved_attributes:
143 setattr(Module_six_moves_urllib_request, attr.name, attr)
144@@ -631,13 +655,16 @@ def u(s):
145 import io
146 StringIO = io.StringIO
147 BytesIO = io.BytesIO
148+ del io
149 _assertCountEqual = "assertCountEqual"
150 if sys.version_info[1] <= 1:
151 _assertRaisesRegex = "assertRaisesRegexp"
152 _assertRegex = "assertRegexpMatches"
153+ _assertNotRegex = "assertNotRegexpMatches"
154 else:
155 _assertRaisesRegex = "assertRaisesRegex"
156 _assertRegex = "assertRegex"
157+ _assertNotRegex = "assertNotRegex"
158 else:
159 def b(s):
160 return s
161@@ -659,6 +686,7 @@ def indexbytes(buf, i):
162 _assertCountEqual = "assertItemsEqual"
163 _assertRaisesRegex = "assertRaisesRegexp"
164 _assertRegex = "assertRegexpMatches"
165+ _assertNotRegex = "assertNotRegexpMatches"
166 _add_doc(b, """Byte literal""")
167 _add_doc(u, """Text literal""")
168
169@@ -675,15 +703,23 @@ def assertRegex(self, *args, **kwargs):
170 return getattr(self, _assertRegex)(*args, **kwargs)
171
172
173+def assertNotRegex(self, *args, **kwargs):
174+ return getattr(self, _assertNotRegex)(*args, **kwargs)
175+
176+
177 if PY3:
178 exec_ = getattr(moves.builtins, "exec")
179
180 def reraise(tp, value, tb=None):
181- if value is None:
182- value = tp()
183- if value.__traceback__ is not tb:
184- raise value.with_traceback(tb)
185- raise value
186+ try:
187+ if value is None:
188+ value = tp()
189+ if value.__traceback__ is not tb:
190+ raise value.with_traceback(tb)
191+ raise value
192+ finally:
193+ value = None
194+ tb = None
195
196 else:
197 def exec_(_code_, _globs_=None, _locs_=None):
198@@ -699,19 +735,19 @@ def exec_(_code_, _globs_=None, _locs_=None):
199 exec("""exec _code_ in _globs_, _locs_""")
200
201 exec_("""def reraise(tp, value, tb=None):
202- raise tp, value, tb
203+ try:
204+ raise tp, value, tb
205+ finally:
206+ tb = None
207 """)
208
209
210-if sys.version_info[:2] == (3, 2):
211+if sys.version_info[:2] > (3,):
212 exec_("""def raise_from(value, from_value):
213- if from_value is None:
214- raise value
215- raise value from from_value
216-""")
217-elif sys.version_info[:2] > (3, 2):
218- exec_("""def raise_from(value, from_value):
219- raise value from from_value
220+ try:
221+ raise value from from_value
222+ finally:
223+ value = None
224 """)
225 else:
226 def raise_from(value, from_value):
227@@ -786,13 +822,33 @@ def print_(*args, **kwargs):
228 _add_doc(reraise, """Reraise an exception.""")
229
230 if sys.version_info[0:2] < (3, 4):
231+ # This does exactly the same what the :func:`py3:functools.update_wrapper`
232+ # function does on Python versions after 3.2. It sets the ``__wrapped__``
233+ # attribute on ``wrapper`` object and it doesn't raise an error if any of
234+ # the attributes mentioned in ``assigned`` and ``updated`` are missing on
235+ # ``wrapped`` object.
236+ def _update_wrapper(wrapper, wrapped,
237+ assigned=functools.WRAPPER_ASSIGNMENTS,
238+ updated=functools.WRAPPER_UPDATES):
239+ for attr in assigned:
240+ try:
241+ value = getattr(wrapped, attr)
242+ except AttributeError:
243+ continue
244+ else:
245+ setattr(wrapper, attr, value)
246+ for attr in updated:
247+ getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
248+ wrapper.__wrapped__ = wrapped
249+ return wrapper
250+ _update_wrapper.__doc__ = functools.update_wrapper.__doc__
251+
252 def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
253 updated=functools.WRAPPER_UPDATES):
254- def wrapper(f):
255- f = functools.wraps(wrapped, assigned, updated)(f)
256- f.__wrapped__ = wrapped
257- return f
258- return wrapper
259+ return functools.partial(_update_wrapper, wrapped=wrapped,
260+ assigned=assigned, updated=updated)
261+ wraps.__doc__ = functools.wraps.__doc__
262+
263 else:
264 wraps = functools.wraps
265
266@@ -802,10 +858,22 @@ def with_metaclass(meta, *bases):
267 # This requires a bit of explanation: the basic idea is to make a dummy
268 # metaclass for one level of class instantiation that replaces itself with
269 # the actual metaclass.
270- class metaclass(meta):
271+ class metaclass(type):
272
273 def __new__(cls, name, this_bases, d):
274- return meta(name, bases, d)
275+ if sys.version_info[:2] >= (3, 7):
276+ # This version introduced PEP 560 that requires a bit
277+ # of extra care (we mimic what is done by __build_class__).
278+ resolved_bases = types.resolve_bases(bases)
279+ if resolved_bases is not bases:
280+ d['__orig_bases__'] = bases
281+ else:
282+ resolved_bases = bases
283+ return meta(name, resolved_bases, d)
284+
285+ @classmethod
286+ def __prepare__(cls, name, this_bases):
287+ return meta.__prepare__(name, bases)
288 return type.__new__(metaclass, 'temporary_class', (), {})
289
290
291@@ -821,13 +889,75 @@ def wrapper(cls):
292 orig_vars.pop(slots_var)
293 orig_vars.pop('__dict__', None)
294 orig_vars.pop('__weakref__', None)
295+ if hasattr(cls, '__qualname__'):
296+ orig_vars['__qualname__'] = cls.__qualname__
297 return metaclass(cls.__name__, cls.__bases__, orig_vars)
298 return wrapper
299
300
301+def ensure_binary(s, encoding='utf-8', errors='strict'):
302+ """Coerce **s** to six.binary_type.
303+
304+ For Python 2:
305+ - `unicode` -> encoded to `str`
306+ - `str` -> `str`
307+
308+ For Python 3:
309+ - `str` -> encoded to `bytes`
310+ - `bytes` -> `bytes`
311+ """
312+ if isinstance(s, binary_type):
313+ return s
314+ if isinstance(s, text_type):
315+ return s.encode(encoding, errors)
316+ raise TypeError("not expecting type '%s'" % type(s))
317+
318+
319+def ensure_str(s, encoding='utf-8', errors='strict'):
320+ """Coerce *s* to `str`.
321+
322+ For Python 2:
323+ - `unicode` -> encoded to `str`
324+ - `str` -> `str`
325+
326+ For Python 3:
327+ - `str` -> `str`
328+ - `bytes` -> decoded to `str`
329+ """
330+ # Optimization: Fast return for the common case.
331+ if type(s) is str:
332+ return s
333+ if PY2 and isinstance(s, text_type):
334+ return s.encode(encoding, errors)
335+ elif PY3 and isinstance(s, binary_type):
336+ return s.decode(encoding, errors)
337+ elif not isinstance(s, (text_type, binary_type)):
338+ raise TypeError("not expecting type '%s'" % type(s))
339+ return s
340+
341+
342+def ensure_text(s, encoding='utf-8', errors='strict'):
343+ """Coerce *s* to six.text_type.
344+
345+ For Python 2:
346+ - `unicode` -> `unicode`
347+ - `str` -> `unicode`
348+
349+ For Python 3:
350+ - `str` -> `str`
351+ - `bytes` -> decoded to `str`
352+ """
353+ if isinstance(s, binary_type):
354+ return s.decode(encoding, errors)
355+ elif isinstance(s, text_type):
356+ return s
357+ else:
358+ raise TypeError("not expecting type '%s'" % type(s))
359+
360+
361 def python_2_unicode_compatible(klass):
362 """
363- A decorator that defines __unicode__ and __str__ methods under Python 2.
364+ A class decorator that defines __unicode__ and __str__ methods under Python 2.
365 Under Python 3 it does nothing.
366
367 To support Python 2 and 3 with a single code base, define a __str__ method