getting file size for all dict files to be downloaded. coming to be 400mb or so.
[worddb.git] / libs / openid / yadis / services.py
blob4753c194d8aad65f3385e88ad32752e63834aa8d
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
14 objects.
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.
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)
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
42 normalized URI.
43 @type xrd_data: str
45 """
46 flt = mkFilter(flt)
47 et = parseXRDS(xrd_data)
49 endpoints = []
50 for service_element in iterServices(et):
51 endpoints.extend(
52 flt.getServiceEndpoints(normalized_uri, service_element))
54 return endpoints