From: Mark Wooding Date: Mon, 21 Oct 2019 17:17:21 +0000 (+0100) Subject: catacomb/pwsafe.py: Hack around the change in metaclass syntax. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/b1f8a1a1b30987f472b67bf3a10bc6b1ab4170a1 catacomb/pwsafe.py: Hack around the change in metaclass syntax. Python 2 (all versions) want you to set `__metaclass__' within the class body. Python 3 ignores this, treating it like an ordinary class attribute, and wants you to say `metaclass = ...' in the direct- superclass list; but the latter is a syntax error to Python 2. Instead, add a hack which constructs a anonymous class with the right metaclass to use as a direct superclass. It's awful, but it works. --- diff --git a/catacomb/pwsafe.py b/catacomb/pwsafe.py index 7951e0a..5e296e3 100644 --- a/catacomb/pwsafe.py +++ b/catacomb/pwsafe.py @@ -48,6 +48,10 @@ _NUL = _bin('\0') _CIPHER = _bin('cipher:') _MAC = _bin('mac:') +def _with_metaclass(meta, *supers): + return meta("#" % meta.__name__, + supers or (object,), dict()) + def _excval(): return SYS.exc_info()[1] _M600 = int("600", 8) @@ -235,7 +239,7 @@ class StorageBackendClass (type): except AttributeError: pass else: StorageBackend.register_concrete_subclass(me) -class StorageBackend (object): +class StorageBackend (_with_metaclass(StorageBackendClass)): """ I provide basic protocol for password storage backends. @@ -303,7 +307,6 @@ class StorageBackend (object): priority order when opening an existing database. """ - __metaclass__ = StorageBackendClass PRIO = 10 ## The registry of subclasses.