Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/wireprotoserver.py @ 36021:5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Currently, we perform simple membership testing for whether a wire
command is available. In the future, not all wire protocol commands
will be available on all transports. For example, a legacy transport
may not support newer commands.
In preparation of this, teach the protocol handlers to call into a
function to determine if a wire protocol command is available. That
function currently does membership testing like before, so behavior
should be identical.
In the case of the HTTP server, behavior is a bit wonkier. "cmd" is
used by both the wire protocol and hgweb. We do want the protocol
handler to handle requests for all commands that look like wire
protocol commands, even if they aren't available. Otherwise, the
fallback to hgweb would only confuse automated clients and make it
easier for hgweb to accidentally implement a "cmd" that is identical
to wire protocol commands (since they aren't centrally registered).
Differential Revision: https://phab.mercurial-scm.org/D1999
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 30 Jan 2018 18:41:44 -0800 |
parents | 48a3a9283f09 |
children | cdc93fe1da77 |
rev | line source |
---|---|
5598
d534ba1c4eb4
separate the wire protocol commands from the user interface commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
d534ba1c4eb4
separate the wire protocol commands from the user interface commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
d534ba1c4eb4
separate the wire protocol commands from the user interface commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8109
diff
changeset
|
4 # This software may be used and distributed according to the terms of the |
10263 | 5 # GNU General Public License version 2 or any later version. |
5598
d534ba1c4eb4
separate the wire protocol commands from the user interface commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
6 |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
7 from __future__ import absolute_import |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
8 |
35912
68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35911
diff
changeset
|
9 import abc |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
10 import cgi |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
11 import struct |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
12 import sys |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
13 |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
14 from .i18n import _ |
35896
ef3a24a023ec
wireprotoserver: rename hgweb.protocol to wireprotoserver (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35750
diff
changeset
|
15 from . import ( |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
16 encoding, |
34509
e21f274cccea
hgweb: in protocol adapter, avoid control reaching end of non-void function
Augie Fackler <augie@google.com>
parents:
33842
diff
changeset
|
17 error, |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
18 hook, |
34742
5a9cad0dfddb
hgweb: when unpacking args from request form, convert to bytes
Augie Fackler <augie@google.com>
parents:
34740
diff
changeset
|
19 pycompat, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
20 util, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
21 wireproto, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
20903
diff
changeset
|
22 ) |
35896
ef3a24a023ec
wireprotoserver: rename hgweb.protocol to wireprotoserver (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35750
diff
changeset
|
23 |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28530
diff
changeset
|
24 stringio = util.stringio |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5915
diff
changeset
|
25 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
26 urlerr = util.urlerr |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
27 urlreq = util.urlreq |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
28 |
35898
1b76a9e0a9de
wireprotoserver: don't import symbol from hgweb.common
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35897
diff
changeset
|
29 HTTP_OK = 200 |
1b76a9e0a9de
wireprotoserver: don't import symbol from hgweb.common
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35897
diff
changeset
|
30 |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
31 HGTYPE = 'application/mercurial-0.1' |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
32 HGTYPE2 = 'application/mercurial-0.2' |
15017
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14614
diff
changeset
|
33 HGERRTYPE = 'application/hg-error' |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
34 |
36015
48a3a9283f09
sshpeer: initial definition and implementation of new SSH protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35940
diff
changeset
|
35 # Names of the SSH protocol implementations. |
48a3a9283f09
sshpeer: initial definition and implementation of new SSH protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35940
diff
changeset
|
36 SSHV1 = 'ssh-v1' |
48a3a9283f09
sshpeer: initial definition and implementation of new SSH protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35940
diff
changeset
|
37 # This is advertised over the wire. Incremental the counter at the end |
48a3a9283f09
sshpeer: initial definition and implementation of new SSH protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35940
diff
changeset
|
38 # to reflect BC breakages. |
48a3a9283f09
sshpeer: initial definition and implementation of new SSH protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35940
diff
changeset
|
39 SSHV2 = 'exp-ssh-v2-0001' |
48a3a9283f09
sshpeer: initial definition and implementation of new SSH protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35940
diff
changeset
|
40 |
35900
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
41 class abstractserverproto(object): |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
42 """abstract class that summarizes the protocol API |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
43 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
44 Used as reference and documentation. |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
45 """ |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
46 |
35912
68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35911
diff
changeset
|
47 __metaclass__ = abc.ABCMeta |
68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35911
diff
changeset
|
48 |
35913
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
49 @abc.abstractproperty |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
50 def name(self): |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
51 """The name of the protocol implementation. |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
52 |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
53 Used for uniquely identifying the transport type. |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
54 """ |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
55 |
35912
68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35911
diff
changeset
|
56 @abc.abstractmethod |
35900
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
57 def getargs(self, args): |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
58 """return the value for arguments in <args> |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
59 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
60 returns a list of values (same order as <args>)""" |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
61 |
35912
68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35911
diff
changeset
|
62 @abc.abstractmethod |
35900
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
63 def getfile(self, fp): |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
64 """write the whole content of a file into a file like object |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
65 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
66 The file is in the form:: |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
67 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
68 (<chunk-size>\n<chunk>)+0\n |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
69 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
70 chunk size is the ascii version of the int. |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
71 """ |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
72 |
35912
68dc621fa06c
wireprotoserver: make abstractserverproto a proper abstract base class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35911
diff
changeset
|
73 @abc.abstractmethod |
35900
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
74 def redirect(self): |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
75 """may setup interception for stdout and stderr |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
76 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
77 See also the `restore` method.""" |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
78 |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
79 # If the `redirect` function does install interception, the `restore` |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
80 # function MUST be defined. If interception is not used, this function |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
81 # MUST NOT be defined. |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
82 # |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
83 # left commented here on purpose |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
84 # |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
85 #def restore(self): |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
86 # """reinstall previous stdout and stderr and return intercepted stdout |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
87 # """ |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
88 # raise NotImplementedError() |
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
89 |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
90 def decodevaluefromheaders(req, headerprefix): |
34744
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
91 """Decode a long value from multiple HTTP request headers. |
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
92 |
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
93 Returns the value as a bytes, not a str. |
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
94 """ |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
95 chunks = [] |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
96 i = 1 |
34744
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
97 prefix = headerprefix.upper().replace(r'-', r'_') |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
98 while True: |
34744
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
99 v = req.env.get(r'HTTP_%s_%d' % (prefix, i)) |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
100 if v is None: |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
101 break |
34744
0a2ef612ad50
hgweb: fix decodevaluefromheaders to always return a bytes value
Augie Fackler <augie@google.com>
parents:
34743
diff
changeset
|
102 chunks.append(pycompat.bytesurl(v)) |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
103 i += 1 |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
104 |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
105 return ''.join(chunks) |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
106 |
35900
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
107 class webproto(abstractserverproto): |
14614
afccc64eea73
ui: use I/O descriptors internally
Idan Kamara <idankk86@gmail.com>
parents:
14494
diff
changeset
|
108 def __init__(self, req, ui): |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
109 self._req = req |
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
110 self._ui = ui |
35913
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
111 |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
112 @property |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
113 def name(self): |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
114 return 'http' |
30567
b3a9ef3d30e8
protocol: declare transport protocol name
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30475
diff
changeset
|
115 |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
116 def getargs(self, args): |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13721
diff
changeset
|
117 knownargs = self._args() |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
118 data = {} |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
119 keys = args.split() |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
120 for k in keys: |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
121 if k == '*': |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
122 star = {} |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13721
diff
changeset
|
123 for key in knownargs.keys(): |
13721
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12704
diff
changeset
|
124 if key != 'cmd' and key not in keys: |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13721
diff
changeset
|
125 star[key] = knownargs[key][0] |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
126 data['*'] = star |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
127 else: |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13721
diff
changeset
|
128 data[k] = knownargs[k][0] |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
129 return [data[k] for k in keys] |
35903
49426bb4476c
wireprotoserver: add some blank lines between methods
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35900
diff
changeset
|
130 |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13721
diff
changeset
|
131 def _args(self): |
35940
72de5c504833
py3: factor out helpers to apply string conversion recursively
Yuya Nishihara <yuya@tcha.org>
parents:
35913
diff
changeset
|
132 args = util.rapply(pycompat.bytesurl, self._req.form.copy()) |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
133 postlen = int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) |
28530
fd2acc5046f6
http: support sending hgargs via POST body instead of in GET or headers
Augie Fackler <augie@google.com>
parents:
27046
diff
changeset
|
134 if postlen: |
fd2acc5046f6
http: support sending hgargs via POST body instead of in GET or headers
Augie Fackler <augie@google.com>
parents:
27046
diff
changeset
|
135 args.update(cgi.parse_qs( |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
136 self._req.read(postlen), keep_blank_values=True)) |
28530
fd2acc5046f6
http: support sending hgargs via POST body instead of in GET or headers
Augie Fackler <augie@google.com>
parents:
27046
diff
changeset
|
137 return args |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
138 |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
139 argvalue = decodevaluefromheaders(self._req, r'X-HgArg') |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30567
diff
changeset
|
140 args.update(cgi.parse_qs(argvalue, keep_blank_values=True)) |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13721
diff
changeset
|
141 return args |
35903
49426bb4476c
wireprotoserver: add some blank lines between methods
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35900
diff
changeset
|
142 |
11621
e46a8b2331a6
protocol: shuffle server methods to group send methods
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11618
diff
changeset
|
143 def getfile(self, fp): |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
144 length = int(self._req.env[r'CONTENT_LENGTH']) |
33842
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33228
diff
changeset
|
145 # If httppostargs is used, we need to read Content-Length |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33228
diff
changeset
|
146 # minus the amount that was consumed by args. |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
147 length -= int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) |
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
148 for s in util.filechunkiter(self._req, limit=length): |
11621
e46a8b2331a6
protocol: shuffle server methods to group send methods
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11618
diff
changeset
|
149 fp.write(s) |
35903
49426bb4476c
wireprotoserver: add some blank lines between methods
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35900
diff
changeset
|
150 |
11621
e46a8b2331a6
protocol: shuffle server methods to group send methods
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11618
diff
changeset
|
151 def redirect(self): |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
152 self._oldio = self._ui.fout, self._ui.ferr |
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
153 self._ui.ferr = self._ui.fout = stringio() |
35903
49426bb4476c
wireprotoserver: add some blank lines between methods
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35900
diff
changeset
|
154 |
14614
afccc64eea73
ui: use I/O descriptors internally
Idan Kamara <idankk86@gmail.com>
parents:
14494
diff
changeset
|
155 def restore(self): |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
156 val = self._ui.fout.getvalue() |
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
157 self._ui.ferr, self._ui.fout = self._oldio |
14614
afccc64eea73
ui: use I/O descriptors internally
Idan Kamara <idankk86@gmail.com>
parents:
14494
diff
changeset
|
158 return val |
30206
d105195436c0
wireproto: compress data from a generator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30016
diff
changeset
|
159 |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
160 def _client(self): |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
161 return 'remote:%s:%s:%s' % ( |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
162 self._req.env.get('wsgi.url_scheme') or 'http', |
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
163 urlreq.quote(self._req.env.get('REMOTE_HOST', '')), |
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
164 urlreq.quote(self._req.env.get('REMOTE_USER', ''))) |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
165 |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
166 def responsetype(self, prefer_uncompressed): |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
167 """Determine the appropriate response type and compression settings. |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
168 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
169 Returns a tuple of (mediatype, compengine, engineopts). |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
170 """ |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
171 # Determine the response media type and compression engine based |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
172 # on the request parameters. |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
173 protocaps = decodevaluefromheaders(self._req, r'X-HgProto').split(' ') |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
174 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
175 if '0.2' in protocaps: |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
176 # All clients are expected to support uncompressed data. |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
177 if prefer_uncompressed: |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
178 return HGTYPE2, util._noopengine(), {} |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
179 |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
180 # Default as defined by wire protocol spec. |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
181 compformats = ['zlib', 'none'] |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
182 for cap in protocaps: |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
183 if cap.startswith('comp='): |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
184 compformats = cap[5:].split(',') |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
185 break |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
186 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
187 # Now find an agreed upon compression format. |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
188 for engine in wireproto.supportedcompengines(self._ui, self, |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
189 util.SERVERROLE): |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
190 if engine.wireprotosupport().name in compformats: |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
191 opts = {} |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
192 level = self._ui.configint('server', |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
193 '%slevel' % engine.name()) |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
194 if level is not None: |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
195 opts['level'] = level |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
196 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
197 return HGTYPE2, engine, opts |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
198 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
199 # No mutually supported compression format. Fall back to the |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
200 # legacy protocol. |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
201 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
202 # Don't allow untrusted settings because disabling compression or |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
203 # setting a very high compression level could lead to flooding |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
204 # the server's network or CPU. |
35906
d747cf39cf70
wireprotoserver: make attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35905
diff
changeset
|
205 opts = {'level': self._ui.configint('server', 'zliblevel')} |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
206 return HGTYPE, util.compengines['zlib'], opts |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
207 |
11595
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
208 def iscmd(cmd): |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
209 return cmd in wireproto.commands |
368cd5325348
protocol: move hgweb protocol support back into protocol.py
Matt Mackall <mpm@selenic.com>
parents:
11594
diff
changeset
|
210 |
35897
a42455b3dbf8
wireprotoserver: rename call to callhttp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35896
diff
changeset
|
211 def callhttp(repo, req, cmd): |
35904
bd38ccf4ecf6
wireprotoserver: rename p to proto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35903
diff
changeset
|
212 proto = webproto(req, repo.ui) |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
213 |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
214 def genversion2(gen, engine, engineopts): |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
215 # application/mercurial-0.2 always sends a payload header |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
216 # identifying the compression engine. |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
217 name = engine.wireprotosupport().name |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
218 assert 0 < len(name) < 256 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
219 yield struct.pack('B', len(name)) |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
220 yield name |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
221 |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
222 for chunk in gen: |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
223 yield chunk |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
224 |
35904
bd38ccf4ecf6
wireprotoserver: rename p to proto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35903
diff
changeset
|
225 rsp = wireproto.dispatch(repo, proto, cmd) |
36021
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
226 |
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
227 if not wireproto.commands.commandavailable(cmd, proto): |
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
228 req.respond(HTTP_OK, HGERRTYPE, |
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
229 body=_('requested wire protocol command is not available ' |
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
230 'over HTTP')) |
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
231 return [] |
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
232 |
34510
c23fa3103925
hgweb: in protocol adapter, look for bytes instances, not str
Augie Fackler <augie@google.com>
parents:
34509
diff
changeset
|
233 if isinstance(rsp, bytes): |
18352
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
234 req.respond(HTTP_OK, HGTYPE, body=rsp) |
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
235 return [] |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
236 elif isinstance(rsp, wireproto.streamres_legacy): |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
237 gen = rsp.gen |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
238 req.respond(HTTP_OK, HGTYPE) |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
239 return gen |
11626
2f8adc60e013
protocol: use generators instead of req.write() for hgweb stream responses
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
240 elif isinstance(rsp, wireproto.streamres): |
35705
8cdb671dbd0b
wireproto: drop support for reader interface from streamres (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34744
diff
changeset
|
241 gen = rsp.gen |
30475
2add671bf55b
wireproto: perform chunking and compression at protocol layer (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30376
diff
changeset
|
242 |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
243 # This code for compression should not be streamres specific. It |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
244 # is here because we only compress streamres at the moment. |
35904
bd38ccf4ecf6
wireprotoserver: rename p to proto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35903
diff
changeset
|
245 mediatype, engine, engineopts = proto.responsetype( |
bd38ccf4ecf6
wireprotoserver: rename p to proto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35903
diff
changeset
|
246 rsp.prefer_uncompressed) |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
247 gen = engine.compressstream(gen, engineopts) |
30475
2add671bf55b
wireproto: perform chunking and compression at protocol layer (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30376
diff
changeset
|
248 |
35750
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
249 if mediatype == HGTYPE2: |
a39a9df7ecca
wireproto: split streamres into legacy and modern case
Joerg Sonnenberger <joerg@bec.de>
parents:
35705
diff
changeset
|
250 gen = genversion2(gen, engine, engineopts) |
30764
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
251 |
e75463e3179f
protocol: send application/mercurial-0.2 responses to capable clients
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
252 req.respond(HTTP_OK, mediatype) |
30475
2add671bf55b
wireproto: perform chunking and compression at protocol layer (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30376
diff
changeset
|
253 return gen |
11626
2f8adc60e013
protocol: use generators instead of req.write() for hgweb stream responses
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
254 elif isinstance(rsp, wireproto.pushres): |
35904
bd38ccf4ecf6
wireprotoserver: rename p to proto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35903
diff
changeset
|
255 val = proto.restore() |
18346
6c2563b2c1c6
hgweb: use Content-Length for pushres
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
256 rsp = '%d\n%s' % (rsp.res, val) |
18352
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
257 req.respond(HTTP_OK, HGTYPE, body=rsp) |
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
258 return [] |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11626
diff
changeset
|
259 elif isinstance(rsp, wireproto.pusherr): |
12704
ca6e2adc3e4d
wireproto/http: drain the incoming bundle in case of errors
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12703
diff
changeset
|
260 # drain the incoming bundle |
ca6e2adc3e4d
wireproto/http: drain the incoming bundle in case of errors
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12703
diff
changeset
|
261 req.drain() |
35904
bd38ccf4ecf6
wireprotoserver: rename p to proto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35903
diff
changeset
|
262 proto.restore() |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11626
diff
changeset
|
263 rsp = '0\n%s\n' % rsp.res |
18352
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
264 req.respond(HTTP_OK, HGTYPE, body=rsp) |
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
265 return [] |
15017
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14614
diff
changeset
|
266 elif isinstance(rsp, wireproto.ooberror): |
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14614
diff
changeset
|
267 rsp = rsp.message |
18352
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
268 req.respond(HTTP_OK, HGERRTYPE, body=rsp) |
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18346
diff
changeset
|
269 return [] |
34509
e21f274cccea
hgweb: in protocol adapter, avoid control reaching end of non-void function
Augie Fackler <augie@google.com>
parents:
33842
diff
changeset
|
270 raise error.ProgrammingError('hgweb.protocol internal failure', rsp) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
271 |
35900
d9e71cce3b2f
wireprotoserver: move abstractserverproto class from wireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35899
diff
changeset
|
272 class sshserver(abstractserverproto): |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
273 def __init__(self, ui, repo): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
274 self._ui = ui |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
275 self._repo = repo |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
276 self._fin = ui.fin |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
277 self._fout = ui.fout |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
278 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
279 hook.redirect(True) |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
280 ui.fout = repo.ui.fout = ui.ferr |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
281 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
282 # Prevent insertion/deletion of CRs |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
283 util.setbinary(self._fin) |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
284 util.setbinary(self._fout) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
285 |
35913
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
286 @property |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
287 def name(self): |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
288 return 'ssh' |
29759c46aa1a
wireprotoserver: make name part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35912
diff
changeset
|
289 |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
290 def getargs(self, args): |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
291 data = {} |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
292 keys = args.split() |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
293 for n in xrange(len(keys)): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
294 argline = self._fin.readline()[:-1] |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
295 arg, l = argline.split() |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
296 if arg not in keys: |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
297 raise error.Abort(_("unexpected parameter %r") % arg) |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
298 if arg == '*': |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
299 star = {} |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
300 for k in xrange(int(l)): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
301 argline = self._fin.readline()[:-1] |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
302 arg, l = argline.split() |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
303 val = self._fin.read(int(l)) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
304 star[arg] = val |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
305 data['*'] = star |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
306 else: |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
307 val = self._fin.read(int(l)) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
308 data[arg] = val |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
309 return [data[k] for k in keys] |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
310 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
311 def getfile(self, fpout): |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
312 self._sendresponse('') |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
313 count = int(self._fin.readline()) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
314 while count: |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
315 fpout.write(self._fin.read(count)) |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
316 count = int(self._fin.readline()) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
317 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
318 def redirect(self): |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
319 pass |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
320 |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
321 def _sendresponse(self, v): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
322 self._fout.write("%d\n" % len(v)) |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
323 self._fout.write(v) |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
324 self._fout.flush() |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
325 |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
326 def _sendstream(self, source): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
327 write = self._fout.write |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
328 for chunk in source.gen: |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
329 write(chunk) |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
330 self._fout.flush() |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
331 |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
332 def _sendpushresponse(self, rsp): |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
333 self._sendresponse('') |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
334 self._sendresponse(str(rsp.res)) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
335 |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
336 def _sendpusherror(self, rsp): |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
337 self._sendresponse(rsp.res) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
338 |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
339 def _sendooberror(self, rsp): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
340 self._ui.ferr.write('%s\n-\n' % rsp.message) |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
341 self._ui.ferr.flush() |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
342 self._fout.write('\n') |
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
343 self._fout.flush() |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
344 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
345 def serve_forever(self): |
35908
5a9ff8c20123
wireprotoserver: remove lock references
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35907
diff
changeset
|
346 while self.serve_one(): |
5a9ff8c20123
wireprotoserver: remove lock references
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35907
diff
changeset
|
347 pass |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
348 sys.exit(0) |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
349 |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
350 _handlers = { |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
351 str: _sendresponse, |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
352 wireproto.streamres: _sendstream, |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
353 wireproto.streamres_legacy: _sendstream, |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
354 wireproto.pushres: _sendpushresponse, |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
355 wireproto.pusherr: _sendpusherror, |
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
356 wireproto.ooberror: _sendooberror, |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
357 } |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
358 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
359 def serve_one(self): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
360 cmd = self._fin.readline()[:-1] |
36021
5a56bf4180ad
wireproto: function for testing if wire protocol command is available
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36015
diff
changeset
|
361 if cmd and wireproto.commands.commandavailable(cmd, self): |
35910
f1efc0caeab7
wireprotoserver: make some instance attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35909
diff
changeset
|
362 rsp = wireproto.dispatch(self._repo, self, cmd) |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
363 self._handlers[rsp.__class__](self, rsp) |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
364 elif cmd: |
35911
49ea1ba15ffd
wireprotoserver: make response handling attributes private
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35910
diff
changeset
|
365 self._sendresponse("") |
35899
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
366 return cmd != '' |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
367 |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
368 def _client(self): |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
369 client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] |
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35898
diff
changeset
|
370 return 'remote:ssh:' + client |