<s> """<STR_LIT>""" <EOL> from paste . registry import RegistryManager , StackedObjectProxy <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class DispatchingConfig ( StackedObjectProxy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = '<STR_LIT>' ) : <EOL> super ( DispatchingConfig , self ) . __init__ ( name = name ) <EOL> self . __dict__ [ '<STR_LIT>' ] = [ ] <EOL> def push_thread_config ( self , conf ) : <EOL> """<STR_LIT>""" <EOL> self . _push_object ( conf ) <EOL> def pop_thread_config ( self , conf = None ) : <EOL> """<STR_LIT>""" <EOL> self . _pop_object ( conf ) <EOL> def push_process_config ( self , conf ) : <EOL> """<STR_LIT>""" <EOL> self . _process_configs . append ( conf ) <EOL> def pop_process_config ( self , conf = None ) : <EOL> self . _pop_from ( self . _process_configs , conf ) <EOL> def _pop_from ( self , lst , conf ) : <EOL> popped = lst . pop ( ) <EOL> if conf is not None and popped is not conf : <EOL> raise AssertionError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( popped , conf ) ) <EOL> def _current_obj ( self ) : <EOL> try : <EOL> return super ( DispatchingConfig , self ) . _current_obj ( ) <EOL> except TypeError : <EOL> if self . _process_configs : <EOL> return self . _process_configs [ - <NUM_LIT:1> ] <EOL> raise AttributeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> current = current_conf = _current_obj <EOL> CONFIG = DispatchingConfig ( ) <EOL> no_config = object ( ) <EOL> class ConfigMiddleware ( RegistryManager ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , application , config , dispatching_config = CONFIG , <EOL> environ_key = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> def register_config ( environ , start_response ) : <EOL> popped_config = environ . get ( environ_key , no_config ) <EOL> current_config = environ [ environ_key ] = config . copy ( ) <EOL> environ [ '<STR_LIT>' ] . register ( dispatching_config , <EOL> current_config ) <EOL> try : <EOL> app_iter = application ( environ , start_response ) <EOL> finally : <EOL> if popped_config is no_config : <EOL> environ . pop ( environ_key , None ) <EOL> else : <EOL> environ [ environ_key ] = popped_config <EOL> return app_iter <EOL> super ( self . __class__ , self ) . __init__ ( register_config ) <EOL> def make_config_filter ( app , global_conf , ** local_conf ) : <EOL> conf = global_conf . copy ( ) <EOL> conf . update ( local_conf ) <EOL> return ConfigMiddleware ( app , conf ) <EOL> make_config_middleware = ConfigMiddleware . __doc__ </s>
