[PATCH] Work around an old version of python-six.

David Lehman dlehman at redhat.com
Wed Sep 3 20:31:20 UTC 2014


Related: rhbz#1075561
---
 blivet/devices.py |  2 +-
 blivet/size.py    |  4 ++--
 blivet/util.py    | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/blivet/devices.py b/blivet/devices.py
index a0f8f56..5ff9f4a 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -28,7 +28,7 @@ import abc
 from decimal import Decimal
 import re
 
-from six import add_metaclass
+from util import add_metaclass
 
 # device backend modules
 from .devicelibs import mdraid
diff --git a/blivet/size.py b/blivet/size.py
index b9f0089..2f4250f 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -135,7 +135,7 @@ def _parseSpec(spec):
     try:
         # This will raise UnicodeDecodeError if specifier contains non-ascii
         # characters
-        if six.PY2:
+        if not six.PY3:
             spec_ascii = specifier.decode("ascii")
             # Convert back to a str type to match the _bytes and _prefixes arrays
             spec_ascii = str(spec_ascii)
@@ -163,7 +163,7 @@ def _parseSpec(spec):
 
     # No English match found, try localized size specs. Accept any utf-8
     # character and leave the result as a (unicode object.
-    if six.PY2:
+    if not six.PY3:
         spec_local = specifier.decode("utf-8")
     else:
         # str = unicode in Python3
diff --git a/blivet/util.py b/blivet/util.py
index 1e28ddc..2dceed9 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -438,3 +438,20 @@ def variable_copy(obj, memo, omit=None, shallow=None, duplicate=None):
             setattr(new, attr, copy.deepcopy(value, memo))
 
     return new
+
+# Borrowed from python-six-1.6.1 for use in an environment which only has
+# python-six-1.3.0, which does not provide add_metaclass.
+def add_metaclass(metaclass):
+    """Class decorator for creating a class with a metaclass."""
+    def wrapper(cls):
+        orig_vars = cls.__dict__.copy()
+        orig_vars.pop('__dict__', None)
+        orig_vars.pop('__weakref__', None)
+        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)
+        return metaclass(cls.__name__, cls.__bases__, orig_vars)
+    return wrapper
-- 
1.9.3



More information about the anaconda-patches mailing list