def with_metaclass(metaclass, *bases):
    """
    Construct a base class with metaclass compatible with python2 and python3.

    Usage:
    ```
    class(with_metaclass(metaclass, base1, base2...)):
        ....
    ```
    """

    class InterposedMetaClass(metaclass):
        def __new__(mcls, name, new_bases, attrs):
            return metaclass(name, bases, attrs)
    return type.__new__(InterposedMetaClass, 'Dummy', (), {})