Show More
@@ -49,15 +49,6 b' class iterbatcher(batcher):' | |||
|
49 | 49 | def results(self): |
|
50 | 50 | raise NotImplementedError() |
|
51 | 51 | |
|
52 | class localbatch(batcher): | |
|
53 | '''performs the queued calls directly''' | |
|
54 | def __init__(self, local): | |
|
55 | batcher.__init__(self) | |
|
56 | self.local = local | |
|
57 | def submit(self): | |
|
58 | for name, args, opts, resref in self.calls: | |
|
59 | resref.set(getattr(self.local, name)(*args, **opts)) | |
|
60 | ||
|
61 | 52 | class localiterbatcher(iterbatcher): |
|
62 | 53 | def __init__(self, local): |
|
63 | 54 | super(iterbatcher, self).__init__() |
@@ -106,10 +97,6 b' def batchable(f):' | |||
|
106 | 97 | return plain |
|
107 | 98 | |
|
108 | 99 | class peerrepository(object): |
|
109 | ||
|
110 | def batch(self): | |
|
111 | return localbatch(self) | |
|
112 | ||
|
113 | 100 | def iterbatch(self): |
|
114 | 101 | """Batch requests but allow iterating over the results. |
|
115 | 102 |
@@ -8,7 +8,6 b'' | |||
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import hashlib |
|
11 | import itertools | |
|
12 | 11 | import os |
|
13 | 12 | import tempfile |
|
14 | 13 | |
@@ -80,38 +79,6 b' class abstractserverproto(object):' | |||
|
80 | 79 | # """ |
|
81 | 80 | # raise NotImplementedError() |
|
82 | 81 | |
|
83 | class remotebatch(peer.batcher): | |
|
84 | '''batches the queued calls; uses as few roundtrips as possible''' | |
|
85 | def __init__(self, remote): | |
|
86 | '''remote must support _submitbatch(encbatch) and | |
|
87 | _submitone(op, encargs)''' | |
|
88 | peer.batcher.__init__(self) | |
|
89 | self.remote = remote | |
|
90 | def submit(self): | |
|
91 | req, rsp = [], [] | |
|
92 | for name, args, opts, resref in self.calls: | |
|
93 | mtd = getattr(self.remote, name) | |
|
94 | batchablefn = getattr(mtd, 'batchable', None) | |
|
95 | if batchablefn is not None: | |
|
96 | batchable = batchablefn(mtd.im_self, *args, **opts) | |
|
97 | encargsorres, encresref = next(batchable) | |
|
98 | assert encresref | |
|
99 | req.append((name, encargsorres,)) | |
|
100 | rsp.append((batchable, encresref, resref,)) | |
|
101 | else: | |
|
102 | if req: | |
|
103 | self._submitreq(req, rsp) | |
|
104 | req, rsp = [], [] | |
|
105 | resref.set(mtd(*args, **opts)) | |
|
106 | if req: | |
|
107 | self._submitreq(req, rsp) | |
|
108 | def _submitreq(self, req, rsp): | |
|
109 | encresults = self.remote._submitbatch(req) | |
|
110 | for encres, r in zip(encresults, rsp): | |
|
111 | batchable, encresref, resref = r | |
|
112 | encresref.set(encres) | |
|
113 | resref.set(next(batchable)) | |
|
114 | ||
|
115 | 82 | class remoteiterbatcher(peer.iterbatcher): |
|
116 | 83 | def __init__(self, remote): |
|
117 | 84 | super(remoteiterbatcher, self).__init__() |
@@ -253,11 +220,6 b' class wirepeer(peer.peerrepository):' | |||
|
253 | 220 | See also httppeer.py and sshpeer.py for protocol-specific |
|
254 | 221 | implementations of this interface. |
|
255 | 222 | """ |
|
256 | def batch(self): | |
|
257 | if self.capable('batch'): | |
|
258 | return remotebatch(self) | |
|
259 | else: | |
|
260 | return peer.localbatch(self) | |
|
261 | 223 | def _submitbatch(self, req): |
|
262 | 224 | """run batch request <req> on the server |
|
263 | 225 |
@@ -55,7 +55,7 b' srv = serverrepo()' | |||
|
55 | 55 | clt = clientpeer(srv) |
|
56 | 56 | |
|
57 | 57 | print(clt.greet("Foobar")) |
|
58 | b = clt.batch() | |
|
59 | fs = [b.greet(s) for s in ["Fo, =;:<o", "Bar"]] | |
|
58 | b = clt.iterbatch() | |
|
59 | map(b.greet, ('Fo, =;:<o', 'Bar')) | |
|
60 | 60 | b.submit() |
|
61 |
print([ |
|
|
61 | print([r for r in b.results()]) |
General Comments 0
You need to be logged in to leave comments.
Login now