Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/wireprototypes.py @ 36809:66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Per the inline comment desiring to formalize permissions checking
in the protocol interface, we do that.
I'm not convinced this is the best way to go about things. I would love
for there to e.g. be a better exception for denoting permissions
problems. But it does feel strictly better than snipping attributes
on the proto instance.
Differential Revision: https://phab.mercurial-scm.org/D2719
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 07 Mar 2018 16:18:52 -0800 |
parents | 6e585bca962e |
children | 1cfef5693203 |
rev | line source |
---|---|
36111
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 from __future__ import absolute_import |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
36402
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
8 import abc |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
9 |
36565
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
10 # Names of the SSH protocol implementations. |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
11 SSHV1 = 'ssh-v1' |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
12 # This is advertised over the wire. Incremental the counter at the end |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
13 # to reflect BC breakages. |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
14 SSHV2 = 'exp-ssh-v2-0001' |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
15 |
36638
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
16 # All available wire protocol transports. |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
17 TRANSPORTS = { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
18 SSHV1: { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
19 'transport': 'ssh', |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
20 'version': 1, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
21 }, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
22 SSHV2: { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
23 'transport': 'ssh', |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
24 'version': 2, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
25 }, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
26 'http-v1': { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
27 'transport': 'http', |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
28 'version': 1, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
29 } |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
30 } |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
31 |
36112
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
32 class bytesresponse(object): |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
33 """A wire protocol response consisting of raw bytes.""" |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
34 def __init__(self, data): |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
35 self.data = data |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
36 |
36111
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 class ooberror(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 """wireproto reply: failure of a batch of operation |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 Something failed during a batch call. The error message is stored in |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 `self.message`. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 def __init__(self, message): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 self.message = message |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 class pushres(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 """wireproto reply: success with simple integer return |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 The call was successful and returned an integer contained in `self.res`. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 def __init__(self, res, output): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 self.res = res |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 self.output = output |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 class pusherr(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 """wireproto reply: failure |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 The call failed. The `self.res` attribute contains the error message. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 def __init__(self, res, output): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 self.res = res |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 self.output = output |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 class streamres(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 """wireproto reply: binary stream |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 The call was successful and the result is a stream. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 Accepts a generator containing chunks of data to be sent to the client. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 ``prefer_uncompressed`` indicates that the data is expected to be |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 uncompressable and that the stream should therefore use the ``none`` |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 engine. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 def __init__(self, gen=None, prefer_uncompressed=False): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 self.gen = gen |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 self.prefer_uncompressed = prefer_uncompressed |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 class streamreslegacy(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 """wireproto reply: uncompressed binary stream |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 The call was successful and the result is a stream. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 Accepts a generator containing chunks of data to be sent to the client. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 Like ``streamres``, but sends an uncompressed data for "version 1" clients |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 using the application/mercurial-0.1 media type. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 def __init__(self, gen=None): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 self.gen = gen |
36402
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
91 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
92 class baseprotocolhandler(object): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
93 """Abstract base class for wire protocol handlers. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
94 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
95 A wire protocol handler serves as an interface between protocol command |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
96 handlers and the wire protocol transport layer. Protocol handlers provide |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
97 methods to read command arguments, redirect stdio for the duration of |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
98 the request, handle response types, etc. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
99 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
100 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
101 __metaclass__ = abc.ABCMeta |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
102 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
103 @abc.abstractproperty |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
104 def name(self): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
105 """The name of the protocol implementation. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
106 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
107 Used for uniquely identifying the transport type. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
108 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
109 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
110 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
111 def getargs(self, args): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
112 """return the value for arguments in <args> |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
113 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
114 returns a list of values (same order as <args>)""" |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
115 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
116 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
117 def forwardpayload(self, fp): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
118 """Read the raw payload and forward to a file. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
119 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
120 The payload is read in full before the function returns. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
121 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
122 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
123 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
124 def mayberedirectstdio(self): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
125 """Context manager to possibly redirect stdio. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
126 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
127 The context manager yields a file-object like object that receives |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
128 stdout and stderr output when the context manager is active. Or it |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
129 yields ``None`` if no I/O redirection occurs. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
130 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
131 The intent of this context manager is to capture stdio output |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
132 so it may be sent in the response. Some transports support streaming |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
133 stdio to the client in real time. For these transports, stdio output |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
134 won't be captured. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
135 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
136 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
137 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
138 def client(self): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
139 """Returns a string representation of this client (as bytes).""" |
36642
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
140 |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
141 @abc.abstractmethod |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
142 def addcapabilities(self, repo, caps): |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
143 """Adds advertised capabilities specific to this protocol. |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
144 |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
145 Receives the list of capabilities collected so far. |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
146 |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
147 Returns a list of capabilities. The passed in argument can be returned. |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
148 """ |
36809
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
149 |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
150 @abc.abstractmethod |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
151 def checkperm(self, perm): |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
152 """Validate that the client has permissions to perform a request. |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
153 |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
154 The argument is the permission required to proceed. If the client |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
155 doesn't have that permission, the exception should raise or abort |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
156 in a protocol specific manner. |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
157 """ |