view tests/test-wireproto.py @ 18796:fa6d5c62f3bd

pathcomplete: complete directories more conservatively Suppose we want to perform a single-level completion (i.e. without --full) of "fi" in a repo containing "fee", "fie/dead", "fie/live", and "foe". If we give back "fie/" as the only answer, the shell will consider the completion to be unambiguous, and will append a space after the completion. We can't complete "fie/live" or "fie/dead" without first backspacing over that space. We used to thus create two fake names, "fie/a" and "fie/b", to force the shell to consider the completion to be ambiguous. It would then stop at "fie/" without appending a space, allowing us to hit tab again to complete "fie/live" or "fie/dead". The change here arises from realising that we only need to force the shell to consider a completion as ambiguous if we have exactly one directory and zero files as possible completions. This prevents spurious names from showing up as possible completions when they don't need to be invented in the first place.
author Bryan O'Sullivan <bryano@fb.com>
date Thu, 21 Mar 2013 22:10:54 -0700
parents 753acee7d6dd
children c69f62906358
line wrap: on
line source

from mercurial import wireproto

class proto(object):
    def __init__(self, args):
        self.args = args
    def getargs(self, spec):
        args = self.args
        args.setdefault('*', {})
        names = spec.split()
        return [args[n] for n in names]

class clientpeer(wireproto.wirepeer):
    def __init__(self, serverrepo):
        self.serverrepo = serverrepo
    def _call(self, cmd, **args):
        return wireproto.dispatch(self.serverrepo, proto(args), cmd)

    @wireproto.batchable
    def greet(self, name):
        f = wireproto.future()
        yield wireproto.todict(name=mangle(name)), f
        yield unmangle(f.value)

class serverrepo(object):
    def greet(self, name):
        return "Hello, " + name

    def filtered(self, name):
        return self

def mangle(s):
    return ''.join(chr(ord(c) + 1) for c in s)
def unmangle(s):
    return ''.join(chr(ord(c) - 1) for c in s)

def greet(repo, proto, name):
    return mangle(repo.greet(unmangle(name)))

wireproto.commands['greet'] = (greet, 'name',)

srv = serverrepo()
clt = clientpeer(srv)

print clt.greet("Foobar")
b = clt.batch()
fs = [b.greet(s) for s in ["Fo, =;o", "Bar"]]
b.submit()
print [f.value for f in fs]