<s> """<STR_LIT>""" <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> from openid . yadis . etxrd import expandService <EOL> import collections <EOL> class BasicServiceEndpoint ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , yadis_url , type_uris , uri , service_element ) : <EOL> self . type_uris = type_uris <EOL> self . yadis_url = yadis_url <EOL> self . uri = uri <EOL> self . service_element = service_element <EOL> def matchTypes ( self , type_uris ) : <EOL> """<STR_LIT>""" <EOL> return [ uri for uri in type_uris if uri in self . type_uris ] <EOL> def fromBasicServiceEndpoint ( endpoint ) : <EOL> """<STR_LIT>""" <EOL> return endpoint <EOL> fromBasicServiceEndpoint = staticmethod ( fromBasicServiceEndpoint ) <EOL> class IFilter ( object ) : <EOL> """<STR_LIT>""" <EOL> def getServiceEndpoints ( self , yadis_url , service_element ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class TransformFilterMaker ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filter_functions ) : <EOL> """<STR_LIT>""" <EOL> self . filter_functions = filter_functions <EOL> def getServiceEndpoints ( self , yadis_url , service_element ) : <EOL> """<STR_LIT>""" <EOL> endpoints = [ ] <EOL> for type_uris , uri , _ in expandService ( service_element ) : <EOL> endpoint = BasicServiceEndpoint ( <EOL> yadis_url , type_uris , uri , service_element ) <EOL> e = self . applyFilters ( endpoint ) <EOL> if e is not None : <EOL> endpoints . append ( e ) <EOL> return endpoints <EOL> def applyFilters ( self , endpoint ) : <EOL> """<STR_LIT>""" <EOL> for filter_function in self . filter_functions : <EOL> e = filter_function ( endpoint ) <EOL> if e is not None : <EOL> return e <EOL> return None <EOL> class CompoundFilter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , subfilters ) : <EOL> self . subfilters = subfilters <EOL> def getServiceEndpoints ( self , yadis_url , service_element ) : <EOL> """<STR_LIT>""" <EOL> endpoints = [ ] <EOL> for subfilter in self . subfilters : <EOL> endpoints . extend ( <EOL> subfilter . getServiceEndpoints ( yadis_url , service_element ) ) <EOL> return endpoints <EOL> filter_type_error = TypeError ( <EOL> '<STR_LIT>' ) <EOL> def mkFilter ( parts ) : <EOL> """<STR_LIT>""" <EOL> if parts is None : <EOL> parts = [ BasicServiceEndpoint ] <EOL> try : <EOL> parts = list ( parts ) <EOL> except TypeError : <EOL> return mkCompoundFilter ( [ parts ] ) <EOL> else : <EOL> return mkCompoundFilter ( parts ) <EOL> def mkCompoundFilter ( parts ) : <EOL> """<STR_LIT>""" <EOL> transformers = [ ] <EOL> filters = [ ] <EOL> for subfilter in parts : <EOL> try : <EOL> subfilter = list ( subfilter ) <EOL> except TypeError : <EOL> if hasattr ( subfilter , '<STR_LIT>' ) : <EOL> filters . append ( subfilter ) <EOL> elif hasattr ( subfilter , '<STR_LIT>' ) : <EOL> transformers . append ( subfilter . fromBasicServiceEndpoint ) <EOL> elif isinstance ( subfilter , collections . Callable ) : <EOL> transformers . append ( subfilter ) <EOL> else : <EOL> raise filter_type_error <EOL> else : <EOL> filters . append ( mkCompoundFilter ( subfilter ) ) <EOL> if transformers : <EOL> filters . append ( TransformFilterMaker ( transformers ) ) <EOL> if len ( filters ) == <NUM_LIT:1> : <EOL> return filters [ <NUM_LIT:0> ] <EOL> else : <EOL> return CompoundFilter ( filters ) </s>
