Mercurial > public > mercurial-scm > hg-stable
comparison tests/sshprotoext.py @ 35977:a9cffd14aa04
sshpeer: inline I/O into _validaterepo()
We want to move the handshake code out of the peer class so the
peer factory function can perform the handshake and instantiate
a proper class depending on the results. To make that refactor
easier to read, we first inline I/O functionality into
_validaterepo().
Test output for low-level protocol tests didn't change, thus
hopefully demonstrating that this refactor didn't change any
material behavior.
Because we no longer call _callstream(), our test extension for
monkeypatching the peer had to change its hook point.
Differential Revision: https://phab.mercurial-scm.org/D2033
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 04 Feb 2018 14:10:56 -0800 |
parents | 83d67257ba90 |
children | 80a2b8ae42a1 |
comparison
equal
deleted
inserted
replaced
35976:f8f034344b39 | 35977:a9cffd14aa04 |
---|---|
52 | 52 |
53 super(prehelloserver, self).serve_forever() | 53 super(prehelloserver, self).serve_forever() |
54 | 54 |
55 class extrahandshakecommandspeer(sshpeer.sshpeer): | 55 class extrahandshakecommandspeer(sshpeer.sshpeer): |
56 """An ssh peer that sends extra commands as part of initial handshake.""" | 56 """An ssh peer that sends extra commands as part of initial handshake.""" |
57 # There isn't a good hook point. So we wrap _callstream() and inject | 57 def _validaterepo(self): |
58 # logic when the peer says "hello". | |
59 def _callstream(self, cmd, **args): | |
60 if cmd != b'hello': | |
61 return super(extrahandshakecommandspeer, self)._callstream(cmd, | |
62 **args) | |
63 | |
64 mode = self._ui.config(b'sshpeer', b'handshake-mode') | 58 mode = self._ui.config(b'sshpeer', b'handshake-mode') |
65 if mode == b'pre-no-args': | 59 if mode == b'pre-no-args': |
66 self._callstream(b'no-args') | 60 self._callstream(b'no-args') |
67 return super(extrahandshakecommandspeer, self)._callstream( | 61 return super(extrahandshakecommandspeer, self)._validaterepo() |
68 cmd, **args) | |
69 elif mode == b'pre-multiple-no-args': | 62 elif mode == b'pre-multiple-no-args': |
70 self._callstream(b'unknown1') | 63 self._callstream(b'unknown1') |
71 self._callstream(b'unknown2') | 64 self._callstream(b'unknown2') |
72 self._callstream(b'unknown3') | 65 self._callstream(b'unknown3') |
73 return super(extrahandshakecommandspeer, self)._callstream( | 66 return super(extrahandshakecommandspeer, self)._validaterepo() |
74 cmd, **args) | |
75 else: | 67 else: |
76 raise error.ProgrammingError(b'unknown HANDSHAKECOMMANDMODE: %s' % | 68 raise error.ProgrammingError(b'unknown HANDSHAKECOMMANDMODE: %s' % |
77 mode) | 69 mode) |
78 | 70 |
79 def registercommands(): | 71 def registercommands(): |