Skip to content

Commit

Permalink
Avoid double initialization of the backend class that Python can do w…
Browse files Browse the repository at this point in the history
…hen using an empty string in the from list.
  • Loading branch information
brosner committed Jan 7, 2009
1 parent 55502ce commit 81de973
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions notification/backends/__init__.py
@@ -1,4 +1,6 @@


import sys

from django.conf import settings from django.conf import settings
from django.core import exceptions from django.core import exceptions


Expand All @@ -7,13 +9,15 @@
def load_backends(): def load_backends():
backends = [] backends = []
for label, backend_path in getattr(settings, "NOTIFICATION_BACKENDS", tuple()): for label, backend_path in getattr(settings, "NOTIFICATION_BACKENDS", tuple()):
dot = backend_path.rindex('.') dot = backend_path.rindex(".")
backend_mod, backend_class = backend_path[:dot], backend_path[dot+1:] backend_mod, backend_class = backend_path[:dot], backend_path[dot+1:]
try: try:
mod = __import__(backend_mod, {}, {}, [""]) # import the module and get the module from sys.modules
__import__(backend_mod)
mod = sys.modules[backend_mod]
except ImportError, e: except ImportError, e:
raise exceptions.ImproperlyConfigured, 'Error importing notification backend %s: "%s"' % (backend_mod, e) raise exceptions.ImproperlyConfigured, 'Error importing notification backend %s: "%s"' % (backend_mod, e)
# add the backend label and an instantiated backend class to the # add the backend label and an instantiated backend class to the
# backends list. # backends list.
backends.append(label, getattr(backend_mod, "")()) backends.append(label, getattr(backend_mod, backend_class)())
return dict(backend_list) return dict(backend_list)

0 comments on commit 81de973

Please sign in to comment.