Mercurial > hg
comparison mercurial/wireprotoserver.py @ 37296:78103e4138b1
wireproto: port protocol handler to zope.interface
zope.interface is superior to the abc module. Let's port to it.
As part of this, we add tests for interface conformance for
classes implementing the interface.
Differential Revision: https://phab.mercurial-scm.org/D2983
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 23 Mar 2018 16:24:53 -0700 |
parents | 45b39c69fae0 |
children | afcfdf53e4b5 |
comparison
equal
deleted
inserted
replaced
37295:45b39c69fae0 | 37296:78103e4138b1 |
---|---|
10 import struct | 10 import struct |
11 import sys | 11 import sys |
12 import threading | 12 import threading |
13 | 13 |
14 from .i18n import _ | 14 from .i18n import _ |
15 from .thirdparty.zope import ( | |
16 interface as zi, | |
17 ) | |
15 from . import ( | 18 from . import ( |
16 encoding, | 19 encoding, |
17 error, | 20 error, |
18 hook, | 21 hook, |
19 pycompat, | 22 pycompat, |
56 chunks.append(pycompat.bytesurl(v)) | 59 chunks.append(pycompat.bytesurl(v)) |
57 i += 1 | 60 i += 1 |
58 | 61 |
59 return ''.join(chunks) | 62 return ''.join(chunks) |
60 | 63 |
61 class httpv1protocolhandler(wireprototypes.baseprotocolhandler): | 64 @zi.implementer(wireprototypes.baseprotocolhandler) |
65 class httpv1protocolhandler(object): | |
62 def __init__(self, req, ui, checkperm): | 66 def __init__(self, req, ui, checkperm): |
63 self._req = req | 67 self._req = req |
64 self._ui = ui | 68 self._ui = ui |
65 self._checkperm = checkperm | 69 self._checkperm = checkperm |
66 | 70 |
572 'config': ('experimental', 'web.api.http-v2'), | 576 'config': ('experimental', 'web.api.http-v2'), |
573 'handler': _handlehttpv2request, | 577 'handler': _handlehttpv2request, |
574 }, | 578 }, |
575 } | 579 } |
576 | 580 |
577 class httpv2protocolhandler(wireprototypes.baseprotocolhandler): | 581 @zi.implementer(wireprototypes.baseprotocolhandler) |
582 class httpv2protocolhandler(object): | |
578 def __init__(self, req, ui, args=None): | 583 def __init__(self, req, ui, args=None): |
579 self._req = req | 584 self._req = req |
580 self._ui = ui | 585 self._ui = ui |
581 self._args = args | 586 self._args = args |
582 | 587 |
735 ferr.write(b'%s\n-\n' % rsp) | 740 ferr.write(b'%s\n-\n' % rsp) |
736 ferr.flush() | 741 ferr.flush() |
737 fout.write(b'\n') | 742 fout.write(b'\n') |
738 fout.flush() | 743 fout.flush() |
739 | 744 |
740 class sshv1protocolhandler(wireprototypes.baseprotocolhandler): | 745 @zi.implementer(wireprototypes.baseprotocolhandler) |
746 class sshv1protocolhandler(object): | |
741 """Handler for requests services via version 1 of SSH protocol.""" | 747 """Handler for requests services via version 1 of SSH protocol.""" |
742 def __init__(self, ui, fin, fout): | 748 def __init__(self, ui, fin, fout): |
743 self._ui = ui | 749 self._ui = ui |
744 self._fin = fin | 750 self._fin = fin |
745 self._fout = fout | 751 self._fout = fout |