def METHOD_NAME(self, idna_encoder=None):  # noqa: C901
    """Encode an IRIReference into a URIReference instance.
    If the ``idna`` module is installed or the ``rfc3986[idna]``
    extra is used then unicode characters in the IRI host
    component will be encoded with IDNA2008.
    :param idna_encoder:
        Function that encodes each part of the host component
        If not given will raise an exception if the IRI
        contains a host component.
    :rtype: uri.URIReference
    :returns: A URI reference
    """
    authority = self.authority
    if authority:
        if idna_encoder is None:
            if idna is None:  # pragma: no cover
                raise exceptions.MissingDependencyError(
                    "Could not import the 'idna' module "
                    "and the IRI hostname requires encoding"
                )
            def idna_encoder(name):
                if any(ord(c) > 128 for c in name):
                    try:
                        return idna.METHOD_NAME(name.lower(),
                                           strict=True,
                                           std3_rules=True)
                    except idna.IDNAError:
                        raise exceptions.InvalidAuthority(self.authority)
                return name
        authority = ""
        if self.host:
            authority = ".".join([compat.to_str(idna_encoder(part))
                                  for part in self.host.split(".")])
        if self.userinfo is not None:
            authority = (normalizers.encode_component(
                         self.userinfo, self.encoding) + '@' + authority)
        if self.port is not None:
            authority += ":" + str(self.port)
    return uri.URIReference(self.scheme,
                            authority,
                            path=self.path,
                            query=self.query,
                            fragment=self.fragment,
                            encoding=self.encoding)