-
-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9464ca
commit 836f6be
Showing
16 changed files
with
20 additions
and
1,031 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +0,0 @@ | ||
from django.utils.module_loading import import_string | ||
|
||
|
||
class InvalidChannelBackendError(ValueError): | ||
pass | ||
|
||
|
||
class BackendManager(object): | ||
""" | ||
Takes a settings dictionary of backends and initialises them. | ||
""" | ||
|
||
def __init__(self, backend_configs): | ||
self.configs = backend_configs | ||
self.backends = {} | ||
|
||
def make_backend(self, name): | ||
# Load the backend class | ||
try: | ||
backend_class = import_string(self.configs[name]['BACKEND']) | ||
except KeyError: | ||
raise InvalidChannelBackendError("No BACKEND specified for %s" % name) | ||
except ImportError: | ||
raise InvalidChannelBackendError( | ||
"Cannot import BACKEND %r specified for %s" % (self.configs[name]['BACKEND'], name) | ||
) | ||
|
||
# Initialise and pass config | ||
instance = backend_class(**{k.lower(): v for k, v in self.configs[name].items() if k != "BACKEND"}) | ||
instance.alias = name | ||
return instance | ||
|
||
def __getitem__(self, key): | ||
if key not in self.backends: | ||
self.backends[key] = self.make_backend(key) | ||
return self.backends[key] | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.