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.
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.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
star[arg] = val | star[arg] = val | ||||
data['*'] = star | data['*'] = star | ||||
else: | else: | ||||
val = self._fin.read(int(l)) | val = self._fin.read(int(l)) | ||||
data[arg] = val | data[arg] = val | ||||
return [data[k] for k in keys] | return [data[k] for k in keys] | ||||
def getfile(self, fpout): | def getfile(self, fpout): | ||||
self.sendresponse('') | self._sendresponse('') | ||||
count = int(self._fin.readline()) | count = int(self._fin.readline()) | ||||
while count: | while count: | ||||
fpout.write(self._fin.read(count)) | fpout.write(self._fin.read(count)) | ||||
count = int(self._fin.readline()) | count = int(self._fin.readline()) | ||||
def redirect(self): | def redirect(self): | ||||
pass | pass | ||||
def sendresponse(self, v): | def _sendresponse(self, v): | ||||
self._fout.write("%d\n" % len(v)) | self._fout.write("%d\n" % len(v)) | ||||
self._fout.write(v) | self._fout.write(v) | ||||
self._fout.flush() | self._fout.flush() | ||||
def sendstream(self, source): | def _sendstream(self, source): | ||||
write = self._fout.write | write = self._fout.write | ||||
for chunk in source.gen: | for chunk in source.gen: | ||||
write(chunk) | write(chunk) | ||||
self._fout.flush() | self._fout.flush() | ||||
def sendpushresponse(self, rsp): | def _sendpushresponse(self, rsp): | ||||
self.sendresponse('') | self._sendresponse('') | ||||
self.sendresponse(str(rsp.res)) | self._sendresponse(str(rsp.res)) | ||||
def sendpusherror(self, rsp): | def _sendpusherror(self, rsp): | ||||
self.sendresponse(rsp.res) | self._sendresponse(rsp.res) | ||||
def sendooberror(self, rsp): | def _sendooberror(self, rsp): | ||||
self._ui.ferr.write('%s\n-\n' % rsp.message) | self._ui.ferr.write('%s\n-\n' % rsp.message) | ||||
self._ui.ferr.flush() | self._ui.ferr.flush() | ||||
self._fout.write('\n') | self._fout.write('\n') | ||||
self._fout.flush() | self._fout.flush() | ||||
def serve_forever(self): | def serve_forever(self): | ||||
while self.serve_one(): | while self.serve_one(): | ||||
pass | pass | ||||
sys.exit(0) | sys.exit(0) | ||||
handlers = { | _handlers = { | ||||
str: sendresponse, | str: _sendresponse, | ||||
wireproto.streamres: sendstream, | wireproto.streamres: _sendstream, | ||||
wireproto.streamres_legacy: sendstream, | wireproto.streamres_legacy: _sendstream, | ||||
wireproto.pushres: sendpushresponse, | wireproto.pushres: _sendpushresponse, | ||||
wireproto.pusherr: sendpusherror, | wireproto.pusherr: _sendpusherror, | ||||
wireproto.ooberror: sendooberror, | wireproto.ooberror: _sendooberror, | ||||
} | } | ||||
def serve_one(self): | def serve_one(self): | ||||
cmd = self._fin.readline()[:-1] | cmd = self._fin.readline()[:-1] | ||||
if cmd and cmd in wireproto.commands: | if cmd and cmd in wireproto.commands: | ||||
rsp = wireproto.dispatch(self._repo, self, cmd) | rsp = wireproto.dispatch(self._repo, self, cmd) | ||||
self.handlers[rsp.__class__](self, rsp) | self._handlers[rsp.__class__](self, rsp) | ||||
elif cmd: | elif cmd: | ||||
self.sendresponse("") | self._sendresponse("") | ||||
return cmd != '' | return cmd != '' | ||||
def _client(self): | def _client(self): | ||||
client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] | client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] | ||||
return 'remote:ssh:' + client | return 'remote:ssh:' + client |