Mercurial > public > mercurial-scm > hg
comparison mercurial/wireprotoserver.py @ 35871:49ea1ba15ffd
wireprotoserver: make response handling attributes private
The send* methods are specific to sshserver and aren't part of the
common protocol interface. So rename them accordingly.
The handlers dict is also specific to sshserver and is related to
these methods. So give it the same treatment.
Differential Revision: https://phab.mercurial-scm.org/D1989
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 31 Jan 2018 11:26:03 -0800 |
parents | f1efc0caeab7 |
children | 68dc621fa06c |
comparison
equal
deleted
inserted
replaced
35870:f1efc0caeab7 | 35871:49ea1ba15ffd |
---|---|
281 val = self._fin.read(int(l)) | 281 val = self._fin.read(int(l)) |
282 data[arg] = val | 282 data[arg] = val |
283 return [data[k] for k in keys] | 283 return [data[k] for k in keys] |
284 | 284 |
285 def getfile(self, fpout): | 285 def getfile(self, fpout): |
286 self.sendresponse('') | 286 self._sendresponse('') |
287 count = int(self._fin.readline()) | 287 count = int(self._fin.readline()) |
288 while count: | 288 while count: |
289 fpout.write(self._fin.read(count)) | 289 fpout.write(self._fin.read(count)) |
290 count = int(self._fin.readline()) | 290 count = int(self._fin.readline()) |
291 | 291 |
292 def redirect(self): | 292 def redirect(self): |
293 pass | 293 pass |
294 | 294 |
295 def sendresponse(self, v): | 295 def _sendresponse(self, v): |
296 self._fout.write("%d\n" % len(v)) | 296 self._fout.write("%d\n" % len(v)) |
297 self._fout.write(v) | 297 self._fout.write(v) |
298 self._fout.flush() | 298 self._fout.flush() |
299 | 299 |
300 def sendstream(self, source): | 300 def _sendstream(self, source): |
301 write = self._fout.write | 301 write = self._fout.write |
302 for chunk in source.gen: | 302 for chunk in source.gen: |
303 write(chunk) | 303 write(chunk) |
304 self._fout.flush() | 304 self._fout.flush() |
305 | 305 |
306 def sendpushresponse(self, rsp): | 306 def _sendpushresponse(self, rsp): |
307 self.sendresponse('') | 307 self._sendresponse('') |
308 self.sendresponse(str(rsp.res)) | 308 self._sendresponse(str(rsp.res)) |
309 | 309 |
310 def sendpusherror(self, rsp): | 310 def _sendpusherror(self, rsp): |
311 self.sendresponse(rsp.res) | 311 self._sendresponse(rsp.res) |
312 | 312 |
313 def sendooberror(self, rsp): | 313 def _sendooberror(self, rsp): |
314 self._ui.ferr.write('%s\n-\n' % rsp.message) | 314 self._ui.ferr.write('%s\n-\n' % rsp.message) |
315 self._ui.ferr.flush() | 315 self._ui.ferr.flush() |
316 self._fout.write('\n') | 316 self._fout.write('\n') |
317 self._fout.flush() | 317 self._fout.flush() |
318 | 318 |
319 def serve_forever(self): | 319 def serve_forever(self): |
320 while self.serve_one(): | 320 while self.serve_one(): |
321 pass | 321 pass |
322 sys.exit(0) | 322 sys.exit(0) |
323 | 323 |
324 handlers = { | 324 _handlers = { |
325 str: sendresponse, | 325 str: _sendresponse, |
326 wireproto.streamres: sendstream, | 326 wireproto.streamres: _sendstream, |
327 wireproto.streamres_legacy: sendstream, | 327 wireproto.streamres_legacy: _sendstream, |
328 wireproto.pushres: sendpushresponse, | 328 wireproto.pushres: _sendpushresponse, |
329 wireproto.pusherr: sendpusherror, | 329 wireproto.pusherr: _sendpusherror, |
330 wireproto.ooberror: sendooberror, | 330 wireproto.ooberror: _sendooberror, |
331 } | 331 } |
332 | 332 |
333 def serve_one(self): | 333 def serve_one(self): |
334 cmd = self._fin.readline()[:-1] | 334 cmd = self._fin.readline()[:-1] |
335 if cmd and cmd in wireproto.commands: | 335 if cmd and cmd in wireproto.commands: |
336 rsp = wireproto.dispatch(self._repo, self, cmd) | 336 rsp = wireproto.dispatch(self._repo, self, cmd) |
337 self.handlers[rsp.__class__](self, rsp) | 337 self._handlers[rsp.__class__](self, rsp) |
338 elif cmd: | 338 elif cmd: |
339 self.sendresponse("") | 339 self._sendresponse("") |
340 return cmd != '' | 340 return cmd != '' |
341 | 341 |
342 def _client(self): | 342 def _client(self): |
343 client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] | 343 client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] |
344 return 'remote:ssh:' + client | 344 return 'remote:ssh:' + client |