<s> """<STR_LIT>""" <EOL> from cgi import parse_qsl <EOL> from django . conf import settings <EOL> from django . core import signals <EOL> from django . core . cache . backends . base import InvalidCacheBackendError <EOL> from django . utils import importlib <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> 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> def get_cache ( backend_uri ) : <EOL> scheme , host , params = parse_backend_uri ( backend_uri ) <EOL> if scheme in BACKENDS : <EOL> name = '<STR_LIT>' % BACKENDS [ scheme ] <EOL> else : <EOL> name = scheme <EOL> module = importlib . import_module ( name ) <EOL> return getattr ( module , '<STR_LIT>' ) ( host , params ) <EOL> cache = get_cache ( settings . CACHE_BACKEND ) <EOL> if hasattr ( cache , '<STR_LIT>' ) : <EOL> signals . request_finished . connect ( cache . close ) </s>
