1 # -*- test-case-name: openid.test.test_services -*-
3 from openid
.yadis
.filters
import mkFilter
4 from openid
.yadis
.discover
import discover
, DiscoveryFailure
5 from openid
.yadis
.etxrd
import parseXRDS
, iterServices
, XRDSError
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.
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
16 @param input_url: The URL on which to perform the Yadis protocol
18 @return: The normalized identity URL and an iterable of endpoint
19 objects generated by the filter function.
21 @rtype: (str, [endpoint])
23 @raises DiscoveryFailure: when Yadis fails to obtain an XRDS document.
25 result
= discover(input_url
)
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
)
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.
37 @param normalized_uri: The input URL, after following redirects,
38 as in the Yadis protocol.
41 @param xrd_data: The XML text the XRDS file fetched from the
47 et
= parseXRDS(xrd_data
)
50 for service_element
in iterServices(et
):
52 flt
.getServiceEndpoints(normalized_uri
, service_element
))