Skip to content

Commit

Permalink
Merge pull request #704 from eurovibes/master
Browse files Browse the repository at this point in the history
Update customized six version
  • Loading branch information
plq authored Dec 8, 2023
2 parents 41fd7d4 + 8f31a7b commit 70d2ec7
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions spyne/util/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import types

__author__ = "Benjamin Peterson <[email protected]>"
__version__ = "1.14.0"
__version__ = "1.16.0"


# Useful for very coarse version differentiation.
Expand Down Expand Up @@ -71,6 +71,11 @@ def __len__(self):
MAXSIZE = int((1 << 63) - 1)
del X

if PY34:
from importlib.util import spec_from_loader
else:
spec_from_loader = None


def _add_doc(func, doc):
"""Add documentation to a function."""
Expand Down Expand Up @@ -186,6 +191,11 @@ def find_module(self, fullname, path=None):
return self
return None

def find_spec(self, fullname, path, target=None):
if fullname in self.known_modules:
return spec_from_loader(fullname, self)
return None

def __get_module(self, fullname):
try:
return self.known_modules[fullname]
Expand Down Expand Up @@ -223,6 +233,12 @@ def get_code(self, fullname):
return None
get_source = get_code # same as get_code

def create_module(self, spec):
return self.load_module(spec.name)

def exec_module(self, module):
pass

_importer = _SixMetaPathImporter(__name__)


Expand All @@ -247,7 +263,7 @@ class _MovedItems(_LazyModule):
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
MovedAttribute("StringIO", "StringIO", "io"),
MovedAttribute("UserDict", "UserDict", "collections"),
MovedAttribute("UserDict", "UserDict", "collections", "IterableUserDict", "UserDict"),
MovedAttribute("UserList", "UserList", "collections"),
MovedAttribute("UserString", "UserString", "collections"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
Expand Down Expand Up @@ -895,12 +911,11 @@ def ensure_binary(s, encoding='utf-8', errors='strict'):
- `str` -> encoded to `bytes`
- `bytes` -> `bytes`
"""
if isinstance(s, binary_type):
return s
if isinstance(s, text_type):
return s.encode(encoding, errors)
elif isinstance(s, binary_type):
return s
else:
raise TypeError("not expecting type '%s'" % type(s))
raise TypeError("not expecting type '%s'" % type(s))


def ensure_str(s, encoding='utf-8', errors='strict'):
Expand All @@ -914,12 +929,15 @@ def ensure_str(s, encoding='utf-8', errors='strict'):
- `str` -> `str`
- `bytes` -> decoded to `str`
"""
if not isinstance(s, (text_type, binary_type)):
raise TypeError("not expecting type '%s'" % type(s))
# Optimization: Fast return for the common case.
if type(s) is str:
return s
if PY2 and isinstance(s, text_type):
s = s.encode(encoding, errors)
return s.encode(encoding, errors)
elif PY3 and isinstance(s, binary_type):
s = s.decode(encoding, errors)
return s.decode(encoding, errors)
elif not isinstance(s, (text_type, binary_type)):
raise TypeError("not expecting type '%s'" % type(s))
return s


Expand Down Expand Up @@ -982,4 +1000,4 @@ def python_2_unicode_compatible(klass):
break
del i, importer
# Finally, add the importer to the meta path import hook.
sys.meta_path.append(_importer)
sys.meta_path.append(_importer)

0 comments on commit 70d2ec7

Please sign in to comment.