<s> """<STR_LIT>""" <EOL> try : <EOL> from urllib . parse import parse_qsl <EOL> except ImportError : <EOL> from urlparse import parse_qsl <EOL> from django . conf import settings <EOL> from django . core import signals <EOL> from django . core . cache . backends . base import ( <EOL> InvalidCacheBackendError , CacheKeyWarning , BaseCache ) <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . utils import importlib <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> BACKENDS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:file>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> DEFAULT_CACHE_ALIAS = '<STR_LIT:default>' <EOL> def parse_backend_uri ( backend_uri ) : <EOL> """<STR_LIT>""" <EOL> if backend_uri . find ( '<STR_LIT::>' ) == - <NUM_LIT:1> : <EOL> raise InvalidCacheBackendError ( "<STR_LIT>" ) <EOL> scheme , rest = backend_uri . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if not rest . startswith ( '<STR_LIT>' ) : <EOL> raise InvalidCacheBackendError ( "<STR_LIT>" ) <EOL> host = rest [ <NUM_LIT:2> : ] <EOL> qpos = rest . find ( '<STR_LIT:?>' ) <EOL> if qpos != - <NUM_LIT:1> : <EOL> params = dict ( parse_qsl ( rest [ qpos + <NUM_LIT:1> : ] ) ) <EOL> host = rest [ <NUM_LIT:2> : qpos ] <EOL> else : <EOL> params = { } <EOL> if host . endswith ( '<STR_LIT:/>' ) : <EOL> host = host [ : - <NUM_LIT:1> ] <EOL> return scheme , host , params <EOL> if DEFAULT_CACHE_ALIAS not in settings . CACHES : <EOL> raise ImproperlyConfigured ( "<STR_LIT>" % DEFAULT_CACHE_ALIAS ) <EOL> def parse_backend_conf ( backend , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> conf = settings . CACHES . get ( backend , None ) <EOL> if conf is not None : <EOL> args = conf . copy ( ) <EOL> args . update ( kwargs ) <EOL> backend = args . pop ( '<STR_LIT>' ) <EOL> location = args . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return backend , location , args <EOL> else : <EOL> try : <EOL> mod_path , cls_name = backend . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> mod = importlib . import_module ( mod_path ) <EOL> backend_cls = getattr ( mod , cls_name ) <EOL> except ( AttributeError , ImportError , ValueError ) : <EOL> raise InvalidCacheBackendError ( "<STR_LIT>" % backend ) <EOL> location = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return backend , location , kwargs <EOL> def get_cache ( backend , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if '<STR_LIT>' in backend : <EOL> backend , location , params = parse_backend_uri ( backend ) <EOL> if backend in BACKENDS : <EOL> backend = '<STR_LIT>' % BACKENDS [ backend ] <EOL> params . update ( kwargs ) <EOL> mod = importlib . import_module ( backend ) <EOL> backend_cls = mod . CacheClass <EOL> else : <EOL> backend , location , params = parse_backend_conf ( backend , ** kwargs ) <EOL> mod_path , cls_name = backend . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> mod = importlib . import_module ( mod_path ) <EOL> backend_cls = getattr ( mod , cls_name ) <EOL> except ( AttributeError , ImportError ) as e : <EOL> raise InvalidCacheBackendError ( <EOL> "<STR_LIT>" % ( backend , e ) ) <EOL> cache = backend_cls ( location , params ) <EOL> if hasattr ( cache , '<STR_LIT>' ) : <EOL> signals . request_finished . connect ( cache . close ) <EOL> return cache <EOL> cache = get_cache ( DEFAULT_CACHE_ALIAS ) </s>
