Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/wireprototypes.py @ 36402:0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
This is needed to prevent a cycle in an upcoming commit.
Differential Revision: https://phab.mercurial-scm.org/D2384
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 21 Feb 2018 14:21:05 -0800 |
parents | 2f7290555c96 |
children | 3cd245945ef3 |
comparison
equal
deleted
inserted
replaced
36401:11ba1a96f946 | 36402:0c231df1ffdc |
---|---|
2 # | 2 # |
3 # This software may be used and distributed according to the terms of the | 3 # This software may be used and distributed according to the terms of the |
4 # GNU General Public License version 2 or any later version. | 4 # GNU General Public License version 2 or any later version. |
5 | 5 |
6 from __future__ import absolute_import | 6 from __future__ import absolute_import |
7 | |
8 import abc | |
7 | 9 |
8 class bytesresponse(object): | 10 class bytesresponse(object): |
9 """A wire protocol response consisting of raw bytes.""" | 11 """A wire protocol response consisting of raw bytes.""" |
10 def __init__(self, data): | 12 def __init__(self, data): |
11 self.data = data | 13 self.data = data |
62 Like ``streamres``, but sends an uncompressed data for "version 1" clients | 64 Like ``streamres``, but sends an uncompressed data for "version 1" clients |
63 using the application/mercurial-0.1 media type. | 65 using the application/mercurial-0.1 media type. |
64 """ | 66 """ |
65 def __init__(self, gen=None): | 67 def __init__(self, gen=None): |
66 self.gen = gen | 68 self.gen = gen |
69 | |
70 class baseprotocolhandler(object): | |
71 """Abstract base class for wire protocol handlers. | |
72 | |
73 A wire protocol handler serves as an interface between protocol command | |
74 handlers and the wire protocol transport layer. Protocol handlers provide | |
75 methods to read command arguments, redirect stdio for the duration of | |
76 the request, handle response types, etc. | |
77 """ | |
78 | |
79 __metaclass__ = abc.ABCMeta | |
80 | |
81 @abc.abstractproperty | |
82 def name(self): | |
83 """The name of the protocol implementation. | |
84 | |
85 Used for uniquely identifying the transport type. | |
86 """ | |
87 | |
88 @abc.abstractmethod | |
89 def getargs(self, args): | |
90 """return the value for arguments in <args> | |
91 | |
92 returns a list of values (same order as <args>)""" | |
93 | |
94 @abc.abstractmethod | |
95 def forwardpayload(self, fp): | |
96 """Read the raw payload and forward to a file. | |
97 | |
98 The payload is read in full before the function returns. | |
99 """ | |
100 | |
101 @abc.abstractmethod | |
102 def mayberedirectstdio(self): | |
103 """Context manager to possibly redirect stdio. | |
104 | |
105 The context manager yields a file-object like object that receives | |
106 stdout and stderr output when the context manager is active. Or it | |
107 yields ``None`` if no I/O redirection occurs. | |
108 | |
109 The intent of this context manager is to capture stdio output | |
110 so it may be sent in the response. Some transports support streaming | |
111 stdio to the client in real time. For these transports, stdio output | |
112 won't be captured. | |
113 """ | |
114 | |
115 @abc.abstractmethod | |
116 def client(self): | |
117 """Returns a string representation of this client (as bytes).""" |