Package openid :: Package yadis :: Module services
[frames] | no frames]

Source Code for Module openid.yadis.services

 1  # -*- test-case-name: openid.test.test_services -*- 
 2   
 3  from openid.yadis.filters import mkFilter 
 4  from openid.yadis.discover import discover, DiscoveryFailure 
 5  from openid.yadis.etxrd import parseXRDS, iterServices, XRDSError 
 6   
7 -def getServiceEndpoints(input_url, flt=None):
8 """Perform the Yadis protocol on the input URL and return an 9 iterable of resulting endpoint objects. 10 11 @param flt: A filter object or something that is convertable to 12 a filter object (using mkFilter) that will be used to generate 13 endpoint objects. This defaults to generating BasicEndpoint 14 objects. 15 16 @param input_url: The URL on which to perform the Yadis protocol 17 18 @return: The normalized identity URL and an iterable of endpoint 19 objects generated by the filter function. 20 21 @rtype: (str, [endpoint]) 22 23 @raises DiscoveryFailure: when Yadis fails to obtain an XRDS document. 24 """ 25 result = discover(input_url) 26 try: 27 endpoints = applyFilter(result.normalized_uri, 28 result.response_text, flt) 29 except XRDSError, err: 30 raise DiscoveryFailure(str(err), None) 31 return (result.normalized_uri, endpoints)
32
33 -def applyFilter(normalized_uri, xrd_data, flt=None):
34 """Generate an iterable of endpoint objects given this input data, 35 presumably from the result of performing the Yadis protocol. 36 37 @param normalized_uri: The input URL, after following redirects, 38 as in the Yadis protocol. 39 40 41 @param xrd_data: The XML text the XRDS file fetched from the 42 normalized URI. 43 @type xrd_data: str 44 45 """ 46 flt = mkFilter(flt) 47 et = parseXRDS(xrd_data) 48 49 endpoints = [] 50 for service_element in iterServices(et): 51 endpoints.extend( 52 flt.getServiceEndpoints(normalized_uri, service_element)) 53 54 return endpoints
55