Update automatic registration to work with Python 3
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 15 Jan 2020 16:00:59 +0000 (17:00 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 15 Jan 2020 16:09:06 +0000 (17:09 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
src/ddns/providers.py

index eb66054..d0c01e7 100644 (file)
@@ -73,24 +73,6 @@ class DDNSProvider(object):
        # Required to remove AAAA records if IPv6 is absent again.
        can_remove_records = True
 
-       # Automatically register all providers.
-       class __metaclass__(type):
-               def __init__(provider, name, bases, dict):
-                       type.__init__(provider, name, bases, dict)
-
-                       # The main class from which is inherited is not registered
-                       # as a provider.
-                       if name == "DDNSProvider":
-                               return
-
-                       if not all((provider.handle, provider.name, provider.website)):
-                               raise DDNSError(_("Provider is not properly configured"))
-
-                       assert provider.handle not in _providers, \
-                               "Provider '%s' has already been registered" % provider.handle
-
-                       _providers[provider.handle] = provider
-
        @staticmethod
        def supported():
                """
@@ -107,6 +89,18 @@ class DDNSProvider(object):
                self.settings = self.DEFAULT_SETTINGS.copy()
                self.settings.update(settings)
 
+       def __init_subclass__(cls, **kwargs):
+               super().__init_subclass__(**kwargs)
+
+               if not all((cls.handle, cls.name, cls.website)):
+                       raise DDNSError(_("Provider is not properly configured"))
+
+               assert cls.handle not in _providers, \
+                       "Provider '%s' has already been registered" % cls.handle
+
+               # Register class
+               _providers[cls.handle] = cls
+
        def __repr__(self):
                return "<DDNS Provider %s (%s)>" % (self.name, self.handle)