def METHOD_NAME(filename=None, verbose=False, python_interpreter='/usr/bin/python'):
    if not filename:
        if verbose:
            sys.stdout.write('filename not provided\n')
        return 1
    # open input file
    try:
        infile = open(filename, 'rb')
    except IOError as msg:
        sys.stderr.write('%s: open failed: %r\n' % (filename, msg))
        return 1
    # process first line
    try:
        firstline = infile.readline()
    except IOError as msg:
        sys.stderr.write('%s: read failed: %r\n' % (filename, msg))
        try:
            infile.close()
        except IOError as msg:
            sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
        return 1
    if firstline.rstrip(b'\n').find(b' -') != -1:
        existingargs = firstline.rstrip(b'\n')[firstline.rstrip(b'\n').find(b' -'):]
    else:
        existingargs = b''
    newline = b'#!' + python_interpreter + existingargs + b'\n'
    if (not firstline.startswith(b'#!')) or (b"python" not in firstline) or (firstline == newline):
        if verbose:
            sys.stdout.write('%s: unchanged\n' % (filename))
        try:
            infile.close()
        except IOError as msg:
            sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
        return 0
    # create temporary output
    head, tail = os.path.split(filename)
    tempname = os.path.join(head, '@' + tail)
    try:
        outfile = open(tempname, 'wb')
    except IOError as msg:
        sys.stderr.write('%s: create failed: %r\n' % (tempname, msg))
        try:
            infile.close()
        except IOError as msg:
            sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
        return 1
    if verbose:
        sys.stdout.write('%s: updating\n' % (filename))
    # write first new line to temporary output
    try:
        outfile.write(newline)
    except IOError as msg:
        sys.stderr.write('%s: write failed: %r\n' % (tempname, msg))
        try:
            infile.close()
        except IOError as msg:
            sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
        try:
            outfile.close()
        except IOError as msg:
            sys.stderr.write('%s: close failed: %r\n' % (tempname, msg))
        return 1
    # copy rest of file
    while True:
        try:
            chunk = infile.read(32678)
        except IOError as msg:
            sys.stderr.write('%s: read failed: %r\n' % (filename, msg))
            try:
                infile.close()
            except IOError as msg:
                sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
            try:
                outfile.close()
            except IOError as msg:
                sys.stderr.write('%s: close failed: %r\n' % (tempname, msg))
            try:
                os.remove(tempname)
            except OSError as msg:
                sys.stderr.write('%s: remove failed: %r\n' % (tempname, msg))
            return 1
        if not chunk:
            break
        try:
            outfile.write(chunk)
        except IOError as msg:
            sys.stderr.write('%s: write failed: %r\n' % (tempname, msg))
            try:
                infile.close()
            except IOError as msg:
                sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
            try:
                outfile.close()
            except IOError as msg:
                sys.stderr.write('%s: close failed: %r\n' % (tempname, msg))
            try:
                os.remove(tempname)
            except OSError as msg:
                sys.stderr.write('%s: remove failed: %r\n' % (tempname, msg))
            return 1
    # close files
    try:
        infile.close()
    except IOError as msg:
        sys.stderr.write('%s: close failed: %r\n' % (filename, msg))
        try:
            outfile.close()
        except IOError as msg:
            sys.stderr.write('%s: close failed: %r\n' % (tempname, msg))
        try:
            os.remove(tempname)
        except OSError as msg:
            sys.stderr.write('%s: remove failed: %r\n' % (tempname, msg))
        return 1
    try:
        outfile.close()
    except IOError as msg:
        sys.stderr.write('%s: close failed: %r\n' % (tempname, msg))
        try:
            os.remove(tempname)
        except OSError as msg:
            sys.stderr.write('%s: remove failed: %r\n' % (tempname, msg))
        return 1
    # copy the file's mode to the temp file
    try:
        statbuf = os.stat(filename)
        os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
    except OSError as msg:
        sys.stderr.write('%s: warning, chmod failed: %r\n' % (tempname, msg))
    # Remove original file
    try:
        os.remove(filename)
    except OSError as msg:
        sys.stderr.write('%s: remove failed: %r\n' % (filename, msg))
        try:
            os.remove(tempname)
        except OSError as msg:
            sys.stderr.write('%s: remove failed: %r\n' % (tempname, msg))
        return 1
    # move the temp file to the original file
    try:
        os.rename(tempname, filename)
    except OSError as msg:
        sys.stderr.write('%s: rename failed: %r\n' % (filename, msg))
        # leave the tempname alone (might be used for recovery)
        return 1
    return 0