human
I wrote the below code

    assert (not re.search('[^\\w-]', subcmd))
    nicedir = re.sub(':', '_', path.exedir())
    if (rhost == '-'):
        rhost = None
    if (not rhost):
        argv = ['bup', subcmd]
    else:
        escapedir = re.sub('([^\\w/])', '\\\\\\\\\\\\\\1', nicedir)
        buglvl = helpers.atoi(os.environ.get('BUP_DEBUG'))
        force_tty = helpers.atoi(os.environ.get('BUP_FORCE_TTY'))
        cmd = ("\n                                                                            sh    -c    PATH=%s:'$PATH    BUP_DEBUG=%s    BUP_FORCE_TTY=%s    bup    %s'\n                                                            " % (escapedir, buglvl, force_tty, subcmd))
        argv = ['ssh']
        if port:
            argv.extend(('-p', port))
        argv.extend((rhost, '--', cmd.strip()))
    def setup():
        if (not rhost):
            os.environ['PATH'] = ':'.join([nicedir, os.environ.get('PATH', '')])
        os.setsid()
    return subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, preexec_fn=setup)

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

def connect(rhost, port, subcmd, stderr=None):