get_backend()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
c 3
b 0
f 0
dl 0
loc 20
rs 9.4285
1
# coding=utf-8
2
"""
3
"""
4
__author__ = 'Alisue <[email protected]>'
5
from roughpages.conf import settings
6
from roughpages.compat import import_module
7
8
9
def get_backend(backend_class=None):
10
    """
11
    Get backend instance
12
13
    If no `backend_class` is specified, the backend class is determined from
14
    the value of `settings.ROUGHPAGES_BACKEND`.
15
    `backend_class` can be a class object or dots separated python import path
16
17
    Returns:
18
        backend instance
19
    """
20
    cache_name = '_backend_instance'
21
    if not hasattr(get_backend, cache_name):
22
        backend_class = backend_class or settings.ROUGHPAGES_BACKEND
23
        if isinstance(backend_class, basestring):
24
            module_path, class_name = backend_class.rsplit(".", 1)
25
            module = import_module(module_path)
26
            backend_class = getattr(module, class_name)
27
        setattr(get_backend, cache_name, backend_class())
28
    return getattr(get_backend, cache_name)
29
30
31
from roughpages.backends.decorators import prepare_filename_decorator
32
from roughpages.backends.base import TemplateFilenameBackendBase
33
from roughpages.backends.plain import PlainTemplateFilenameBackend
34
from roughpages.backends.auth import AuthTemplateFilenameBackend
35