code: def iri_to_uri(iri, charset='utf-8', errors='strict'):
      r
      if isinstance(iri, tuple):
          iri = url_unparse(iri)
      iri = url_parse(to_unicode(iri, charset, errors))
  
      netloc = iri.encode_netloc().decode('ascii')
      path = url_quote(iri.path, charset, errors, '/:~+%')
      query = url_quote(iri.query, charset, errors, '%&[]:;$*()+,!?*/=')
      fragment = url_quote(iri.fragment, charset, errors, '=%&[]:;$()+,!?*/')
  
      return to_native(url_unparse((iri.scheme, netloc,
                                    path, query, fragment)))
docs: r"""
      Converts any unicode based IRI to an acceptable ASCII URI. Werkzeug always
      uses utf-8 URLs internally because this is what browsers and HTTP do as
      well. In some places where it accepts an URL it also accepts a unicode IRI
      and converts it into a URI.
  
      Examples for IRI versus URI:
  
      >>> iri_to_uri(u'http://☃.net/')
      'http://xn--n3h.net/'
      >>> iri_to_uri(u'http://üser:pässword@☃.net/påth')
      'http://%C3%BCser:p%C3%A4ssword@xn--n3h.net/p%C3%A5th'
  
      .. versionadded:: 0.6
  
      :param iri: The IRI to convert.
      :param charset: The charset for the URI.