changeset 30:d4563cb0376c

Handle importing valid module name as backend when that module is NOT a backend.
author btimby
date Sun, 05 Feb 2012 03:28:19 +0000
parents 2b46eceda739
children 06f1c0a8557d
files queues/__init__.py queues/backends/__init__.py
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/queues/__init__.py	Sun Feb 05 03:10:46 2012 +0000
+++ b/queues/__init__.py	Sun Feb 05 03:28:19 2012 +0000
@@ -56,3 +56,8 @@
         queues = __import__(BACKEND, {}, {}, [''])
     except ImportError:
         raise InvalidBackend("Unable to import QUEUE BACKEND '%s'" % BACKEND)
+    # Check that this is really a queues backend, not just some other random
+    # module.
+    from .backends.base import BaseQueue
+    if not getattr(queues, 'Queue', None) in BaseQueue.__subclasses__():
+        raise InvalidBackend("Unable to import QUEUE_BACKEND '%s' does not appear to be valid." % BACKEND)
--- a/queues/backends/__init__.py	Sun Feb 05 03:10:46 2012 +0000
+++ b/queues/backends/__init__.py	Sun Feb 05 03:28:19 2012 +0000
@@ -25,3 +25,6 @@
         backend = __import__(BACKEND, {}, {}, [''])
     except ImportError:
         raise InvalidBackend("Unable to import QUEUE BACKEND '%s'" % BACKEND)
+    from .base import BaseQueue
+    if not getattr(backend, 'Queue', None) in BaseQueue.__subclasses__():
+        raise InvalidBackend("Unable to import QUEUE BACKEND '%s' does not appear to be valid." % BACKEND)