Skip to content

Commit 11f5b3b

Browse files
author
Shoshana Berleant
committed
update six to version 1.10.0
1 parent 61fd4f6 commit 11f5b3b

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

nipype/external/six.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# SOFTWARE.
2222

2323
from __future__ import absolute_import
24-
from future.utils import raise_from
2524

2625
import functools
2726
import itertools
@@ -30,12 +29,13 @@
3029
import types
3130

3231
__author__ = "Benjamin Peterson <benjamin@python.org>"
33-
__version__ = "1.9.0"
32+
__version__ = "1.10.0"
3433

3534

3635
# Useful for very coarse version differentiation.
3736
PY2 = sys.version_info[0] == 2
3837
PY3 = sys.version_info[0] == 3
38+
PY34 = sys.version_info[0:2] >= (3, 4)
3939

4040
if PY3:
4141
string_types = str,
@@ -58,6 +58,7 @@
5858
else:
5959
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
6060
class X(object):
61+
6162
def __len__(self):
6263
return 1 << 31
6364
try:
@@ -161,6 +162,7 @@ def _resolve(self):
161162

162163

163164
class _SixMetaPathImporter(object):
165+
164166
"""
165167
A meta path importer to import six.moves and its submodules.
166168
@@ -187,8 +189,8 @@ def find_module(self, fullname, path=None):
187189
def __get_module(self, fullname):
188190
try:
189191
return self.known_modules[fullname]
190-
except KeyError as e:
191-
raise_from(ImportError("This loader does not know module " + fullname), e)
192+
except KeyError:
193+
raise ImportError("This loader does not know module " + fullname)
192194

193195
def load_module(self, fullname):
194196
try:
@@ -225,6 +227,7 @@ def get_code(self, fullname):
225227

226228

227229
class _MovedItems(_LazyModule):
230+
228231
"""Lazy loading of moved objects"""
229232
__path__ = [] # mark as package
230233

@@ -236,8 +239,10 @@ class _MovedItems(_LazyModule):
236239
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
237240
MovedAttribute("intern", "__builtin__", "sys"),
238241
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
242+
MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"),
243+
MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"),
239244
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
240-
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
245+
MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
241246
MovedAttribute("reduce", "__builtin__", "functools"),
242247
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
243248
MovedAttribute("StringIO", "StringIO", "io"),
@@ -247,7 +252,6 @@ class _MovedItems(_LazyModule):
247252
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
248253
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
249254
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
250-
251255
MovedModule("builtins", "__builtin__"),
252256
MovedModule("configparser", "ConfigParser"),
253257
MovedModule("copyreg", "copy_reg"),
@@ -294,8 +298,13 @@ class _MovedItems(_LazyModule):
294298
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
295299
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
296300
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
297-
MovedModule("winreg", "_winreg"),
298301
]
302+
# Add windows specific modules.
303+
if sys.platform == "win32":
304+
_moved_attributes += [
305+
MovedModule("winreg", "_winreg"),
306+
]
307+
299308
for attr in _moved_attributes:
300309
setattr(_MovedItems, attr.name, attr)
301310
if isinstance(attr, MovedModule):
@@ -309,6 +318,7 @@ class _MovedItems(_LazyModule):
309318

310319

311320
class Module_six_moves_urllib_parse(_LazyModule):
321+
312322
"""Lazy loading of moved objects in six.moves.urllib_parse"""
313323

314324

@@ -348,6 +358,7 @@ class Module_six_moves_urllib_parse(_LazyModule):
348358

349359

350360
class Module_six_moves_urllib_error(_LazyModule):
361+
351362
"""Lazy loading of moved objects in six.moves.urllib_error"""
352363

353364

@@ -367,6 +378,7 @@ class Module_six_moves_urllib_error(_LazyModule):
367378

368379

369380
class Module_six_moves_urllib_request(_LazyModule):
381+
370382
"""Lazy loading of moved objects in six.moves.urllib_request"""
371383

372384

@@ -416,6 +428,7 @@ class Module_six_moves_urllib_request(_LazyModule):
416428

417429

418430
class Module_six_moves_urllib_response(_LazyModule):
431+
419432
"""Lazy loading of moved objects in six.moves.urllib_response"""
420433

421434

@@ -436,6 +449,7 @@ class Module_six_moves_urllib_response(_LazyModule):
436449

437450

438451
class Module_six_moves_urllib_robotparser(_LazyModule):
452+
439453
"""Lazy loading of moved objects in six.moves.urllib_robotparser"""
440454

441455

@@ -453,6 +467,7 @@ class Module_six_moves_urllib_robotparser(_LazyModule):
453467

454468

455469
class Module_six_moves_urllib(types.ModuleType):
470+
456471
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
457472
__path__ = [] # mark as package
458473
parse = _importer._get_module("moves.urllib_parse")
@@ -523,6 +538,9 @@ def get_unbound_function(unbound):
523538

524539
create_bound_method = types.MethodType
525540

541+
def create_unbound_method(func, cls):
542+
return func
543+
526544
Iterator = object
527545
else:
528546
def get_unbound_function(unbound):
@@ -531,6 +549,9 @@ def get_unbound_function(unbound):
531549
def create_bound_method(func, obj):
532550
return types.MethodType(func, obj, obj.__class__)
533551

552+
def create_unbound_method(func, cls):
553+
return types.MethodType(func, None, cls)
554+
534555
class Iterator(object):
535556

536557
def next(self):
@@ -569,16 +590,16 @@ def iterlists(d, **kw):
569590
viewitems = operator.methodcaller("items")
570591
else:
571592
def iterkeys(d, **kw):
572-
return iter(d.iterkeys(**kw))
593+
return d.iterkeys(**kw)
573594

574595
def itervalues(d, **kw):
575-
return iter(d.itervalues(**kw))
596+
return d.itervalues(**kw)
576597

577598
def iteritems(d, **kw):
578-
return iter(d.iteritems(**kw))
599+
return d.iteritems(**kw)
579600

580601
def iterlists(d, **kw):
581-
return iter(d.iterlists(**kw))
602+
return d.iterlists(**kw)
582603

583604
viewkeys = operator.methodcaller("viewkeys")
584605

@@ -601,21 +622,22 @@ def b(s):
601622
def u(s):
602623
return s
603624
unichr = chr
604-
if sys.version_info[1] <= 1:
605-
def int2byte(i):
606-
return bytes((i,))
607-
else:
608-
# This is about 2x faster than the implementation above on 3.2+
609-
int2byte = operator.methodcaller("to_bytes", 1, "big")
625+
import struct
626+
int2byte = struct.Struct(">B").pack
627+
del struct
610628
byte2int = operator.itemgetter(0)
611629
indexbytes = operator.getitem
612630
iterbytes = iter
613631
import io
614632
StringIO = io.StringIO
615633
BytesIO = io.BytesIO
616634
_assertCountEqual = "assertCountEqual"
617-
_assertRaisesRegex = "assertRaisesRegex"
618-
_assertRegex = "assertRegex"
635+
if sys.version_info[1] <= 1:
636+
_assertRaisesRegex = "assertRaisesRegexp"
637+
_assertRegex = "assertRegexpMatches"
638+
else:
639+
_assertRaisesRegex = "assertRaisesRegex"
640+
_assertRegex = "assertRegex"
619641
else:
620642
def b(s):
621643
return s
@@ -781,6 +803,7 @@ def with_metaclass(meta, *bases):
781803
# metaclass for one level of class instantiation that replaces itself with
782804
# the actual metaclass.
783805
class metaclass(meta):
806+
784807
def __new__(cls, name, this_bases, d):
785808
return meta(name, bases, d)
786809
return type.__new__(metaclass, 'temporary_class', (), {})

0 commit comments

Comments
 (0)