diff options
Diffstat (limited to 'cloudinit/net/compat.py')
-rw-r--r-- | cloudinit/net/compat.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cloudinit/net/compat.py b/cloudinit/net/compat.py new file mode 100644 index 00000000..8bf92ef5 --- /dev/null +++ b/cloudinit/net/compat.py @@ -0,0 +1,51 @@ +# Curtin is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# Curtin is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +# more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Curtin. If not, see <http://www.gnu.org/licenses/>. + +# Mini six like module (so that this code can be more easily extracted). + +import sys + +PY26 = sys.version_info[0:2] == (2, 6) +PY27 = sys.version_info[0:2] == (2, 7) +PY2 = PY26 or PY27 +PY3 = sys.version_info[0:2] >= (3, 0) + +if PY3: + text_type = str + binary_type = bytes + string_types = (text_type, text_type) + import io + StringIO = io.StringIO +else: + text_type = unicode + binary_type = bytes + string_types = (binary_type, text_type) + from StringIO import StringIO # noqa + + +# Taken from six (remove when we can actually directly use six) + +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) + return metaclass(cls.__name__, cls.__bases__, orig_vars) + return wrapper |