Mercurial > public > mercurial-scm > hg
comparison mercurial/wireprotoserver.py @ 35872:68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Plug in the abc module so we can have run-time validation of type
conformance.
Differential Revision: https://phab.mercurial-scm.org/D1990
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 31 Jan 2018 11:30:16 -0800 |
parents | 49ea1ba15ffd |
children | 29759c46aa1a |
comparison
equal
deleted
inserted
replaced
35871:49ea1ba15ffd | 35872:68dc621fa06c |
---|---|
4 # This software may be used and distributed according to the terms of the | 4 # This software may be used and distributed according to the terms of the |
5 # GNU General Public License version 2 or any later version. | 5 # GNU General Public License version 2 or any later version. |
6 | 6 |
7 from __future__ import absolute_import | 7 from __future__ import absolute_import |
8 | 8 |
9 import abc | |
9 import cgi | 10 import cgi |
10 import struct | 11 import struct |
11 import sys | 12 import sys |
12 | 13 |
13 from .i18n import _ | 14 from .i18n import _ |
35 """abstract class that summarizes the protocol API | 36 """abstract class that summarizes the protocol API |
36 | 37 |
37 Used as reference and documentation. | 38 Used as reference and documentation. |
38 """ | 39 """ |
39 | 40 |
41 __metaclass__ = abc.ABCMeta | |
42 | |
43 @abc.abstractmethod | |
40 def getargs(self, args): | 44 def getargs(self, args): |
41 """return the value for arguments in <args> | 45 """return the value for arguments in <args> |
42 | 46 |
43 returns a list of values (same order as <args>)""" | 47 returns a list of values (same order as <args>)""" |
44 raise NotImplementedError() | 48 |
45 | 49 @abc.abstractmethod |
46 def getfile(self, fp): | 50 def getfile(self, fp): |
47 """write the whole content of a file into a file like object | 51 """write the whole content of a file into a file like object |
48 | 52 |
49 The file is in the form:: | 53 The file is in the form:: |
50 | 54 |
51 (<chunk-size>\n<chunk>)+0\n | 55 (<chunk-size>\n<chunk>)+0\n |
52 | 56 |
53 chunk size is the ascii version of the int. | 57 chunk size is the ascii version of the int. |
54 """ | 58 """ |
55 raise NotImplementedError() | 59 |
56 | 60 @abc.abstractmethod |
57 def redirect(self): | 61 def redirect(self): |
58 """may setup interception for stdout and stderr | 62 """may setup interception for stdout and stderr |
59 | 63 |
60 See also the `restore` method.""" | 64 See also the `restore` method.""" |
61 raise NotImplementedError() | |
62 | 65 |
63 # If the `redirect` function does install interception, the `restore` | 66 # If the `redirect` function does install interception, the `restore` |
64 # function MUST be defined. If interception is not used, this function | 67 # function MUST be defined. If interception is not used, this function |
65 # MUST NOT be defined. | 68 # MUST NOT be defined. |
66 # | 69 # |