<s> """<STR_LIT>""" <EOL> import os <EOL> import time <EOL> from django . conf import global_settings <EOL> ENVIRONMENT_VARIABLE = "<STR_LIT>" <EOL> class LazySettings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _target = None <EOL> def __getattr__ ( self , name ) : <EOL> if self . _target is None : <EOL> self . _import_settings ( ) <EOL> if name == '<STR_LIT>' : <EOL> return self . _target . get_all_members ( ) <EOL> return getattr ( self . _target , name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> if name == '<STR_LIT>' : <EOL> self . __dict__ [ '<STR_LIT>' ] = value <EOL> else : <EOL> if self . _target is None : <EOL> self . _import_settings ( ) <EOL> setattr ( self . _target , name , value ) <EOL> def _import_settings ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> settings_module = os . environ [ ENVIRONMENT_VARIABLE ] <EOL> if not settings_module : <EOL> raise KeyError <EOL> except KeyError : <EOL> raise ImportError ( "<STR_LIT>" % ENVIRONMENT_VARIABLE ) <EOL> self . _target = Settings ( settings_module ) <EOL> def configure ( self , default_settings = global_settings , ** options ) : <EOL> """<STR_LIT>""" <EOL> if self . _target != None : <EOL> raise RuntimeError , '<STR_LIT>' <EOL> holder = UserSettingsHolder ( default_settings ) <EOL> for name , value in options . items ( ) : <EOL> setattr ( holder , name , value ) <EOL> self . _target = holder <EOL> def configured ( self ) : <EOL> """<STR_LIT>""" <EOL> return bool ( self . _target ) <EOL> configured = property ( configured ) <EOL> class Settings ( object ) : <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 = __import__ ( self . SETTINGS_MODULE , { } , { } , [ '<STR_LIT>' ] ) <EOL> except ImportError , 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 type ( setting_value ) == str : <EOL> setting_value = ( setting_value , ) <EOL> setattr ( self , setting , setting_value ) <EOL> new_installed_apps = [ ] <EOL> for app in self . INSTALLED_APPS : <EOL> if app . endswith ( '<STR_LIT>' ) : <EOL> appdir = os . path . dirname ( __import__ ( app [ : - <NUM_LIT:2> ] , { } , { } , [ '<STR_LIT>' ] ) . __file__ ) <EOL> app_subdirs = os . listdir ( appdir ) <EOL> app_subdirs . sort ( ) <EOL> for d in app_subdirs : <EOL> if d . isalpha ( ) and os . path . isdir ( os . path . join ( appdir , d ) ) : <EOL> new_installed_apps . append ( '<STR_LIT>' % ( app [ : - <NUM_LIT:2> ] , d ) ) <EOL> else : <EOL> new_installed_apps . append ( app ) <EOL> self . INSTALLED_APPS = new_installed_apps <EOL> if hasattr ( time , '<STR_LIT>' ) : <EOL> os . environ [ '<STR_LIT>' ] = self . TIME_ZONE <EOL> time . tzset ( ) <EOL> def get_all_members ( self ) : <EOL> return dir ( self ) <EOL> class UserSettingsHolder ( object ) : <EOL> """<STR_LIT>""" <EOL> SETTINGS_MODULE = None <EOL> def __init__ ( self , default_settings ) : <EOL> """<STR_LIT>""" <EOL> self . default_settings = default_settings <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . default_settings , name ) <EOL> def get_all_members ( self ) : <EOL> return dir ( self ) + dir ( self . default_settings ) <EOL> settings = LazySettings ( ) </s>
