Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2698537

Browse files
committed
Update vendored six to 1.16.0
1 parent07bed79 commit2698537

File tree

1 file changed

+89
-33
lines changed

1 file changed

+89
-33
lines changed

‎src/urllib3/packages/six.py‎

Lines changed: 89 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010-2019 Benjamin Peterson
1+
# Copyright (c) 2010-2020 Benjamin Peterson
22
#
33
# Permission is hereby granted, free of charge, to any person obtaining a copy
44
# of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@
2929
importtypes
3030

3131
__author__="Benjamin Peterson <benjamin@python.org>"
32-
__version__="1.12.0"
32+
__version__="1.16.0"
3333

3434

3535
# Useful for very coarse version differentiation.
@@ -71,6 +71,11 @@ def __len__(self):
7171
MAXSIZE=int((1<<63)-1)
7272
delX
7373

74+
ifPY34:
75+
fromimportlib.utilimportspec_from_loader
76+
else:
77+
spec_from_loader=None
78+
7479

7580
def_add_doc(func,doc):
7681
"""Add documentation to a function."""
@@ -182,6 +187,11 @@ def find_module(self, fullname, path=None):
182187
returnself
183188
returnNone
184189

190+
deffind_spec(self,fullname,path,target=None):
191+
iffullnameinself.known_modules:
192+
returnspec_from_loader(fullname,self)
193+
returnNone
194+
185195
def__get_module(self,fullname):
186196
try:
187197
returnself.known_modules[fullname]
@@ -220,6 +230,12 @@ def get_code(self, fullname):
220230

221231
get_source=get_code# same as get_code
222232

233+
defcreate_module(self,spec):
234+
returnself.load_module(spec.name)
235+
236+
defexec_module(self,module):
237+
pass
238+
223239

224240
_importer=_SixMetaPathImporter(__name__)
225241

@@ -260,9 +276,19 @@ class _MovedItems(_LazyModule):
260276
),
261277
MovedModule("builtins","__builtin__"),
262278
MovedModule("configparser","ConfigParser"),
279+
MovedModule(
280+
"collections_abc",
281+
"collections",
282+
"collections.abc"ifsys.version_info>= (3,3)else"collections",
283+
),
263284
MovedModule("copyreg","copy_reg"),
264285
MovedModule("dbm_gnu","gdbm","dbm.gnu"),
265-
MovedModule("_dummy_thread","dummy_thread","_dummy_thread"),
286+
MovedModule("dbm_ndbm","dbm","dbm.ndbm"),
287+
MovedModule(
288+
"_dummy_thread",
289+
"dummy_thread",
290+
"_dummy_thread"ifsys.version_info< (3,9)else"_thread",
291+
),
266292
MovedModule("http_cookiejar","cookielib","http.cookiejar"),
267293
MovedModule("http_cookies","Cookie","http.cookies"),
268294
MovedModule("html_entities","htmlentitydefs","html.entities"),
@@ -307,7 +333,9 @@ class _MovedItems(_LazyModule):
307333
]
308334
# Add windows specific modules.
309335
ifsys.platform=="win32":
310-
_moved_attributes+= [MovedModule("winreg","_winreg")]
336+
_moved_attributes+= [
337+
MovedModule("winreg","_winreg"),
338+
]
311339

312340
forattrin_moved_attributes:
313341
setattr(_MovedItems,attr.name,attr)
@@ -476,7 +504,7 @@ class Module_six_moves_urllib_robotparser(_LazyModule):
476504

477505

478506
_urllib_robotparser_moved_attributes= [
479-
MovedAttribute("RobotFileParser","robotparser","urllib.robotparser")
507+
MovedAttribute("RobotFileParser","robotparser","urllib.robotparser"),
480508
]
481509
forattrin_urllib_robotparser_moved_attributes:
482510
setattr(Module_six_moves_urllib_robotparser,attr.name,attr)
@@ -678,9 +706,11 @@ def u(s):
678706
ifsys.version_info[1]<=1:
679707
_assertRaisesRegex="assertRaisesRegexp"
680708
_assertRegex="assertRegexpMatches"
709+
_assertNotRegex="assertNotRegexpMatches"
681710
else:
682711
_assertRaisesRegex="assertRaisesRegex"
683712
_assertRegex="assertRegex"
713+
_assertNotRegex="assertNotRegex"
684714
else:
685715

686716
defb(s):
@@ -707,6 +737,7 @@ def indexbytes(buf, i):
707737
_assertCountEqual="assertItemsEqual"
708738
_assertRaisesRegex="assertRaisesRegexp"
709739
_assertRegex="assertRegexpMatches"
740+
_assertNotRegex="assertNotRegexpMatches"
710741
_add_doc(b,"""Byte literal""")
711742
_add_doc(u,"""Text literal""")
712743

@@ -723,6 +754,10 @@ def assertRegex(self, *args, **kwargs):
723754
returngetattr(self,_assertRegex)(*args,**kwargs)
724755

725756

757+
defassertNotRegex(self,*args,**kwargs):
758+
returngetattr(self,_assertNotRegex)(*args,**kwargs)
759+
760+
726761
ifPY3:
727762
exec_=getattr(moves.builtins,"exec")
728763

@@ -762,18 +797,7 @@ def exec_(_code_, _globs_=None, _locs_=None):
762797
)
763798

764799

765-
ifsys.version_info[:2]== (3,2):
766-
exec_(
767-
"""def raise_from(value, from_value):
768-
try:
769-
if from_value is None:
770-
raise value
771-
raise value from from_value
772-
finally:
773-
value = None
774-
"""
775-
)
776-
elifsys.version_info[:2]> (3,2):
800+
ifsys.version_info[:2]> (3,):
777801
exec_(
778802
"""def raise_from(value, from_value):
779803
try:
@@ -863,19 +887,41 @@ def print_(*args, **kwargs):
863887
_add_doc(reraise,"""Reraise an exception.""")
864888

865889
ifsys.version_info[0:2]< (3,4):
890+
# This does exactly the same what the :func:`py3:functools.update_wrapper`
891+
# function does on Python versions after 3.2. It sets the ``__wrapped__``
892+
# attribute on ``wrapper`` object and it doesn't raise an error if any of
893+
# the attributes mentioned in ``assigned`` and ``updated`` are missing on
894+
# ``wrapped`` object.
895+
def_update_wrapper(
896+
wrapper,
897+
wrapped,
898+
assigned=functools.WRAPPER_ASSIGNMENTS,
899+
updated=functools.WRAPPER_UPDATES,
900+
):
901+
forattrinassigned:
902+
try:
903+
value=getattr(wrapped,attr)
904+
exceptAttributeError:
905+
continue
906+
else:
907+
setattr(wrapper,attr,value)
908+
forattrinupdated:
909+
getattr(wrapper,attr).update(getattr(wrapped,attr, {}))
910+
wrapper.__wrapped__=wrapped
911+
returnwrapper
912+
913+
_update_wrapper.__doc__=functools.update_wrapper.__doc__
866914

867915
defwraps(
868916
wrapped,
869917
assigned=functools.WRAPPER_ASSIGNMENTS,
870918
updated=functools.WRAPPER_UPDATES,
871919
):
872-
defwrapper(f):
873-
f=functools.wraps(wrapped,assigned,updated)(f)
874-
f.__wrapped__=wrapped
875-
returnf
876-
877-
returnwrapper
920+
returnfunctools.partial(
921+
_update_wrapper,wrapped=wrapped,assigned=assigned,updated=updated
922+
)
878923

924+
wraps.__doc__=functools.wraps.__doc__
879925

880926
else:
881927
wraps=functools.wraps
@@ -888,7 +934,15 @@ def with_metaclass(meta, *bases):
888934
# the actual metaclass.
889935
classmetaclass(type):
890936
def__new__(cls,name,this_bases,d):
891-
returnmeta(name,bases,d)
937+
ifsys.version_info[:2]>= (3,7):
938+
# This version introduced PEP 560 that requires a bit
939+
# of extra care (we mimic what is done by __build_class__).
940+
resolved_bases=types.resolve_bases(bases)
941+
ifresolved_basesisnotbases:
942+
d["__orig_bases__"]=bases
943+
else:
944+
resolved_bases=bases
945+
returnmeta(name,resolved_bases,d)
892946

893947
@classmethod
894948
def__prepare__(cls,name,this_bases):
@@ -928,12 +982,11 @@ def ensure_binary(s, encoding="utf-8", errors="strict"):
928982
- `str` -> encoded to `bytes`
929983
- `bytes` -> `bytes`
930984
"""
985+
ifisinstance(s,binary_type):
986+
returns
931987
ifisinstance(s,text_type):
932988
returns.encode(encoding,errors)
933-
elifisinstance(s,binary_type):
934-
returns
935-
else:
936-
raiseTypeError("not expecting type '%s'"%type(s))
989+
raiseTypeError("not expecting type '%s'"%type(s))
937990

938991

939992
defensure_str(s,encoding="utf-8",errors="strict"):
@@ -947,12 +1000,15 @@ def ensure_str(s, encoding="utf-8", errors="strict"):
9471000
- `str` -> `str`
9481001
- `bytes` -> decoded to `str`
9491002
"""
950-
ifnotisinstance(s, (text_type,binary_type)):
951-
raiseTypeError("not expecting type '%s'"%type(s))
1003+
# Optimization: Fast return for the common case.
1004+
iftype(s)isstr:
1005+
returns
9521006
ifPY2andisinstance(s,text_type):
953-
s=s.encode(encoding,errors)
1007+
returns.encode(encoding,errors)
9541008
elifPY3andisinstance(s,binary_type):
955-
s=s.decode(encoding,errors)
1009+
returns.decode(encoding,errors)
1010+
elifnotisinstance(s, (text_type,binary_type)):
1011+
raiseTypeError("not expecting type '%s'"%type(s))
9561012
returns
9571013

9581014

@@ -977,7 +1033,7 @@ def ensure_text(s, encoding="utf-8", errors="strict"):
9771033

9781034
defpython_2_unicode_compatible(klass):
9791035
"""
980-
A decorator that defines __unicode__ and __str__ methods under Python 2.
1036+
Aclassdecorator that defines __unicode__ and __str__ methods under Python 2.
9811037
Under Python 3 it does nothing.
9821038
9831039
To support Python 2 and 3 with a single code base, define a __str__ method

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp