# Path: openid/fetchers.py
# USER_AGENT = "python-openid/%s (%s)" % (openid.__version__, sys.platform)
# MAX_RESPONSE_KB = 1024
#     ALLOWED_TIME = 20  # seconds
# def fetch(url, body=None, headers=None):
# def createHTTPFetcher():
# def getDefaultFetcher():
# def setDefaultFetcher(fetcher, wrap_exceptions=True):
# def usingCurl():
#     def __init__(self, final_url=None, status=None, headers=None, body=None):
#     def __repr__(self):
#     def fetch(self, url, body=None, headers=None):
# def _allowedURL(url):
#     def __init__(self, why=None):
#     def __init__(self, fetcher):
#     def fetch(self, *args, **kwargs):
#     def fetch(self, url, body=None, headers=None):
#     def _makeResponse(self, urllib_response):
#     def __init__(self):
#     def _parseHeaders(self, header_file):
#     def _checkURL(self, url):
#     def fetch(self, url, body=None, headers=None):
#                 def write_data(chunk):
#     def __init__(self, cache=None):
#     def fetch(self, url, body=None, headers=None):
#     def fetch(self, url, body=None, headers=None):
# class HTTPResponse(object):
# class HTTPFetcher(object):
# class HTTPFetchingError(Exception):
# class ExceptionWrappingFetcher(HTTPFetcher):
# class Urllib2Fetcher(HTTPFetcher):
# class HTTPError(HTTPFetchingError):
# class CurlHTTPFetcher(HTTPFetcher):
# class HTTPLib2Fetcher(HTTPFetcher):
# class RequestsFetcher(HTTPFetcher):
# 
# Path: openid/oidutil.py
# def string_to_text(value, deprecate_msg):
#     """
#     Return input string coverted to text string.
# 
#     If input is text, it is returned as is.
#     If input is binary, it is decoded using UTF-8 to text.
#     """
#     assert isinstance(value, (six.text_type, six.binary_type))
#     if isinstance(value, six.binary_type):
#         warnings.warn(deprecate_msg, DeprecationWarning)
#         value = value.decode('utf-8')
#     return value
# 
# Path: openid/yadis/etxrd.py
# class XRDSError(Exception):
# class XRDSFraud(XRDSError):
# class _Max(object):
# def parseXRDS(text):
# def nsTag(ns, t):
# def mkXRDTag(t):
# def mkXRDSTag(t):
# def isXRDS(xrd_tree):
# def getYadisXRD(xrd_tree):
# def getXRDExpiration(xrd_element, default=None):
# def getCanonicalID(iname, xrd_tree):
#     def __eq__(self, other):
#     def __gt__(self, other):
# def getPriorityStrict(element):
# def getPriority(element):
# def prioSort(elements):
# def iterServices(xrd_tree):
# def sortedURIs(service_element):
# def getTypeURIs(service_element):
# def expandService(service_element):
# def expandServices(service_elements):
# XRD_NS_2_0 = 'xri://$xrd*($v*2.0)'
# XRDS_NS = 'xri://$xrds'
# 
# Path: openid/yadis/services.py
# def getServiceEndpoints(input_url, flt=None):
# def applyFilter(normalized_uri, xrd_data, flt=None):
# 
# Path: openid/yadis/xri.py
# def toURINormal(xri):
#     """Transform an XRI to URI normal form."""
#     return iriToURI(toIRINormal(xri))


from six.moves.urllib.parse import urlencode
from openid import fetchers
from openid.oidutil import string_to_text
from openid.yadis import etxrd
from openid.yadis.services import iterServices
from openid.yadis.xri import toURINormal

        May raise fetchers.HTTPFetchingError or L{etxrd.XRDSError} if
        the fetching or parsing don't go so well.

        @param xri: An XRI to resolve.
        @type xri: six.text_type

        @param service_types: A list of services types to query for.  Service
            types are URIs.
        @type service_types: List[six.text_type], six.binary_type is deprecated

        @returns: tuple of (CanonicalID, Service elements)
        @returntype: (six.text_type, list of C{ElementTree.Element}s)
        """
        # FIXME: No test coverage!
        services = []
        # Make a seperate request to the proxy resolver for each service
        # type, as, if it is following Refs, it could return a different
        # XRDS for each.

        canonicalID = None

        for service_type in service_types:
            url = self.queryURL(xri, service_type)
            response = fetchers.fetch(url)
            if response.status not in (200, 206):
                # XXX: sucks to fail silently.
                # print("response not OK:", response)
                continue
            et = etxrd.parseXRDS(response.body)

# Path: openid/fetchers.py
# USER_AGENT = "python-openid/%s (%s)" % (openid.__version__, sys.platform)
# MAX_RESPONSE_KB = 1024
#     ALLOWED_TIME = 20  # seconds
# def fetch(url, body=None, headers=None):
# def createHTTPFetcher():
# def getDefaultFetcher():
# def setDefaultFetcher(fetcher, wrap_exceptions=True):
# def usingCurl():
#     def __init__(self, final_url=None, status=None, headers=None, body=None):
#     def __repr__(self):
#     def fetch(self, url, body=None, headers=None):
# def _allowedURL(url):
#     def __init__(self, why=None):
#     def __init__(self, fetcher):
#     def fetch(self, *args, **kwargs):
#     def fetch(self, url, body=None, headers=None):
#     def _makeResponse(self, urllib_response):
#     def __init__(self):
#     def _parseHeaders(self, header_file):
#     def _checkURL(self, url):
#     def fetch(self, url, body=None, headers=None):
#                 def write_data(chunk):
#     def __init__(self, cache=None):
#     def fetch(self, url, body=None, headers=None):
#     def fetch(self, url, body=None, headers=None):
# class HTTPResponse(object):
# class HTTPFetcher(object):
# class HTTPFetchingError(Exception):
# class ExceptionWrappingFetcher(HTTPFetcher):
# class Urllib2Fetcher(HTTPFetcher):
# class HTTPError(HTTPFetchingError):
# class CurlHTTPFetcher(HTTPFetcher):
# class HTTPLib2Fetcher(HTTPFetcher):
# class RequestsFetcher(HTTPFetcher):
# 
# Path: openid/oidutil.py
# def string_to_text(value, deprecate_msg):
#     """
#     Return input string coverted to text string.
# 
#     If input is text, it is returned as is.
#     If input is binary, it is decoded using UTF-8 to text.
#     """
#     assert isinstance(value, (six.text_type, six.binary_type))
#     if isinstance(value, six.binary_type):
#         warnings.warn(deprecate_msg, DeprecationWarning)
#         value = value.decode('utf-8')
#     return value
# 
# Path: openid/yadis/etxrd.py
# class XRDSError(Exception):
# class XRDSFraud(XRDSError):
# class _Max(object):
# def parseXRDS(text):
# def nsTag(ns, t):
# def mkXRDTag(t):
# def mkXRDSTag(t):
# def isXRDS(xrd_tree):
# def getYadisXRD(xrd_tree):
# def getXRDExpiration(xrd_element, default=None):
# def getCanonicalID(iname, xrd_tree):
#     def __eq__(self, other):
#     def __gt__(self, other):
# def getPriorityStrict(element):
# def getPriority(element):
# def prioSort(elements):
# def iterServices(xrd_tree):
# def sortedURIs(service_element):
# def getTypeURIs(service_element):
# def expandService(service_element):
# def expandServices(service_elements):
# XRD_NS_2_0 = 'xri://$xrd*($v*2.0)'
# XRDS_NS = 'xri://$xrds'
# 
# Path: openid/yadis/services.py
# def getServiceEndpoints(input_url, flt=None):
# def applyFilter(normalized_uri, xrd_data, flt=None):
# 
# Path: openid/yadis/xri.py
# def toURINormal(xri):
#     """Transform an XRI to URI normal form."""
#     return iriToURI(toIRINormal(xri))


# Path: openid/yadis/xrires.py
from six.moves.urllib.parse import urlencode
from openid import fetchers
from openid.oidutil import string_to_text
from openid.yadis import etxrd
from openid.yadis.services import iterServices
from openid.yadis.xri import toURINormal


        May raise fetchers.HTTPFetchingError or L{etxrd.XRDSError} if
        the fetching or parsing don't go so well.

        @param xri: An XRI to resolve.
        @type xri: six.text_type

        @param service_types: A list of services types to query for.  Service
            types are URIs.
        @type service_types: List[six.text_type], six.binary_type is deprecated

        @returns: tuple of (CanonicalID, Service elements)
        @returntype: (six.text_type, list of C{ElementTree.Element}s)
        """
        # FIXME: No test coverage!
        services = []
        # Make a seperate request to the proxy resolver for each service
        # type, as, if it is following Refs, it could return a different
        # XRDS for each.

        canonicalID = None

        for service_type in service_types:
            url = self.queryURL(xri, service_type)
            response = fetchers.fetch(url)
            if response.status not in (200, 206):
                # XXX: sucks to fail silently.
                # print("response not OK:", response)
                continue
            et = etxrd.parseXRDS(response.body)

            canonicalID = etxrd.getCanonicalID(xri, et)