# 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
# 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 os.path
import tempfile
import unittest
import six
from lxml import etree
from openid.yadis import etxrd, services, xri

    test_status222 = mkTest("=x", "status222.xrds", None)

    test_multisegment_xri = mkTest('xri://=nishitani*masaki',
                                   'subsegments.xrds',
                                   '=!E117.EF2F.454B.C707!0000.0000.3B9A.CA01')

    test_iri_auth_not_allowed = mkTest(
        "phreak.example.com", "delegated-20060809-r2.xrds", etxrd.XRDSFraud)
    test_iri_auth_not_allowed.__doc__ = \
        "Don't let IRI authorities be canonical for the GCS."

    # TODO: Refs
    # test_ref = mkTest("@ootao*test.ref", "ref.xrds", "@!BAE.A650.823B.2475")

    # TODO: Add a IRI authority with an IRI canonicalID.
    # TODO: Add test cases with real examples of multiple CanonicalIDs
    #   somewhere in the resolution chain.

    def _getCanonicalID(self, iname, xrds, expectedID):
        if isinstance(expectedID, six.string_types + (type(None), )):
            cid = etxrd.getCanonicalID(iname, xrds)
            self.assertEqual(cid, expectedID and xri.XRI(expectedID))
        elif issubclass(expectedID, etxrd.XRDSError):
            self.assertRaises(expectedID, etxrd.getCanonicalID, iname, xrds)
        else:
            self.fail("Don't know how to test for expected value %r"
                      % (expectedID,))



# 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
# 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/test/test_etxrd.py
import os.path
import tempfile
import unittest
import six
from lxml import etree
from openid.yadis import etxrd, services, xri


    test_status222 = mkTest("=x", "status222.xrds", None)

    test_multisegment_xri = mkTest('xri://=nishitani*masaki',
                                   'subsegments.xrds',
                                   '=!E117.EF2F.454B.C707!0000.0000.3B9A.CA01')

    test_iri_auth_not_allowed = mkTest(
        "phreak.example.com", "delegated-20060809-r2.xrds", etxrd.XRDSFraud)
    test_iri_auth_not_allowed.__doc__ = \
        "Don't let IRI authorities be canonical for the GCS."

    # TODO: Refs
    # test_ref = mkTest("@ootao*test.ref", "ref.xrds", "@!BAE.A650.823B.2475")

    # TODO: Add a IRI authority with an IRI canonicalID.
    # TODO: Add test cases with real examples of multiple CanonicalIDs
    #   somewhere in the resolution chain.

    def _getCanonicalID(self, iname, xrds, expectedID):
        if isinstance(expectedID, six.string_types + (type(None), )):
            cid = etxrd.getCanonicalID(iname, xrds)
            self.assertEqual(cid, expectedID and xri.XRI(expectedID))
        elif issubclass(expectedID, etxrd.XRDSError):
            self.assertRaises(expectedID, etxrd.getCanonicalID, iname, xrds)
        else:
            self.fail("Don't know how to test for expected value %r"
                      % (expectedID,))



if __name__ == '__main__':