These methods on the protocol handler interface are no longer used in
core.
.. api::
redirect() and restore() have been removed from the wire protocol handler interface. Use mayberedirectstdio() instead.
durin42 |
hg-reviewers |
These methods on the protocol handler interface are no longer used in
core.
.. api::
redirect() and restore() have been removed from the wire protocol handler interface. Use mayberedirectstdio() instead.
Lint Skipped |
Unit Tests Skipped |
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 redirect(self): | |||||
"""may setup interception for stdout and stderr | |||||
See also the `restore` method.""" | |||||
# If the `redirect` function does install interception, the `restore` | |||||
# function MUST be defined. If interception is not used, this function | |||||
# MUST NOT be defined. | |||||
# | |||||
# left commented here on purpose | |||||
# | |||||
#def restore(self): | |||||
# """reinstall previous stdout and stderr and return intercepted stdout | |||||
# """ | |||||
# raise NotImplementedError() | |||||
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 redirect(self): | |||||
self._oldio = self._ui.fout, self._ui.ferr | |||||
self._ui.ferr = self._ui.fout = stringio() | |||||
def restore(self): | |||||
val = self._ui.fout.getvalue() | |||||
self._ui.ferr, self._ui.fout = self._oldio | |||||
return val | |||||
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. | ||||
while count: | while count: | ||||
fpout.write(self._fin.read(count)) | fpout.write(self._fin.read(count)) | ||||
count = int(self._fin.readline()) | count = int(self._fin.readline()) | ||||
@contextlib.contextmanager | @contextlib.contextmanager | ||||
def mayberedirectstdio(self): | def mayberedirectstdio(self): | ||||
yield None | yield None | ||||
def redirect(self): | |||||
pass | |||||
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 |