# Path: werkzeug/_compat.py
# PY2 = sys.version_info[0] == 2
#     def fix_tuple_repr(obj):
#         def __repr__(self):
#     def implements_iterator(cls):
#     def implements_to_string(cls):
#     def native_string_result(func):
#         def wrapper(*args, **kwargs):
#     def implements_bool(cls):
#     def make_literal_wrapper(reference):
#     def normalize_string_tuple(tup):
#     def try_coerce_native(s):
#     def wsgi_decoding_dance(s, charset='utf-8', errors='replace'):
#     def wsgi_encoding_dance(s, charset='utf-8', errors='replace'):
#     def to_bytes(x, charset=sys.getdefaultencoding(), errors='strict'):
#     def to_native(x, charset=sys.getdefaultencoding(), errors='strict'):
#     def iter_bytes(b):
#     def reraise(tp, value, tb=None):
#     def make_literal_wrapper(reference):
#     def normalize_string_tuple(tup):
#     def wsgi_get_bytes(s):
#     def wsgi_decoding_dance(s, charset='utf-8', errors='replace'):
#     def wsgi_encoding_dance(s, charset='utf-8', errors='replace'):
#     def to_bytes(x, charset=sys.getdefaultencoding(), errors='strict'):
#     def to_native(x, charset=sys.getdefaultencoding(), errors='strict'):
# def to_unicode(x, charset=sys.getdefaultencoding(), errors='strict',
#                allow_none_charset=False):
# 
# Path: werkzeug/_internal.py
# def _encode_idna(domain):
#     # If we're given bytes, make sure they fit into ASCII
#     if not isinstance(domain, text_type):
#         domain.decode('ascii')
#         return domain
# 
#     # Otherwise check if it's already ascii, then return
#     try:
#         return domain.encode('ascii')
#     except UnicodeError:
#         pass
# 
#     # Otherwise encode each part separately
#     parts = domain.split('.')
#     for idx, part in enumerate(parts):
#         parts[idx] = part.encode('idna')
#     return b'.'.join(parts)
# 
# def _decode_idna(domain):
#     # If the input is a string try to encode it to ascii to
#     # do the idna decoding.  if that fails because of an
#     # unicode error, then we already have a decoded idna domain
#     if isinstance(domain, text_type):
#         try:
#             domain = domain.encode('ascii')
#         except UnicodeError:
#             return domain
# 
#     # Decode each part separately.  If a part fails, try to
#     # decode it with ascii and silently ignore errors.  This makes
#     # most sense because the idna codec does not have error handling
#     parts = domain.split(b'.')
#     for idx, part in enumerate(parts):
#         try:
#             parts[idx] = part.decode('idna')
#         except UnicodeError:
#             parts[idx] = part.decode('ascii', 'ignore')
# 
#     return '.'.join(parts)


import re
from werkzeug._compat import text_type, PY2, to_unicode, \
     to_native, implements_to_string, try_coerce_native, \
     normalize_string_tuple, make_literal_wrapper, \
     fix_tuple_repr
from werkzeug._internal import _encode_idna, _decode_idna
from werkzeug.datastructures import MultiDict, iter_multi_items
from collections import namedtuple
    from werkzeug.wsgi import make_chunk_iter

_URLTuple = fix_tuple_repr(namedtuple('_URLTuple',
    ['scheme', 'netloc', 'path', 'query', 'fragment']))


class _URLMixin(object):
    __slots__ = ()

    def replace(self, **kwargs):
        """Return an URL with the same values, except for those parameters
        given new values by whichever keyword arguments are specified."""
        return self._replace(**kwargs)

    @property
    def host(self):
        """The host part of the URL if available, otherwise `None`.  The
        host is either the hostname or the IP address mentioned in the
        URL.  It will not contain the port.
        """
        return self._split_host()[0]

    @property
    def ascii_host(self):
        """Works exactly like :attr:`host` but will return a result that
        is restricted to ASCII.  If it finds a netloc that is not ASCII
        it will attempt to idna decode it.  This is useful for socket
        operations when the URL might include internationalized characters.
        """
        rv = self.host
        if rv is not None and isinstance(rv, text_type):

# Path: werkzeug/_compat.py
# PY2 = sys.version_info[0] == 2
#     def fix_tuple_repr(obj):
#         def __repr__(self):
#     def implements_iterator(cls):
#     def implements_to_string(cls):
#     def native_string_result(func):
#         def wrapper(*args, **kwargs):
#     def implements_bool(cls):
#     def make_literal_wrapper(reference):
#     def normalize_string_tuple(tup):
#     def try_coerce_native(s):
#     def wsgi_decoding_dance(s, charset='utf-8', errors='replace'):
#     def wsgi_encoding_dance(s, charset='utf-8', errors='replace'):
#     def to_bytes(x, charset=sys.getdefaultencoding(), errors='strict'):
#     def to_native(x, charset=sys.getdefaultencoding(), errors='strict'):
#     def iter_bytes(b):
#     def reraise(tp, value, tb=None):
#     def make_literal_wrapper(reference):
#     def normalize_string_tuple(tup):
#     def wsgi_get_bytes(s):
#     def wsgi_decoding_dance(s, charset='utf-8', errors='replace'):
#     def wsgi_encoding_dance(s, charset='utf-8', errors='replace'):
#     def to_bytes(x, charset=sys.getdefaultencoding(), errors='strict'):
#     def to_native(x, charset=sys.getdefaultencoding(), errors='strict'):
# def to_unicode(x, charset=sys.getdefaultencoding(), errors='strict',
#                allow_none_charset=False):
# 
# Path: werkzeug/_internal.py
# def _encode_idna(domain):
#     # If we're given bytes, make sure they fit into ASCII
#     if not isinstance(domain, text_type):
#         domain.decode('ascii')
#         return domain
# 
#     # Otherwise check if it's already ascii, then return
#     try:
#         return domain.encode('ascii')
#     except UnicodeError:
#         pass
# 
#     # Otherwise encode each part separately
#     parts = domain.split('.')
#     for idx, part in enumerate(parts):
#         parts[idx] = part.encode('idna')
#     return b'.'.join(parts)
# 
# def _decode_idna(domain):
#     # If the input is a string try to encode it to ascii to
#     # do the idna decoding.  if that fails because of an
#     # unicode error, then we already have a decoded idna domain
#     if isinstance(domain, text_type):
#         try:
#             domain = domain.encode('ascii')
#         except UnicodeError:
#             return domain
# 
#     # Decode each part separately.  If a part fails, try to
#     # decode it with ascii and silently ignore errors.  This makes
#     # most sense because the idna codec does not have error handling
#     parts = domain.split(b'.')
#     for idx, part in enumerate(parts):
#         try:
#             parts[idx] = part.decode('idna')
#         except UnicodeError:
#             parts[idx] = part.decode('ascii', 'ignore')
# 
#     return '.'.join(parts)


# Path: werkzeug/urls.py
import re
from werkzeug._compat import text_type, PY2, to_unicode, \
     to_native, implements_to_string, try_coerce_native, \
     normalize_string_tuple, make_literal_wrapper, \
     fix_tuple_repr
from werkzeug._internal import _encode_idna, _decode_idna
from werkzeug.datastructures import MultiDict, iter_multi_items
from collections import namedtuple
    from werkzeug.wsgi import make_chunk_iter


_URLTuple = fix_tuple_repr(namedtuple('_URLTuple',
    ['scheme', 'netloc', 'path', 'query', 'fragment']))


class _URLMixin(object):
    __slots__ = ()

    def replace(self, **kwargs):
        """Return an URL with the same values, except for those parameters
        given new values by whichever keyword arguments are specified."""
        return self._replace(**kwargs)

    @property
    def host(self):
        """The host part of the URL if available, otherwise `None`.  The
        host is either the hostname or the IP address mentioned in the
        URL.  It will not contain the port.
        """
        return self._split_host()[0]

    @property
    def ascii_host(self):
        """Works exactly like :attr:`host` but will return a result that
        is restricted to ASCII.  If it finds a netloc that is not ASCII
        it will attempt to idna decode it.  This is useful for socket
        operations when the URL might include internationalized characters.
        """
        rv = self.host
        if rv is not None and isinstance(rv, text_type):

            rv = _encode_idna(rv)