# Path: openid/yadis/xri.py
# XRI_AUTHORITIES = ['!', '=', '@', '+', '$', '(']
# def identifierScheme(identifier):
# def toIRINormal(xri):
# def _escape_xref(xref_match):
# def escapeForIRI(xri):
# def toURINormal(xri):
# def iriToURI(iri):
# def providerIsAuthoritative(providerID, canonicalID):
# def rootAuthority(xri):
# def XRI(xri):


import random
import six
from datetime import datetime
from functools import total_ordering
from operator import itemgetter
from time import strptime
from lxml import etree
from openid.yadis import xri
    """Return the CanonicalID from this XRDS document.

    @param iname: the XRI being resolved.
    @type iname: six.text_type

    @param xrd_tree: The XRDS output from the resolver.
    @type xrd_tree: ElementTree

    @returns: The XRI CanonicalID or None.
    @returntype: six.text_type or None
    """
    xrd_list = xrd_tree.findall(xrd_tag)
    xrd_list.reverse()

    try:
        canonicalID = xri.XRI(xrd_list[0].findall(canonicalID_tag)[0].text)
    except IndexError:
        return None

    childID = canonicalID.lower()

    for xrd in xrd_list[1:]:
        # XXX: can't use rsplit until we require python >= 2.4.
        parent_sought = childID[:childID.rindex('!')]
        parent = xri.XRI(xrd.findtext(canonicalID_tag))
        if parent_sought != parent.lower():
            raise XRDSFraud("%r can not come from %s" % (childID, parent))

        childID = parent_sought


# Path: openid/yadis/xri.py
# XRI_AUTHORITIES = ['!', '=', '@', '+', '$', '(']
# def identifierScheme(identifier):
# def toIRINormal(xri):
# def _escape_xref(xref_match):
# def escapeForIRI(xri):
# def toURINormal(xri):
# def iriToURI(iri):
# def providerIsAuthoritative(providerID, canonicalID):
# def rootAuthority(xri):
# def XRI(xri):


# Path: openid/yadis/etxrd.py
import random
import six
from datetime import datetime
from functools import total_ordering
from operator import itemgetter
from time import strptime
from lxml import etree
from openid.yadis import xri

    """Return the CanonicalID from this XRDS document.

    @param iname: the XRI being resolved.
    @type iname: six.text_type

    @param xrd_tree: The XRDS output from the resolver.
    @type xrd_tree: ElementTree

    @returns: The XRI CanonicalID or None.
    @returntype: six.text_type or None
    """
    xrd_list = xrd_tree.findall(xrd_tag)
    xrd_list.reverse()

    try:
        canonicalID = xri.XRI(xrd_list[0].findall(canonicalID_tag)[0].text)
    except IndexError:
        return None

    childID = canonicalID.lower()

    for xrd in xrd_list[1:]:
        # XXX: can't use rsplit until we require python >= 2.4.
        parent_sought = childID[:childID.rindex('!')]
        parent = xri.XRI(xrd.findtext(canonicalID_tag))
        if parent_sought != parent.lower():
            raise XRDSFraud("%r can not come from %s" % (childID, parent))

        childID = parent_sought


    root = xri.rootAuthority(iname)