# Path: openid/urinorm.py
# def urinorm(uri):
#     """Return normalized URI.
# 
#     Normalization if performed according to RFC 3986, section 6 https://tools.ietf.org/html/rfc3986#section-6.
#     Supported URIs are URLs and OpenID realm URIs.
# 
#     @type uri: six.text_type, six.binary_type deprecated
#     @rtype: six.text_type
#     @raise ValueError: If URI is invalid.
#     """
#     uri = string_to_text(uri, "Binary input for urinorm is deprecated. Use text input instead.")
# 
#     split_uri = urlsplit(uri)
# 
#     # Normalize scheme
#     scheme = split_uri.scheme.lower()
#     if scheme not in ('http', 'https'):
#         raise ValueError('Not an absolute HTTP or HTTPS URI: {!r}'.format(uri))
# 
#     # Normalize netloc
#     if not split_uri.netloc:
#         raise ValueError('Not an absolute URI: {!r}'.format(uri))
# 
#     hostname = split_uri.hostname
#     if hostname is None:
#         hostname = ''
#     else:
#         hostname = hostname.lower()
#     # Unquote percent encoded characters
#     hostname = unquote(hostname)
#     # Quote IDN domain names
#     try:
#         # hostname: str --[idna]--> bytes --[utf-8]--> str
#         hostname = hostname.encode('idna').decode('utf-8')
#     except ValueError as error:
#         raise ValueError('Invalid hostname {!r}: {}'.format(hostname, error))
#     _check_disallowed_characters(hostname, 'hostname')
# 
#     try:
#         port = split_uri.port
#     except ValueError as error:
#         raise ValueError('Invalid port in {!r}: {}'.format(split_uri.netloc, error))
#     if port is None:
#         port = ''
#     elif (scheme == 'http' and port == 80) or (scheme == 'https' and port == 443):
#         port = ''
# 
#     netloc = hostname
#     if port:
#         netloc = netloc + ':' + six.text_type(port)
#     userinfo_chunks = [i for i in (split_uri.username, split_uri.password) if i is not None]
#     if userinfo_chunks:
#         userinfo = ':'.join(userinfo_chunks)
#         _check_disallowed_characters(userinfo, 'userinfo')
#         netloc = userinfo + '@' + netloc
# 
#     # Normalize path
#     path = split_uri.path
#     # Unquote and quote - this normalizes the percent encoding
# 
#     # This is hackish. `unquote` and `quote` requires `str` in both py27 and py3+.
#     if isinstance(path, str):
#         # Python 3 branch
#         path = quote(unquote(path), safe='/' + SUB_DELIMS)
#     else:
#         # Python 2 branch
#         path = quote(unquote(path.encode('utf-8')), safe=('/' + SUB_DELIMS).encode('utf-8')).decode('utf-8')
# 
#     path = remove_dot_segments(path)
#     if not path:
#         path = '/'
#     _check_disallowed_characters(path, 'path')
# 
#     # Normalize query.  On Python 2, `urlencode` without `doseq=True`
#     # requires values to be convertible to native strings using `str()`.
#     if isinstance(split_uri.query, str):
#         # Python 3 branch
#         data = parse_qsl(split_uri.query)
#     else:
#         # Python 2 branch
#         data = parse_qsl(split_uri.query.encode('utf-8'))
#     query = urlencode(data)
#     _check_disallowed_characters(query, 'query')
# 
#     # Normalize fragment
#     fragment = unquote(split_uri.fragment)
#     _check_disallowed_characters(fragment, 'fragment')
# 
#     return urlunsplit((scheme, netloc, path, query, fragment))
# 
# 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/services.py
# def getServiceEndpoints(input_url, flt=None):
# def applyFilter(normalized_uri, xrd_data, flt=None):


import logging
import re
import six
from six.moves.urllib.parse import urlsplit, urlunsplit
from openid import urinorm
from openid.oidutil import string_to_text
from openid.yadis import services

            # These characters must be on the boundary between the end
            # of the trust root's path and the start of the URL's
            # path.
            if '?' in self.path:
                allowed = '&'
            else:
                allowed = '?/'

            return (self.path[-1] in allowed or path[path_len] in allowed)

        return True

    @classmethod
    def parse(cls, trust_root):
        """
        This method creates a C{L{TrustRoot}} instance from the given
        input, if possible.


        @param trust_root: This is the trust root to parse into a
        C{L{TrustRoot}} object.
        @type trust_root: six.text_type, six.binary_type is deprecated


        @return: A C{L{TrustRoot}} instance if trust_root parses as a
        trust root, C{None} otherwise.

        @rtype: C{NoneType} or C{L{TrustRoot}}
        """

# Path: openid/urinorm.py
# def urinorm(uri):
#     """Return normalized URI.
# 
#     Normalization if performed according to RFC 3986, section 6 https://tools.ietf.org/html/rfc3986#section-6.
#     Supported URIs are URLs and OpenID realm URIs.
# 
#     @type uri: six.text_type, six.binary_type deprecated
#     @rtype: six.text_type
#     @raise ValueError: If URI is invalid.
#     """
#     uri = string_to_text(uri, "Binary input for urinorm is deprecated. Use text input instead.")
# 
#     split_uri = urlsplit(uri)
# 
#     # Normalize scheme
#     scheme = split_uri.scheme.lower()
#     if scheme not in ('http', 'https'):
#         raise ValueError('Not an absolute HTTP or HTTPS URI: {!r}'.format(uri))
# 
#     # Normalize netloc
#     if not split_uri.netloc:
#         raise ValueError('Not an absolute URI: {!r}'.format(uri))
# 
#     hostname = split_uri.hostname
#     if hostname is None:
#         hostname = ''
#     else:
#         hostname = hostname.lower()
#     # Unquote percent encoded characters
#     hostname = unquote(hostname)
#     # Quote IDN domain names
#     try:
#         # hostname: str --[idna]--> bytes --[utf-8]--> str
#         hostname = hostname.encode('idna').decode('utf-8')
#     except ValueError as error:
#         raise ValueError('Invalid hostname {!r}: {}'.format(hostname, error))
#     _check_disallowed_characters(hostname, 'hostname')
# 
#     try:
#         port = split_uri.port
#     except ValueError as error:
#         raise ValueError('Invalid port in {!r}: {}'.format(split_uri.netloc, error))
#     if port is None:
#         port = ''
#     elif (scheme == 'http' and port == 80) or (scheme == 'https' and port == 443):
#         port = ''
# 
#     netloc = hostname
#     if port:
#         netloc = netloc + ':' + six.text_type(port)
#     userinfo_chunks = [i for i in (split_uri.username, split_uri.password) if i is not None]
#     if userinfo_chunks:
#         userinfo = ':'.join(userinfo_chunks)
#         _check_disallowed_characters(userinfo, 'userinfo')
#         netloc = userinfo + '@' + netloc
# 
#     # Normalize path
#     path = split_uri.path
#     # Unquote and quote - this normalizes the percent encoding
# 
#     # This is hackish. `unquote` and `quote` requires `str` in both py27 and py3+.
#     if isinstance(path, str):
#         # Python 3 branch
#         path = quote(unquote(path), safe='/' + SUB_DELIMS)
#     else:
#         # Python 2 branch
#         path = quote(unquote(path.encode('utf-8')), safe=('/' + SUB_DELIMS).encode('utf-8')).decode('utf-8')
# 
#     path = remove_dot_segments(path)
#     if not path:
#         path = '/'
#     _check_disallowed_characters(path, 'path')
# 
#     # Normalize query.  On Python 2, `urlencode` without `doseq=True`
#     # requires values to be convertible to native strings using `str()`.
#     if isinstance(split_uri.query, str):
#         # Python 3 branch
#         data = parse_qsl(split_uri.query)
#     else:
#         # Python 2 branch
#         data = parse_qsl(split_uri.query.encode('utf-8'))
#     query = urlencode(data)
#     _check_disallowed_characters(query, 'query')
# 
#     # Normalize fragment
#     fragment = unquote(split_uri.fragment)
#     _check_disallowed_characters(fragment, 'fragment')
# 
#     return urlunsplit((scheme, netloc, path, query, fragment))
# 
# 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/services.py
# def getServiceEndpoints(input_url, flt=None):
# def applyFilter(normalized_uri, xrd_data, flt=None):


# Path: openid/server/trustroot.py
import logging
import re
import six
from six.moves.urllib.parse import urlsplit, urlunsplit
from openid import urinorm
from openid.oidutil import string_to_text
from openid.yadis import services


            # These characters must be on the boundary between the end
            # of the trust root's path and the start of the URL's
            # path.
            if '?' in self.path:
                allowed = '&'
            else:
                allowed = '?/'

            return (self.path[-1] in allowed or path[path_len] in allowed)

        return True

    @classmethod
    def parse(cls, trust_root):
        """
        This method creates a C{L{TrustRoot}} instance from the given
        input, if possible.


        @param trust_root: This is the trust root to parse into a
        C{L{TrustRoot}} object.
        @type trust_root: six.text_type, six.binary_type is deprecated


        @return: A C{L{TrustRoot}} instance if trust_root parses as a
        trust root, C{None} otherwise.

        @rtype: C{NoneType} or C{L{TrustRoot}}
        """

        trust_root = string_to_text(trust_root, "Binary values for trust_root are deprecated. Use text input instead.")