<s> """<STR_LIT>""" <EOL> class MultiHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , application ) : <EOL> self . application = application <EOL> self . default = application <EOL> self . binding = { } <EOL> self . predicate = [ ] <EOL> def add_method ( self , name , factory , * args , ** kwargs ) : <EOL> self . binding [ name ] = factory ( self . application , * args , ** kwargs ) <EOL> def add_predicate ( self , name , checker ) : <EOL> self . predicate . append ( ( checker , self . binding [ name ] ) ) <EOL> def set_default ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . default = self . binding [ name ] <EOL> def set_query_argument ( self , name , key = '<STR_LIT>' , value = None ) : <EOL> """<STR_LIT>""" <EOL> lookfor = "<STR_LIT>" % ( key , value or name ) <EOL> self . add_predicate ( name , <EOL> lambda environ : lookfor in environ . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def __call__ ( self , environ , start_response ) : <EOL> for ( checker , binding ) in self . predicate : <EOL> if checker ( environ ) : <EOL> return binding ( environ , start_response ) <EOL> return self . default ( environ , start_response ) <EOL> middleware = MultiHandler <EOL> __all__ = [ '<STR_LIT>' ] <EOL> if "<STR_LIT:__main__>" == __name__ : <EOL> import doctest <EOL> doctest . testmod ( optionflags = doctest . ELLIPSIS ) </s>
