OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 Donald Stufft |
| 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at |
| 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. |
| 14 from __future__ import absolute_import, division, print_function |
| 15 |
| 16 import sys |
| 17 |
| 18 |
| 19 PY2 = sys.version_info[0] == 2 |
| 20 PY3 = sys.version_info[0] == 3 |
| 21 |
| 22 # flake8: noqa |
| 23 |
| 24 if PY3: |
| 25 string_types = str, |
| 26 else: |
| 27 string_types = basestring, |
| 28 |
| 29 |
| 30 def with_metaclass(meta, *bases): |
| 31 """ |
| 32 Create a base class with a metaclass. |
| 33 """ |
| 34 # This requires a bit of explanation: the basic idea is to make a dummy |
| 35 # metaclass for one level of class instantiation that replaces itself with |
| 36 # the actual metaclass. |
| 37 class metaclass(meta): |
| 38 def __new__(cls, name, this_bases, d): |
| 39 return meta(name, bases, d) |
| 40 return type.__new__(metaclass, 'temporary_class', (), {}) |
OLD | NEW |