def METHOD_NAME(shebang, encoding):
    # Python parser starts to read a script using UTF-8 until
    # it gets a #coding:xxx cookie. The shebang has to be the
    # first line of a file, the #coding:xxx cookie cannot be
    # written before. So the shebang has to be encodable to
    # UTF-8.
    try:
        shebang.encode('utf-8')
    except UnicodeEncodeError:
        raise ValueError(
            "The shebang ({!r}) is not encodable " "to utf-8".format(shebang)
        )
    # If the script is encoded to a custom encoding (use a
    # #coding:xxx cookie), the shebang has to be encodable to
    # the script encoding too.
    try:
        shebang.encode(encoding)
    except UnicodeEncodeError:
        raise ValueError(
            "The shebang ({!r}) is not encodable "
            "to the script encoding ({})".format(shebang, encoding)
        )