0001import sys
0002import types
0003
0004# Credit to six authors: http://pypi.python.org/pypi/six
0005# License: MIT
0006
0007
0008def with_metaclass(meta, *bases):
0009    """Create a base class with a metaclass."""
0010    # This requires a bit of explanation: the basic idea is to make a dummy
0011    # metaclass for one level of class instantiation that replaces itself with
0012    # the actual metaclass.
0013
0014    class metaclass(meta):
0015        def __new__(cls, name, this_bases, d):
0016            return meta(name, bases, d)
0017    return type.__new__(metaclass, 'temporary_class', (), {})
0018
0019# Compatability definitions (inspired by six)
0020PY2 = sys.version_info[0] < 3
0021if PY2:
0022    # disable flake8 checks on python 3
0023    string_type = basestring  # noqa
0024    unicode_type = unicode  # noqa
0025    class_types = (type, types.ClassType)
0026    buffer_type = buffer  # noqa
0027else:
0028    string_type = str
0029    unicode_type = str
0030    class_types = (type,)
0031    buffer_type = memoryview