This method is called in wireproto.py. It should be part of the public
API/interface.
.. api::
The ``_client()`` method of the wire protocol handler interface has been renamed to ``client()``.
durin42 |
hg-reviewers |
This method is called in wireproto.py. It should be part of the public
API/interface.
.. api::
The ``_client()`` method of the wire protocol handler interface has been renamed to ``client()``.
Lint Skipped |
Unit Tests Skipped |
# the http client on failed push so we need to abuse | # the http client on failed push so we need to abuse | ||||
# some other error type to make sure the message get to | # some other error type to make sure the message get to | ||||
# the user. | # the user. | ||||
return ooberror(bundle2required) | return ooberror(bundle2required) | ||||
raise error.Abort(bundle2requiredmain, | raise error.Abort(bundle2requiredmain, | ||||
hint=bundle2requiredhint) | hint=bundle2requiredhint) | ||||
r = exchange.unbundle(repo, gen, their_heads, 'serve', | r = exchange.unbundle(repo, gen, their_heads, 'serve', | ||||
proto._client()) | proto.client()) | ||||
if util.safehasattr(r, 'addpart'): | if util.safehasattr(r, 'addpart'): | ||||
# The return looks streamable, we are in the bundle2 case | # The return looks streamable, we are in the bundle2 case | ||||
# and should return a stream. | # and should return a stream. | ||||
return streamres_legacy(gen=r.getchunks()) | return streamres_legacy(gen=r.getchunks()) | ||||
return pushres(r, output.getvalue() if output else '') | return pushres(r, output.getvalue() if output else '') | ||||
finally: | finally: | ||||
fp.close() | fp.close() |
yields ``None`` if no I/O redirection occurs. | yields ``None`` if no I/O redirection occurs. | ||||
The intent of this context manager is to capture stdio output | The intent of this context manager is to capture stdio output | ||||
so it may be sent in the response. Some transports support streaming | so it may be sent in the response. Some transports support streaming | ||||
stdio to the client in real time. For these transports, stdio output | stdio to the client in real time. For these transports, stdio output | ||||
won't be captured. | won't be captured. | ||||
""" | """ | ||||
@abc.abstractmethod | |||||
def client(self): | |||||
"""Returns a string representation of this client (as bytes).""" | |||||
def decodevaluefromheaders(req, headerprefix): | def decodevaluefromheaders(req, headerprefix): | ||||
"""Decode a long value from multiple HTTP request headers. | """Decode a long value from multiple HTTP request headers. | ||||
Returns the value as a bytes, not a str. | Returns the value as a bytes, not a str. | ||||
""" | """ | ||||
chunks = [] | chunks = [] | ||||
i = 1 | i = 1 | ||||
prefix = headerprefix.upper().replace(r'-', r'_') | prefix = headerprefix.upper().replace(r'-', r'_') | ||||
try: | try: | ||||
self._ui.fout = out | self._ui.fout = out | ||||
self._ui.ferr = out | self._ui.ferr = out | ||||
yield out | yield out | ||||
finally: | finally: | ||||
self._ui.fout = oldout | self._ui.fout = oldout | ||||
self._ui.ferr = olderr | self._ui.ferr = olderr | ||||
def _client(self): | def client(self): | ||||
return 'remote:%s:%s:%s' % ( | return 'remote:%s:%s:%s' % ( | ||||
self._req.env.get('wsgi.url_scheme') or 'http', | self._req.env.get('wsgi.url_scheme') or 'http', | ||||
urlreq.quote(self._req.env.get('REMOTE_HOST', '')), | urlreq.quote(self._req.env.get('REMOTE_HOST', '')), | ||||
urlreq.quote(self._req.env.get('REMOTE_USER', ''))) | urlreq.quote(self._req.env.get('REMOTE_USER', ''))) | ||||
def responsetype(self, prefer_uncompressed): | def responsetype(self, prefer_uncompressed): | ||||
"""Determine the appropriate response type and compression settings. | """Determine the appropriate response type and compression settings. | ||||
str: _sendresponse, | str: _sendresponse, | ||||
wireproto.streamres: _sendstream, | wireproto.streamres: _sendstream, | ||||
wireproto.streamres_legacy: _sendstream, | wireproto.streamres_legacy: _sendstream, | ||||
wireproto.pushres: _sendpushresponse, | wireproto.pushres: _sendpushresponse, | ||||
wireproto.pusherr: _sendpusherror, | wireproto.pusherr: _sendpusherror, | ||||
wireproto.ooberror: _sendooberror, | wireproto.ooberror: _sendooberror, | ||||
} | } | ||||
def _client(self): | def client(self): | ||||
client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] | client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0] | ||||
return 'remote:ssh:' + client | return 'remote:ssh:' + client | ||||
class sshserver(object): | class sshserver(object): | ||||
def __init__(self, ui, repo): | def __init__(self, ui, repo): | ||||
self._ui = ui | self._ui = ui | ||||
self._repo = repo | self._repo = repo | ||||
self._fin = ui.fin | self._fin = ui.fin |