<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import time <EOL> import warnings <EOL> from django . conf import global_settings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . utils . functional import LazyObject , empty <EOL> from django . utils import importlib <EOL> from django . utils import six <EOL> ENVIRONMENT_VARIABLE = "<STR_LIT>" <EOL> class LazySettings ( LazyObject ) : <EOL> """<STR_LIT>""" <EOL> def _setup ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> settings_module = os . environ [ ENVIRONMENT_VARIABLE ] <EOL> if not settings_module : <EOL> raise KeyError <EOL> except KeyError : <EOL> desc = ( "<STR_LIT>" % name ) if name else "<STR_LIT>" <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( desc , ENVIRONMENT_VARIABLE ) ) <EOL> self . _wrapped = Settings ( settings_module ) <EOL> self . _configure_logging ( ) <EOL> def __getattr__ ( self , name ) : <EOL> if self . _wrapped is empty : <EOL> self . _setup ( name ) <EOL> return getattr ( self . _wrapped , name ) <EOL> def _configure_logging ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> logging . captureWarnings ( True ) <EOL> warnings . simplefilter ( "<STR_LIT:default>" , DeprecationWarning ) <EOL> except AttributeError : <EOL> pass <EOL> if self . LOGGING_CONFIG : <EOL> from django . utils . log import DEFAULT_LOGGING <EOL> logging_config_path , logging_config_func_name = self . LOGGING_CONFIG . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> logging_config_module = importlib . import_module ( logging_config_path ) <EOL> logging_config_func = getattr ( logging_config_module , logging_config_func_name ) <EOL> logging_config_func ( DEFAULT_LOGGING ) <EOL> if self . LOGGING : <EOL> compat_patch_logging_config ( self . LOGGING ) <EOL> logging_config_func ( self . LOGGING ) <EOL> def configure ( self , default_settings = global_settings , ** options ) : <EOL> """<STR_LIT>""" <EOL> if self . _wrapped is not empty : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> holder = UserSettingsHolder ( default_settings ) <EOL> for name , value in options . items ( ) : <EOL> setattr ( holder , name , value ) <EOL> self . _wrapped = holder <EOL> self . _configure_logging ( ) <EOL> @ property <EOL> def configured ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrapped is not empty <EOL> class BaseSettings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __setattr__ ( self , name , value ) : <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" ) and value and not value . endswith ( '<STR_LIT:/>' ) : <EOL> raise ImproperlyConfigured ( "<STR_LIT>" % name ) <EOL> elif name == "<STR_LIT>" and isinstance ( value , six . string_types ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> object . __setattr__ ( self , name , value ) <EOL> class Settings ( BaseSettings ) : <EOL> def __init__ ( self , settings_module ) : <EOL> for setting in dir ( global_settings ) : <EOL> if setting == setting . upper ( ) : <EOL> setattr ( self , setting , getattr ( global_settings , setting ) ) <EOL> self . SETTINGS_MODULE = settings_module <EOL> try : <EOL> mod = importlib . import_module ( self . SETTINGS_MODULE ) <EOL> except ImportError as e : <EOL> raise ImportError ( "<STR_LIT>" % ( self . SETTINGS_MODULE , e ) ) <EOL> tuple_settings = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> for setting in dir ( mod ) : <EOL> if setting == setting . upper ( ) : <EOL> setting_value = getattr ( mod , setting ) <EOL> if setting in tuple_settings and isinstance ( setting_value , six . string_types ) : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % setting , <EOL> PendingDeprecationWarning ) <EOL> setting_value = ( setting_value , ) <EOL> setattr ( self , setting , setting_value ) <EOL> if not self . SECRET_KEY : <EOL> raise ImproperlyConfigured ( "<STR_LIT>" ) <EOL> if hasattr ( time , '<STR_LIT>' ) and self . TIME_ZONE : <EOL> zoneinfo_root = '<STR_LIT>' <EOL> if ( os . path . exists ( zoneinfo_root ) and not <EOL> os . path . exists ( os . path . join ( zoneinfo_root , * ( self . TIME_ZONE . split ( '<STR_LIT:/>' ) ) ) ) ) : <EOL> raise ValueError ( "<STR_LIT>" % self . TIME_ZONE ) <EOL> os . environ [ '<STR_LIT>' ] = self . TIME_ZONE <EOL> time . tzset ( ) <EOL> class UserSettingsHolder ( BaseSettings ) : <EOL> """<STR_LIT>""" <EOL> SETTINGS_MODULE = None <EOL> def __init__ ( self , default_settings ) : <EOL> """<STR_LIT>""" <EOL> self . __dict__ [ '<STR_LIT>' ] = set ( ) <EOL> self . default_settings = default_settings <EOL> def __getattr__ ( self , name ) : <EOL> if name in self . _deleted : <EOL> raise AttributeError <EOL> return getattr ( self . default_settings , name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> self . _deleted . discard ( name ) <EOL> return super ( UserSettingsHolder , self ) . __setattr__ ( name , value ) <EOL> def __delattr__ ( self , name ) : <EOL> self . _deleted . add ( name ) <EOL> return super ( UserSettingsHolder , self ) . __delattr__ ( name ) <EOL> def __dir__ ( self ) : <EOL> return list ( self . __dict__ ) + dir ( self . default_settings ) <EOL> settings = LazySettings ( ) <EOL> def compat_patch_logging_config ( logging_config ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT>" not in logging_config . get ( <EOL> "<STR_LIT>" , { } ) . get ( <EOL> "<STR_LIT>" , { "<STR_LIT>" : [ ] } ) : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> DeprecationWarning ) <EOL> filter_name = "<STR_LIT>" <EOL> filters = logging_config . setdefault ( "<STR_LIT>" , { } ) <EOL> while filter_name in filters : <EOL> filter_name = filter_name + "<STR_LIT:_>" <EOL> filters [ filter_name ] = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> logging_config [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = [ filter_name ] </s>
