Skip to content

six

Utilities for writing code that runs on Python 2 and 3

Module_six_moves_urllib

Bases: ModuleType

Create a six.moves.urllib namespace that resembles the Python 3 namespace

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
524
525
526
527
528
529
530
531
532
533
534
535
536
class Module_six_moves_urllib(types.ModuleType):

    """Create a six.moves.urllib namespace that resembles the Python 3 namespace"""

    __path__ = []  # mark as package
    parse = _importer._get_module("moves.urllib_parse")
    error = _importer._get_module("moves.urllib_error")
    request = _importer._get_module("moves.urllib_request")
    response = _importer._get_module("moves.urllib_response")
    robotparser = _importer._get_module("moves.urllib_robotparser")

    def __dir__(self):
        return ["parse", "error", "request", "response", "robotparser"]

Module_six_moves_urllib_error

Bases: _LazyModule

Lazy loading of moved objects in six.moves.urllib_error

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
399
400
401
class Module_six_moves_urllib_error(_LazyModule):

    """Lazy loading of moved objects in six.moves.urllib_error"""

Module_six_moves_urllib_parse

Bases: _LazyModule

Lazy loading of moved objects in six.moves.urllib_parse

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
352
353
354
class Module_six_moves_urllib_parse(_LazyModule):

    """Lazy loading of moved objects in six.moves.urllib_parse"""

Module_six_moves_urllib_request

Bases: _LazyModule

Lazy loading of moved objects in six.moves.urllib_request

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
422
423
424
class Module_six_moves_urllib_request(_LazyModule):

    """Lazy loading of moved objects in six.moves.urllib_request"""

Module_six_moves_urllib_response

Bases: _LazyModule

Lazy loading of moved objects in six.moves.urllib_response

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
477
478
479
class Module_six_moves_urllib_response(_LazyModule):

    """Lazy loading of moved objects in six.moves.urllib_response"""

Module_six_moves_urllib_robotparser

Bases: _LazyModule

Lazy loading of moved objects in six.moves.urllib_robotparser

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
501
502
503
class Module_six_moves_urllib_robotparser(_LazyModule):

    """Lazy loading of moved objects in six.moves.urllib_robotparser"""

add_metaclass(metaclass)

Class decorator for creating a class with a metaclass.

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
def add_metaclass(metaclass):
    """Class decorator for creating a class with a metaclass."""

    def wrapper(cls):
        orig_vars = cls.__dict__.copy()
        slots = orig_vars.get("__slots__")
        if slots is not None:
            if isinstance(slots, str):
                slots = [slots]
            for slots_var in slots:
                orig_vars.pop(slots_var)
        orig_vars.pop("__dict__", None)
        orig_vars.pop("__weakref__", None)
        if hasattr(cls, "__qualname__"):
            orig_vars["__qualname__"] = cls.__qualname__
        return metaclass(cls.__name__, cls.__bases__, orig_vars)

    return wrapper

add_move(move)

Add an item to six.moves.

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
544
545
546
def add_move(move):
    """Add an item to six.moves."""
    setattr(_MovedItems, move.name, move)

ensure_binary(s, encoding='utf-8', errors='strict')

Coerce s to six.binary_type.

For Python 2
  • unicode -> encoded to str
  • str -> str
For Python 3
  • str -> encoded to bytes
  • bytes -> bytes
Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
def ensure_binary(s, encoding="utf-8", errors="strict"):
    """Coerce **s** to six.binary_type.

    For Python 2:
      - `unicode` -> encoded to `str`
      - `str` -> `str`

    For Python 3:
      - `str` -> encoded to `bytes`
      - `bytes` -> `bytes`
    """
    if isinstance(s, binary_type):
        return s
    if isinstance(s, text_type):
        return s.encode(encoding, errors)
    raise TypeError("not expecting type '%s'" % type(s))

ensure_str(s, encoding='utf-8', errors='strict')

Coerce s to str.

For Python 2
  • unicode -> encoded to str
  • str -> str
For Python 3
  • str -> str
  • bytes -> decoded to str
Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
def ensure_str(s, encoding="utf-8", errors="strict"):
    """Coerce *s* to `str`.

    For Python 2:
      - `unicode` -> encoded to `str`
      - `str` -> `str`

    For Python 3:
      - `str` -> `str`
      - `bytes` -> decoded to `str`
    """
    # Optimization: Fast return for the common case.
    if type(s) is str:
        return s
    if PY2 and isinstance(s, text_type):
        return s.encode(encoding, errors)
    elif PY3 and isinstance(s, binary_type):
        return s.decode(encoding, errors)
    elif not isinstance(s, (text_type, binary_type)):
        raise TypeError("not expecting type '%s'" % type(s))
    return s

ensure_text(s, encoding='utf-8', errors='strict')

Coerce s to six.text_type.

For Python 2
  • unicode -> unicode
  • str -> unicode
For Python 3
  • str -> str
  • bytes -> decoded to str
Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
def ensure_text(s, encoding="utf-8", errors="strict"):
    """Coerce *s* to six.text_type.

    For Python 2:
      - `unicode` -> `unicode`
      - `str` -> `unicode`

    For Python 3:
      - `str` -> `str`
      - `bytes` -> decoded to `str`
    """
    if isinstance(s, binary_type):
        return s.decode(encoding, errors)
    elif isinstance(s, text_type):
        return s
    else:
        raise TypeError("not expecting type '%s'" % type(s))

exec_(_code_, _globs_=None, _locs_=None)

Execute code in a namespace.

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
778
779
780
781
782
783
784
785
786
787
788
def exec_(_code_, _globs_=None, _locs_=None):
    """Execute code in a namespace."""
    if _globs_ is None:
        frame = sys._getframe(1)
        _globs_ = frame.f_globals
        if _locs_ is None:
            _locs_ = frame.f_locals
        del frame
    elif _locs_ is None:
        _locs_ = _globs_
    exec ("""exec _code_ in _globs_, _locs_""")

python_2_unicode_compatible(klass)

A class decorator that defines unicode and str methods under Python 2. Under Python 3 it does nothing.

To support Python 2 and 3 with a single code base, define a str method returning text and apply this decorator to the class.

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
def python_2_unicode_compatible(klass):
    """
    A class decorator that defines __unicode__ and __str__ methods under Python 2.
    Under Python 3 it does nothing.

    To support Python 2 and 3 with a single code base, define a __str__ method
    returning text and apply this decorator to the class.
    """
    if PY2:
        if "__str__" not in klass.__dict__:
            raise ValueError(
                "@python_2_unicode_compatible cannot be applied "
                "to %s because it doesn't define __str__()." % klass.__name__
            )
        klass.__unicode__ = klass.__str__
        klass.__str__ = lambda self: self.__unicode__().encode("utf-8")
    return klass

remove_move(name)

Remove item from six.moves.

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
549
550
551
552
553
554
555
556
557
def remove_move(name):
    """Remove item from six.moves."""
    try:
        delattr(_MovedItems, name)
    except AttributeError:
        try:
            del moves.__dict__[name]
        except KeyError:
            raise AttributeError("no such move, %r" % (name,))

with_metaclass(meta, *bases)

Create a base class with a metaclass.

Source code in client/ayon_fusion/vendor/urllib3/packages/six.py
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
def with_metaclass(meta, *bases):
    """Create a base class with a metaclass."""
    # This requires a bit of explanation: the basic idea is to make a dummy
    # metaclass for one level of class instantiation that replaces itself with
    # the actual metaclass.
    class metaclass(type):
        def __new__(cls, name, this_bases, d):
            if sys.version_info[:2] >= (3, 7):
                # This version introduced PEP 560 that requires a bit
                # of extra care (we mimic what is done by __build_class__).
                resolved_bases = types.resolve_bases(bases)
                if resolved_bases is not bases:
                    d["__orig_bases__"] = bases
            else:
                resolved_bases = bases
            return meta(name, resolved_bases, d)

        @classmethod
        def __prepare__(cls, name, this_bases):
            return meta.__prepare__(name, bases)

    return type.__new__(metaclass, "temporary_class", (), {})