# 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/urinorm.py
# GEN_DELIMS = ":" + "/" + "?" + "#" + "[" + "]" + "@"
# 
# PERCENT_ENCODING_CHARACTER = "%"
# 
# SUB_DELIMS = "!" + "$" + "&" + "'" + "(" + ")" + "*" + "+" + "," + ";" + "="


import re
from six.moves.urllib.parse import quote
from openid.oidutil import string_to_text
from openid.urinorm import GEN_DELIMS, PERCENT_ENCODING_CHARACTER, SUB_DELIMS

def escapeForIRI(xri):
    """Escape things that need to be escaped when transforming to an IRI."""
    xri = xri.replace('%', '%25')
    xri = _xref_re.sub(_escape_xref, xri)
    return xri


def toURINormal(xri):
    """Transform an XRI to URI normal form."""
    return iriToURI(toIRINormal(xri))


def iriToURI(iri):
    """Transform an IRI to a URI by escaping unicode.

    According to RFC 3987, section 3.1, "Mapping of IRIs to URIs"

    @type iri: six.text_type, six.binary_type deprecated.
    @rtype: six.text_type
    """
    iri = string_to_text(iri, "Binary input for iriToURI is deprecated. Use text input instead.")

    # This is hackish. `quote` requires `str` in both py27 and py3+.
    if isinstance(iri, str):
        # Python 3 branch
        return quote(iri, GEN_DELIMS + SUB_DELIMS + PERCENT_ENCODING_CHARACTER)
    else:
        # Python 2 branch
        return quote(iri.encode('utf-8'),

# 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/urinorm.py
# GEN_DELIMS = ":" + "/" + "?" + "#" + "[" + "]" + "@"
# 
# PERCENT_ENCODING_CHARACTER = "%"
# 
# SUB_DELIMS = "!" + "$" + "&" + "'" + "(" + ")" + "*" + "+" + "," + ";" + "="


# Path: openid/yadis/xri.py
import re
from six.moves.urllib.parse import quote
from openid.oidutil import string_to_text
from openid.urinorm import GEN_DELIMS, PERCENT_ENCODING_CHARACTER, SUB_DELIMS


def escapeForIRI(xri):
    """Escape things that need to be escaped when transforming to an IRI."""
    xri = xri.replace('%', '%25')
    xri = _xref_re.sub(_escape_xref, xri)
    return xri


def toURINormal(xri):
    """Transform an XRI to URI normal form."""
    return iriToURI(toIRINormal(xri))


def iriToURI(iri):
    """Transform an IRI to a URI by escaping unicode.

    According to RFC 3987, section 3.1, "Mapping of IRIs to URIs"

    @type iri: six.text_type, six.binary_type deprecated.
    @rtype: six.text_type
    """
    iri = string_to_text(iri, "Binary input for iriToURI is deprecated. Use text input instead.")

    # This is hackish. `quote` requires `str` in both py27 and py3+.
    if isinstance(iri, str):
        # Python 3 branch
        return quote(iri, GEN_DELIMS + SUB_DELIMS + PERCENT_ENCODING_CHARACTER)
    else:
        # Python 2 branch
        return quote(iri.encode('utf-8'),

                     (GEN_DELIMS + SUB_DELIMS + PERCENT_ENCODING_CHARACTER).encode('utf-8')).decode('utf-8')