src.six module

Utilities for writing code that runs on Python 2 and 3

src.six._add_doc(func, doc)[source]

Add documentation to a function.

src.six._import_module(name)[source]

Import module, returning the module after the last dot.

class src.six._LazyDescr(name)[source]

Bases: object

__init__(name)[source]

Initialize self. See help(type(self)) for accurate signature.

class src.six.MovedModule(name, old, new=None)[source]

Bases: src.six._LazyDescr

__init__(name, old, new=None)[source]

Initialize self. See help(type(self)) for accurate signature.

_resolve()[source]
class src.six._LazyModule(name)[source]

Bases: module

__init__(name)[source]

Initialize self. See help(type(self)) for accurate signature.

_moved_attributes = []
class src.six.MovedAttribute(name, old_mod, new_mod, old_attr=None, new_attr=None)[source]

Bases: src.six._LazyDescr

__init__(name, old_mod, new_mod, old_attr=None, new_attr=None)[source]

Initialize self. See help(type(self)) for accurate signature.

_resolve()[source]
class src.six._SixMetaPathImporter(six_module_name)[source]

Bases: object

A meta path importer to import six.moves and its submodules.

This class implements a PEP302 finder and loader. It should be compatible with Python 2.5 and all existing versions of Python3

__init__(six_module_name)[source]

Initialize self. See help(type(self)) for accurate signature.

_add_module(mod, *fullnames)[source]
_get_module(fullname)[source]
find_module(fullname, path=None)[source]
load_module(fullname)[source]
is_package(fullname)[source]

Return true, if the named module is a package.

We need this method to get correct spec objects with Python 3.4 (see PEP451)

get_code(fullname)[source]

Return None

Required, if is_package is implemented

get_source(fullname)

Return None

Required, if is_package is implemented

_SixMetaPathImporter__get_module(fullname)
src.six.add_move(move)[source]

Add an item to six.moves.

src.six.remove_move(name)[source]

Remove item from six.moves.

src.six.get_unbound_function(unbound)[source]

Get the function out of a possibly unbound function

src.six.create_unbound_method(func, cls)[source]
src.six.iterkeys(d, **kw)[source]

Return an iterator over the keys of a dictionary.

src.six.itervalues(d, **kw)[source]

Return an iterator over the values of a dictionary.

src.six.iteritems(d, **kw)[source]

Return an iterator over the (key, value) pairs of a dictionary.

src.six.iterlists(d, **kw)[source]

Return an iterator over the (key, [values]) pairs of a dictionary.

src.six.b(s)[source]

Byte literal

src.six.u(s)[source]

Text literal

src.six.int2byte()

S.pack(v1, v2, …) -> bytes

Return a bytes object containing values v1, v2, … packed according to the format string S.format. See help(struct) for more on format strings.

src.six.assertCountEqual(self, *args, **kwargs)[source]
src.six.assertRaisesRegex(self, *args, **kwargs)[source]
src.six.assertRegex(self, *args, **kwargs)[source]
src.six.assertNotRegex(self, *args, **kwargs)[source]
src.six.reraise(tp, value, tb=None)[source]

Reraise an exception.

src.six.raise_from(value, from_value)[source]
src.six.with_metaclass(meta, *bases)[source]

Create a base class with a metaclass.

src.six.add_metaclass(metaclass)[source]

Class decorator for creating a class with a metaclass.

src.six.ensure_binary(s, encoding='utf-8', errors='strict')[source]

Coerce s to six.binary_type.

For Python 2:
  • unicode -> encoded to str

  • str -> str

For Python 3:
  • str -> encoded to bytes

  • bytes -> bytes

src.six.ensure_str(s, encoding='utf-8', errors='strict')[source]

Coerce s to str.

For Python 2:
  • unicode -> encoded to str

  • str -> str

For Python 3:
  • str -> str

  • bytes -> decoded to str

src.six.ensure_text(s, encoding='utf-8', errors='strict')[source]

Coerce s to six.text_type.

For Python 2:
  • unicode -> unicode

  • str -> unicode

For Python 3:
  • str -> str

  • bytes -> decoded to str

src.six.python_2_unicode_compatible(klass)[source]

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.