human
I wrote the below code

    if (direction not in (DOWNLOAD, UPLOAD)):
        raise ValueError('Invalid    direction    argument    {!r}.    Must    be    one    of    ``runner.DOWNLOAD``    or    ``runner.UPLOAD``.'.format(direction))
    remote_host_path = ((((username + '@') + host) + ':') + remote_path.path)
    scp_command = (['scp', '-r', '-P', bytes(port)] + SSH_OPTIONS)
    if (identity_file is not None):
        scp_command += ['-i', identity_file.path]
    if (direction is DOWNLOAD):
        scp_command += [remote_host_path, local_path.path]
    else:
        scp_command += [local_path.path, remote_host_path]
    action = SCP_ACTION(username=username, host=host, remote_path=remote_path, local_path=local_path, port=port, identity_file=identity_file)
    failed_reason = []
    def handle_stdout(line):
        SCP_OUTPUT_MESSAGE(line=line).write(action=action)
    def handle_stderr(line):
        "\n                                Notice    scp's    particular    way    of    describing    the    file-not-found    condition\n                                and    turn    it    into    a    more    easily    recognized    form.\n                                "
        if ('No    such    file    or    directory' in line):
            failed_reason.append(RemoteFileNotFound(remote_path))
        if ('lost    connection' in line):
            failed_reason.append(SCPConnectionError())
        SCP_ERROR_MESSAGE(line=line).write(action=action)
    def scp_failed(reason):
        '\n                                Check    for    a    known    error    with    the    scp    attempt    and    turn    the    normal\n                                failure    into    a    more    meaningful    one.\n                                '
        reason.trap(ProcessTerminated)
        if failed_reason:
            return Failure(failed_reason[(-1)])
        return reason
    with action.context():
        context = DeferredContext(run(reactor, scp_command, handle_stdout=handle_stdout, handle_stderr=handle_stderr))
       ...

What's a good function header?
assistant
#Here's a good function header.

def scp(reactor, username, host, remote_path, local_path, direction, port=22, identity_file=None):