<s> """<STR_LIT>""" <EOL> import json <EOL> import logging <EOL> import os <EOL> import re <EOL> import sys <EOL> import warnings <EOL> try : <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> except ImportError : <EOL> class ImproperlyConfigured ( Exception ) : <EOL> pass <EOL> from six . moves import urllib_parse as urlparse <EOL> from six import string_types <EOL> logger = logging . getLogger ( __name__ ) <EOL> VERSION = '<STR_LIT>' <EOL> __author__ = '<STR_LIT>' <EOL> __version__ = tuple ( VERSION . split ( '<STR_LIT:.>' ) ) <EOL> def _cast_int ( v ) : <EOL> return int ( v ) if hasattr ( v , '<STR_LIT>' ) and v . isdigit ( ) else v <EOL> DJANGO_REDIS_DRIVER = '<STR_LIT>' <EOL> DJANGO_REDIS_CACHE_DRIVER = '<STR_LIT>' <EOL> REDIS_DRIVER = DJANGO_REDIS_DRIVER <EOL> try : <EOL> import redis_cache <EOL> REDIS_DRIVER = DJANGO_REDIS_CACHE_DRIVER <EOL> except : <EOL> pass <EOL> class NoValue ( object ) : <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . __class__ . __name__ ) <EOL> class Env ( object ) : <EOL> """<STR_LIT>""" <EOL> ENVIRON = os . environ <EOL> NOTSET = NoValue ( ) <EOL> BOOLEAN_TRUE_STRINGS = ( '<STR_LIT:true>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:y>' , '<STR_LIT:yes>' , '<STR_LIT:1>' ) <EOL> URL_CLASS = urlparse . ParseResult <EOL> DEFAULT_DATABASE_ENV = '<STR_LIT>' <EOL> DB_SCHEMES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _DB_BASE_OPTIONS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> DEFAULT_CACHE_ENV = '<STR_LIT>' <EOL> CACHE_SCHEMES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : REDIS_DRIVER , <EOL> '<STR_LIT>' : REDIS_DRIVER , <EOL> } <EOL> _CACHE_BASE_OPTIONS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> DEFAULT_EMAIL_ENV = '<STR_LIT>' <EOL> EMAIL_SCHEMES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> _EMAIL_BASE_OPTIONS = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> DEFAULT_SEARCH_ENV = '<STR_LIT>' <EOL> SEARCH_SCHEMES = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> def __init__ ( self , ** scheme ) : <EOL> self . scheme = scheme <EOL> def __call__ ( self , var , cast = None , default = NOTSET , parse_default = False ) : <EOL> return self . get_value ( var , cast = cast , default = default , parse_default = parse_default ) <EOL> def str ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , default = default ) <EOL> def unicode ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = str , default = default ) <EOL> def bool ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = bool , default = default ) <EOL> def int ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = int , default = default ) <EOL> def float ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = float , default = default ) <EOL> def json ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = json . loads , default = default ) <EOL> def list ( self , var , cast = None , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = list if not cast else [ cast ] , default = default ) <EOL> def tuple ( self , var , cast = None , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = tuple if not cast else ( cast , ) , default = default ) <EOL> def dict ( self , var , cast = dict , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = cast , default = default ) <EOL> def url ( self , var , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . get_value ( var , cast = urlparse . urlparse , default = default , parse_default = True ) <EOL> def db_url ( self , var = DEFAULT_DATABASE_ENV , default = NOTSET , engine = None ) : <EOL> """<STR_LIT>""" <EOL> return self . db_url_config ( self . get_value ( var , default = default ) , engine = engine ) <EOL> db = db_url <EOL> def cache_url ( self , var = DEFAULT_CACHE_ENV , default = NOTSET , backend = None ) : <EOL> """<STR_LIT>""" <EOL> return self . cache_url_config ( self . url ( var , default = default ) , backend = backend ) <EOL> cache = cache_url <EOL> def email_url ( self , var = DEFAULT_EMAIL_ENV , default = NOTSET , backend = None ) : <EOL> """<STR_LIT>""" <EOL> return self . email_url_config ( self . url ( var , default = default ) , backend = backend ) <EOL> email = email_url <EOL> def search_url ( self , var = DEFAULT_SEARCH_ENV , default = NOTSET , engine = None ) : <EOL> """<STR_LIT>""" <EOL> return self . search_url_config ( self . url ( var , default = default ) , engine = engine ) <EOL> def path ( self , var , default = NOTSET , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Path ( self . get_value ( var , default = default ) , ** kwargs ) <EOL> def get_value ( self , var , cast = None , default = NOTSET , parse_default = False ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" . format ( <EOL> var , cast , default <EOL> ) ) <EOL> if var in self . scheme : <EOL> var_info = self . scheme [ var ] <EOL> try : <EOL> has_default = len ( var_info ) == <NUM_LIT:2> <EOL> except TypeError : <EOL> has_default = False <EOL> if has_default : <EOL> if not cast : <EOL> cast = var_info [ <NUM_LIT:0> ] <EOL> if default is self . NOTSET : <EOL> try : <EOL> default = var_info [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> pass <EOL> else : <EOL> if not cast : <EOL> cast = var_info <EOL> try : <EOL> value = self . ENVIRON [ var ] <EOL> except KeyError : <EOL> if default is self . NOTSET : <EOL> error_msg = "<STR_LIT>" . format ( var ) <EOL> raise ImproperlyConfigured ( error_msg ) <EOL> value = default <EOL> if hasattr ( value , '<STR_LIT>' ) and value . startswith ( '<STR_LIT:$>' ) : <EOL> value = value . lstrip ( '<STR_LIT:$>' ) <EOL> value = self . get_value ( value , cast = cast , default = default ) <EOL> if value != default or ( parse_default and value ) : <EOL> value = self . parse_value ( value , cast ) <EOL> return value <EOL> @ classmethod <EOL> def parse_value ( cls , value , cast ) : <EOL> """<STR_LIT>""" <EOL> if cast is None : <EOL> return value <EOL> elif cast is bool : <EOL> try : <EOL> value = int ( value ) != <NUM_LIT:0> <EOL> except ValueError : <EOL> value = value . lower ( ) in cls . BOOLEAN_TRUE_STRINGS <EOL> elif isinstance ( cast , list ) : <EOL> value = list ( map ( cast [ <NUM_LIT:0> ] , [ x for x in value . split ( '<STR_LIT:U+002C>' ) if x ] ) ) <EOL> elif isinstance ( cast , tuple ) : <EOL> val = value . strip ( '<STR_LIT:(>' ) . strip ( '<STR_LIT:)>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> value = tuple ( map ( cast [ <NUM_LIT:0> ] , [ x for x in val if x ] ) ) <EOL> elif isinstance ( cast , dict ) : <EOL> key_cast = cast . get ( '<STR_LIT:key>' , str ) <EOL> value_cast = cast . get ( '<STR_LIT:value>' , str ) <EOL> value_cast_by_key = cast . get ( '<STR_LIT>' , dict ( ) ) <EOL> value = dict ( map ( <EOL> lambda kv : ( <EOL> key_cast ( kv [ <NUM_LIT:0> ] ) , <EOL> cls . parse_value ( kv [ <NUM_LIT:1> ] , value_cast_by_key . get ( kv [ <NUM_LIT:0> ] , value_cast ) ) <EOL> ) , <EOL> [ val . split ( '<STR_LIT:=>' ) for val in value . split ( '<STR_LIT:;>' ) if val ] <EOL> ) ) <EOL> elif cast is dict : <EOL> value = dict ( [ val . split ( '<STR_LIT:=>' ) for val in value . split ( '<STR_LIT:U+002C>' ) if val ] ) <EOL> elif cast is list : <EOL> value = [ x for x in value . split ( '<STR_LIT:U+002C>' ) if x ] <EOL> elif cast is tuple : <EOL> val = value . strip ( '<STR_LIT:(>' ) . strip ( '<STR_LIT:)>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> value = tuple ( [ x for x in val if x ] ) <EOL> elif cast is float : <EOL> float_str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , value ) <EOL> parts = re . split ( r'<STR_LIT>' , float_str ) <EOL> if len ( parts ) == <NUM_LIT:1> : <EOL> float_str = parts [ <NUM_LIT:0> ] <EOL> else : <EOL> float_str = "<STR_LIT>" . format ( '<STR_LIT>' . join ( parts [ <NUM_LIT:0> : - <NUM_LIT:1> ] ) , parts [ - <NUM_LIT:1> ] ) <EOL> value = float ( float_str ) <EOL> else : <EOL> value = cast ( value ) <EOL> return value <EOL> @ classmethod <EOL> def db_url_config ( cls , url , engine = None ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( url , cls . URL_CLASS ) : <EOL> if url == '<STR_LIT>' : <EOL> return { <EOL> '<STR_LIT>' : cls . DB_SCHEMES [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> url = urlparse . urlparse ( url ) <EOL> config = { } <EOL> path = url . path [ <NUM_LIT:1> : ] <EOL> path = path . split ( '<STR_LIT:?>' , <NUM_LIT:2> ) [ <NUM_LIT:0> ] <EOL> if url . scheme == '<STR_LIT>' and path == '<STR_LIT>' : <EOL> path = '<STR_LIT>' <EOL> if url . scheme == '<STR_LIT>' : <EOL> path = '<STR_LIT>' . format ( scheme = url . scheme , hostname = url . hostname ) <EOL> if url . port : <EOL> path += '<STR_LIT>' . format ( port = url . port ) <EOL> config . update ( { <EOL> '<STR_LIT>' : path or '<STR_LIT>' , <EOL> '<STR_LIT>' : url . username or '<STR_LIT>' , <EOL> '<STR_LIT>' : url . password or '<STR_LIT>' , <EOL> '<STR_LIT>' : url . hostname or '<STR_LIT>' , <EOL> '<STR_LIT>' : _cast_int ( url . port ) or '<STR_LIT>' , <EOL> } ) <EOL> if url . scheme == '<STR_LIT>' and path == '<STR_LIT>' : <EOL> config [ '<STR_LIT>' ] = config [ '<STR_LIT>' ] <EOL> config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if url . scheme == '<STR_LIT>' and not config [ '<STR_LIT>' ] : <EOL> del ( config [ '<STR_LIT>' ] ) <EOL> if url . query : <EOL> config_options = { } <EOL> for k , v in urlparse . parse_qs ( url . query ) . items ( ) : <EOL> if k . upper ( ) in cls . _DB_BASE_OPTIONS : <EOL> config . update ( { k . upper ( ) : _cast_int ( v [ <NUM_LIT:0> ] ) } ) <EOL> else : <EOL> config_options . update ( { k : _cast_int ( v [ <NUM_LIT:0> ] ) } ) <EOL> config [ '<STR_LIT>' ] = config_options <EOL> if engine : <EOL> config [ '<STR_LIT>' ] = engine <EOL> if url . scheme in Env . DB_SCHEMES : <EOL> config [ '<STR_LIT>' ] = Env . DB_SCHEMES [ url . scheme ] <EOL> if not config . get ( '<STR_LIT>' , False ) : <EOL> warnings . warn ( "<STR_LIT>" . format ( config ) ) <EOL> return { } <EOL> return config <EOL> @ classmethod <EOL> def cache_url_config ( cls , url , backend = None ) : <EOL> """<STR_LIT>""" <EOL> url = urlparse . urlparse ( url ) if not isinstance ( url , cls . URL_CLASS ) else url <EOL> location = url . netloc . split ( '<STR_LIT:U+002C>' ) <EOL> if len ( location ) == <NUM_LIT:1> : <EOL> location = location [ <NUM_LIT:0> ] <EOL> config = { <EOL> '<STR_LIT>' : cls . CACHE_SCHEMES [ url . scheme ] , <EOL> '<STR_LIT>' : location , <EOL> } <EOL> if url . scheme == '<STR_LIT>' : <EOL> config . update ( { <EOL> '<STR_LIT>' : url . netloc + url . path , <EOL> } ) <EOL> if url . path and url . scheme in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> config . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' + url . path , <EOL> } ) <EOL> elif url . scheme . startswith ( '<STR_LIT>' ) : <EOL> if url . hostname : <EOL> scheme = url . scheme . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> scheme = '<STR_LIT>' <EOL> config [ '<STR_LIT>' ] = scheme + '<STR_LIT>' + url . netloc + url . path <EOL> if url . query : <EOL> config_options = { } <EOL> for k , v in urlparse . parse_qs ( url . query ) . items ( ) : <EOL> opt = { k . upper ( ) : _cast_int ( v [ <NUM_LIT:0> ] ) } <EOL> if k . upper ( ) in cls . _CACHE_BASE_OPTIONS : <EOL> config . update ( opt ) <EOL> else : <EOL> config_options . update ( opt ) <EOL> config [ '<STR_LIT>' ] = config_options <EOL> if backend : <EOL> config [ '<STR_LIT>' ] = backend <EOL> return config <EOL> @ classmethod <EOL> def email_url_config ( cls , url , backend = None ) : <EOL> """<STR_LIT>""" <EOL> config = { } <EOL> url = urlparse . urlparse ( url ) if not isinstance ( url , cls . URL_CLASS ) else url <EOL> path = url . path [ <NUM_LIT:1> : ] <EOL> path = path . split ( '<STR_LIT:?>' , <NUM_LIT:2> ) [ <NUM_LIT:0> ] <EOL> config . update ( { <EOL> '<STR_LIT>' : path , <EOL> '<STR_LIT>' : url . username , <EOL> '<STR_LIT>' : url . password , <EOL> '<STR_LIT>' : url . hostname , <EOL> '<STR_LIT>' : _cast_int ( url . port ) , <EOL> } ) <EOL> if backend : <EOL> config [ '<STR_LIT>' ] = backend <EOL> elif url . scheme not in cls . EMAIL_SCHEMES : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % url . scheme ) <EOL> elif url . scheme in cls . EMAIL_SCHEMES : <EOL> config [ '<STR_LIT>' ] = cls . EMAIL_SCHEMES [ url . scheme ] <EOL> if url . scheme in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> config [ '<STR_LIT>' ] = True <EOL> elif url . scheme == '<STR_LIT>' : <EOL> config [ '<STR_LIT>' ] = True <EOL> if url . query : <EOL> config_options = { } <EOL> for k , v in urlparse . parse_qs ( url . query ) . items ( ) : <EOL> opt = { k . upper ( ) : _cast_int ( v [ <NUM_LIT:0> ] ) } <EOL> if k . upper ( ) in cls . _EMAIL_BASE_OPTIONS : <EOL> config . update ( opt ) <EOL> else : <EOL> config_options . update ( opt ) <EOL> config [ '<STR_LIT>' ] = config_options <EOL> return config <EOL> @ classmethod <EOL> def search_url_config ( cls , url , engine = None ) : <EOL> config = { } <EOL> url = urlparse . urlparse ( url ) if not isinstance ( url , cls . URL_CLASS ) else url <EOL> path = url . path [ <NUM_LIT:1> : ] <EOL> path = path . split ( '<STR_LIT:?>' , <NUM_LIT:2> ) [ <NUM_LIT:0> ] <EOL> if url . scheme not in cls . SEARCH_SCHEMES : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % url . scheme ) <EOL> config [ "<STR_LIT>" ] = cls . SEARCH_SCHEMES [ url . scheme ] <EOL> params = { } <EOL> if url . query : <EOL> params = urlparse . parse_qs ( url . query ) <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+002C>' ) <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = cls . parse_value ( params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , bool ) <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = cls . parse_value ( params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , int ) <EOL> if url . scheme == '<STR_LIT>' : <EOL> return config <EOL> elif url . scheme in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> if path . endswith ( "<STR_LIT:/>" ) : <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> if url . scheme == '<STR_LIT>' : <EOL> config [ '<STR_LIT>' ] = urlparse . urlunparse ( ( '<STR_LIT:http>' , ) + url [ <NUM_LIT:1> : <NUM_LIT:2> ] + ( path , ) + ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = cls . parse_value ( params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , int ) <EOL> return config <EOL> if url . scheme == '<STR_LIT>' : <EOL> split = path . rsplit ( "<STR_LIT:/>" , <NUM_LIT:1> ) <EOL> if len ( split ) > <NUM_LIT:1> : <EOL> path = "<STR_LIT:/>" . join ( split [ : - <NUM_LIT:1> ] ) <EOL> index = split [ - <NUM_LIT:1> ] <EOL> else : <EOL> path = "<STR_LIT>" <EOL> index = split [ <NUM_LIT:0> ] <EOL> config [ '<STR_LIT>' ] = urlparse . urlunparse ( ( '<STR_LIT:http>' , ) + url [ <NUM_LIT:1> : <NUM_LIT:2> ] + ( path , ) + ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = cls . parse_value ( params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , int ) <EOL> config [ '<STR_LIT>' ] = index <EOL> return config <EOL> config [ '<STR_LIT>' ] = '<STR_LIT:/>' + path <EOL> if url . scheme == '<STR_LIT>' : <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = cls . parse_value ( params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , int ) <EOL> elif url . scheme == '<STR_LIT>' : <EOL> if '<STR_LIT>' in params . keys ( ) : <EOL> config [ '<STR_LIT>' ] = params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> if engine : <EOL> config [ '<STR_LIT>' ] = engine <EOL> return config <EOL> @ classmethod <EOL> def read_env ( cls , env_file = None , ** overrides ) : <EOL> """<STR_LIT>""" <EOL> if env_file is None : <EOL> frame = sys . _getframe ( ) <EOL> env_file = os . path . join ( os . path . dirname ( frame . f_back . f_code . co_filename ) , '<STR_LIT>' ) <EOL> if not os . path . exists ( env_file ) : <EOL> warnings . warn ( "<STR_LIT>" % env_file ) <EOL> return <EOL> try : <EOL> with open ( env_file ) if isinstance ( env_file , string_types ) else env_file as f : <EOL> content = f . read ( ) <EOL> except IOError : <EOL> warnings . warn ( "<STR_LIT>" % env_file ) <EOL> return <EOL> logger . debug ( '<STR_LIT>' . format ( env_file ) ) <EOL> for line in content . splitlines ( ) : <EOL> m1 = re . match ( r'<STR_LIT>' , line ) <EOL> if m1 : <EOL> key , val = m1 . group ( <NUM_LIT:1> ) , m1 . group ( <NUM_LIT:2> ) <EOL> m2 = re . match ( r"<STR_LIT>" , val ) <EOL> if m2 : <EOL> val = m2 . group ( <NUM_LIT:1> ) <EOL> m3 = re . match ( r'<STR_LIT>' , val ) <EOL> if m3 : <EOL> val = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , m3 . group ( <NUM_LIT:1> ) ) <EOL> cls . ENVIRON . setdefault ( key , str ( val ) ) <EOL> for key , value in overrides . items ( ) : <EOL> cls . ENVIRON . setdefault ( key , value ) <EOL> class Path ( object ) : <EOL> """<STR_LIT>""" <EOL> def path ( self , * paths , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . __class__ ( self . __root__ , * paths , ** kwargs ) <EOL> def file ( self , name , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return open ( self ( name ) , * args , ** kwargs ) <EOL> @ property <EOL> def root ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __root__ <EOL> def __init__ ( self , start = '<STR_LIT>' , * paths , ** kwargs ) : <EOL> super ( Path , self ) . __init__ ( ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) : <EOL> start = os . path . dirname ( start ) <EOL> self . __root__ = self . _absolute_join ( start , * paths , ** kwargs ) <EOL> def __call__ ( self , * paths , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _absolute_join ( self . __root__ , * paths , ** kwargs ) <EOL> def __eq__ ( self , other ) : <EOL> return self . __root__ == other . __root__ <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def __add__ ( self , other ) : <EOL> return Path ( self . __root__ , other if not isinstance ( other , Path ) else other . __root__ ) <EOL> def __sub__ ( self , other ) : <EOL> if isinstance ( other , int ) : <EOL> return self . path ( '<STR_LIT>' * other ) <EOL> elif isinstance ( other , string_types ) : <EOL> return Path ( self . __root__ . rstrip ( other ) ) <EOL> raise TypeError ( <EOL> "<STR_LIT>" . format ( self , type ( other ) ) ) <EOL> def __invert__ ( self ) : <EOL> return self . path ( '<STR_LIT:..>' ) <EOL> def __contains__ ( self , item ) : <EOL> base_path = self . __root__ <EOL> if len ( base_path ) > <NUM_LIT:1> : <EOL> base_path = os . path . join ( base_path , '<STR_LIT>' ) <EOL> return item . __root__ . startswith ( base_path ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . __root__ ) <EOL> def __str__ ( self ) : <EOL> return self . __root__ <EOL> def __unicode__ ( self ) : <EOL> return self . __str__ ( ) <EOL> def __getitem__ ( self , * args , ** kwargs ) : <EOL> return self . __str__ ( ) . __getitem__ ( * args , ** kwargs ) <EOL> def rfind ( self , * args , ** kwargs ) : <EOL> return self . __str__ ( ) . rfind ( * args , ** kwargs ) <EOL> def find ( self , * args , ** kwargs ) : <EOL> return self . __str__ ( ) . find ( * args , ** kwargs ) <EOL> @ staticmethod <EOL> def _absolute_join ( base , * paths , ** kwargs ) : <EOL> absolute_path = os . path . abspath ( os . path . join ( base , * paths ) ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) and not os . path . exists ( absolute_path ) : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" . format ( absolute_path ) ) <EOL> return absolute_path <EOL> def register_scheme ( scheme ) : <EOL> for method in dir ( urlparse ) : <EOL> if method . startswith ( '<STR_LIT>' ) : <EOL> getattr ( urlparse , method ) . append ( scheme ) <EOL> def register_schemes ( schemes ) : <EOL> for scheme in schemes : <EOL> register_scheme ( scheme ) <EOL> register_schemes ( Env . DB_SCHEMES . keys ( ) ) <EOL> register_schemes ( Env . CACHE_SCHEMES . keys ( ) ) <EOL> register_schemes ( Env . SEARCH_SCHEMES . keys ( ) ) <EOL> register_schemes ( Env . EMAIL_SCHEMES . keys ( ) ) </s>
