tests/test-wireproto.py
author wujek srujek <wujek.srujek@googlemail.com>
Tue, 31 Jul 2012 00:59:38 +0200
branchstable
changeset 17303 06217d3cf8d9
parent 17192 1ac628cd7113
child 18278 753acee7d6dd
permissions -rw-r--r--
hgweb: fixes invalid parents / children in comparison Previously, the parents / children were computed relative to the cset of the currently shown file, which was wrong and inconsistent with diff and others. With this patch, the listed csets are those that contain changes to the currently compared file, which don't necessarily have to be the direct parents and children of the changeset itself.

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 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]