# 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/yadis/constants.py
# YADIS_ACCEPT_HEADER = generateAcceptHeader(
#     ('text/html', 0.3),
#     ('application/xhtml+xml', 0.5),
#     (YADIS_CONTENT_TYPE, 1.0),
# )
# 
# YADIS_CONTENT_TYPE = 'application/xrds+xml'
# 
# YADIS_HEADER_NAME = 'X-XRDS-Location'
# 
# Path: openid/yadis/parsehtml.py
# class MetaNotFound(Exception):
#     """Yadis meta tag not found in the HTML page."""
# 
# def findHTMLMeta(stream):
#     """Look for a meta http-equiv tag with the YADIS header name.
# 
#     @param stream: Source of the html text
#     @type stream: Readable text I/O file object
# 
#     @return: The URI from which to fetch the XRDS document
#     @rtype: six.text_type
# 
#     @raises MetaNotFound: raised with the content that was
#         searched as the first parameter.
#     """
#     parser = etree.HTMLParser()
#     try:
#         html = etree.parse(stream, parser)
#     except (ValueError, etree.XMLSyntaxError):
#         raise MetaNotFound("Couldn't parse HTML page.")
# 
#     # Invalid input may return element with no content
#     if html.getroot() is None:
#         raise MetaNotFound("Couldn't parse HTML page.")
# 
#     # Create a XPath evaluator with a local function to lowercase values.
#     xpath_evaluator = etree.XPathEvaluator(html, extensions={(None, 'lower-case'): xpath_lower_case})
#     # Find YADIS meta tag, case insensitive to the header name.
#     yadis_headers = xpath_evaluator('/html/head/meta[lower-case(@http-equiv)="{}"]'.format(YADIS_HEADER_NAME.lower()))
#     if not yadis_headers:
#         raise MetaNotFound('Yadis meta tag not found.')
# 
#     yadis_header = yadis_headers[0]
#     yadis_url = yadis_header.get('content')
#     if yadis_url is None:
#         raise MetaNotFound('Attribute "content" missing in yadis meta tag.')
#     return yadis_url


from six import BytesIO, StringIO
from openid import fetchers
from openid.yadis.constants import YADIS_ACCEPT_HEADER, YADIS_CONTENT_TYPE, YADIS_HEADER_NAME
from openid.yadis.parsehtml import MetaNotFound, findHTMLMeta
    if result.xrds_uri and result.usedYadisLocation():
        resp = fetchers.fetch(result.xrds_uri)
        if resp.status not in (200, 206):
            exc = DiscoveryFailure(
                'HTTP Response status from Yadis host is not 200. '
                'Got status %r' % (resp.status,), resp)
            exc.identity_url = result.normalized_uri
            raise exc
        result.content_type = resp.headers.get('content-type')

    result.response_text = resp.body
    return result


def whereIsYadis(resp):
    """Given a HTTPResponse, return the location of the Yadis document.

    May be the URL just retrieved, another URL, or None, if I can't
    find any.

    [non-blocking]

    @returns: six.text_type or None
    """
    # Attempt to find out where to go to discover the document
    # or if we already have it
    content_type = resp.headers.get('content-type')

    # According to the spec, the content-type header must be an exact
    # match, or else we have to look for an indirection.

# 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/yadis/constants.py
# YADIS_ACCEPT_HEADER = generateAcceptHeader(
#     ('text/html', 0.3),
#     ('application/xhtml+xml', 0.5),
#     (YADIS_CONTENT_TYPE, 1.0),
# )
# 
# YADIS_CONTENT_TYPE = 'application/xrds+xml'
# 
# YADIS_HEADER_NAME = 'X-XRDS-Location'
# 
# Path: openid/yadis/parsehtml.py
# class MetaNotFound(Exception):
#     """Yadis meta tag not found in the HTML page."""
# 
# def findHTMLMeta(stream):
#     """Look for a meta http-equiv tag with the YADIS header name.
# 
#     @param stream: Source of the html text
#     @type stream: Readable text I/O file object
# 
#     @return: The URI from which to fetch the XRDS document
#     @rtype: six.text_type
# 
#     @raises MetaNotFound: raised with the content that was
#         searched as the first parameter.
#     """
#     parser = etree.HTMLParser()
#     try:
#         html = etree.parse(stream, parser)
#     except (ValueError, etree.XMLSyntaxError):
#         raise MetaNotFound("Couldn't parse HTML page.")
# 
#     # Invalid input may return element with no content
#     if html.getroot() is None:
#         raise MetaNotFound("Couldn't parse HTML page.")
# 
#     # Create a XPath evaluator with a local function to lowercase values.
#     xpath_evaluator = etree.XPathEvaluator(html, extensions={(None, 'lower-case'): xpath_lower_case})
#     # Find YADIS meta tag, case insensitive to the header name.
#     yadis_headers = xpath_evaluator('/html/head/meta[lower-case(@http-equiv)="{}"]'.format(YADIS_HEADER_NAME.lower()))
#     if not yadis_headers:
#         raise MetaNotFound('Yadis meta tag not found.')
# 
#     yadis_header = yadis_headers[0]
#     yadis_url = yadis_header.get('content')
#     if yadis_url is None:
#         raise MetaNotFound('Attribute "content" missing in yadis meta tag.')
#     return yadis_url


# Path: openid/yadis/discover.py
from six import BytesIO, StringIO
from openid import fetchers
from openid.yadis.constants import YADIS_ACCEPT_HEADER, YADIS_CONTENT_TYPE, YADIS_HEADER_NAME
from openid.yadis.parsehtml import MetaNotFound, findHTMLMeta

    if result.xrds_uri and result.usedYadisLocation():
        resp = fetchers.fetch(result.xrds_uri)
        if resp.status not in (200, 206):
            exc = DiscoveryFailure(
                'HTTP Response status from Yadis host is not 200. '
                'Got status %r' % (resp.status,), resp)
            exc.identity_url = result.normalized_uri
            raise exc
        result.content_type = resp.headers.get('content-type')

    result.response_text = resp.body
    return result


def whereIsYadis(resp):
    """Given a HTTPResponse, return the location of the Yadis document.

    May be the URL just retrieved, another URL, or None, if I can't
    find any.

    [non-blocking]

    @returns: six.text_type or None
    """
    # Attempt to find out where to go to discover the document
    # or if we already have it
    content_type = resp.headers.get('content-type')

    # According to the spec, the content-type header must be an exact
    # match, or else we have to look for an indirection.

    if content_type and content_type.split(';', 1)[0].lower() == YADIS_CONTENT_TYPE: