This is similar to what we did to sshpeer. Quirks and all.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
hg-reviewers |
This is similar to what we did to sshpeer. Quirks and all.
Lint Skipped |
Unit Tests Skipped |
from .i18n import _ | from .i18n import _ | ||||
from .node import nullid | from .node import nullid | ||||
from . import ( | from . import ( | ||||
bundle2, | bundle2, | ||||
error, | error, | ||||
httpconnection, | httpconnection, | ||||
pycompat, | pycompat, | ||||
repository, | |||||
statichttprepo, | statichttprepo, | ||||
url, | url, | ||||
util, | util, | ||||
wireproto, | wireproto, | ||||
) | ) | ||||
httplib = util.httplib | httplib = util.httplib | ||||
urlerr = util.urlerr | urlerr = util.urlerr | ||||
raise error.PeerTransportError( | raise error.PeerTransportError( | ||||
_('HTTP request error (%s)') % e, | _('HTTP request error (%s)') % e, | ||||
hint=_('this may be an intermittent network failure; ' | hint=_('this may be an intermittent network failure; ' | ||||
'if the error persists, consider contacting the ' | 'if the error persists, consider contacting the ' | ||||
'network or server operator')) | 'network or server operator')) | ||||
resp.__class__ = readerproxy | resp.__class__ = readerproxy | ||||
class httppeer(wireproto.wirepeer): | class httppeer(wireproto.wirepeer, repository.legacypeer): | ||||
def __init__(self, ui, path): | def __init__(self, ui, path): | ||||
self._path = path | self._path = path | ||||
self._caps = None | self._caps = None | ||||
self._urlopener = None | self._urlopener = None | ||||
self._requestbuilder = None | self._requestbuilder = None | ||||
u = util.url(path) | u = util.url(path) | ||||
if u.query or u.fragment: | if u.query or u.fragment: | ||||
raise error.Abort(_('unsupported URL component: "%s"') % | raise error.Abort(_('unsupported URL component: "%s"') % | ||||
(u.query or u.fragment)) | (u.query or u.fragment)) | ||||
# urllib cannot handle URLs with embedded user or passwd | # urllib cannot handle URLs with embedded user or passwd | ||||
self._url, authinfo = u.authinfo() | self._url, authinfo = u.authinfo() | ||||
self.ui = ui | self._ui = ui | ||||
self.ui.debug('using %s\n' % self._url) | ui.debug('using %s\n' % self._url) | ||||
self._urlopener = url.opener(ui, authinfo) | self._urlopener = url.opener(ui, authinfo) | ||||
self._requestbuilder = urlreq.request | self._requestbuilder = urlreq.request | ||||
# TODO remove once peerrepository isn't in inheritance. | |||||
self._capabilities = self.capabilities | |||||
def __del__(self): | def __del__(self): | ||||
urlopener = getattr(self, '_urlopener', None) | urlopener = getattr(self, '_urlopener', None) | ||||
if urlopener: | if urlopener: | ||||
for h in urlopener.handlers: | for h in urlopener.handlers: | ||||
h.close() | h.close() | ||||
getattr(h, "close_all", lambda : None)() | getattr(h, "close_all", lambda : None)() | ||||
# Begin of _basepeer interface. | |||||
@util.propertycache | |||||
def ui(self): | |||||
return self._ui | |||||
def url(self): | def url(self): | ||||
return self._path | return self._path | ||||
# look up capabilities only when needed | def local(self): | ||||
return None | |||||
def _fetchcaps(self): | def peer(self): | ||||
self._caps = set(self._call('capabilities').split()) | return self | ||||
def canpush(self): | |||||
return True | |||||
def close(self): | |||||
pass | |||||
def _capabilities(self): | # End of _basepeer interface. | ||||
# Begin of _basewirepeer interface. | |||||
def capabilities(self): | |||||
if self._caps is None: | if self._caps is None: | ||||
try: | try: | ||||
self._fetchcaps() | self._fetchcaps() | ||||
except error.RepoError: | except error.RepoError: | ||||
self._caps = set() | self._caps = set() | ||||
self.ui.debug('capabilities: %s\n' % | self.ui.debug('capabilities: %s\n' % | ||||
(' '.join(self._caps or ['none']))) | (' '.join(self._caps or ['none']))) | ||||
return self._caps | return self._caps | ||||
# End of _basewirepeer interface. | |||||
# look up capabilities only when needed | |||||
def _fetchcaps(self): | |||||
self._caps = set(self._call('capabilities').split()) | |||||
def _callstream(self, cmd, _compressible=False, **args): | def _callstream(self, cmd, _compressible=False, **args): | ||||
if cmd == 'pushkey': | if cmd == 'pushkey': | ||||
args['data'] = '' | args['data'] = '' | ||||
data = args.pop('data', None) | data = args.pop('data', None) | ||||
headers = args.pop('headers', {}) | headers = args.pop('headers', {}) | ||||
self.ui.debug("sending %s command\n" % cmd) | self.ui.debug("sending %s command\n" % cmd) | ||||
q = [('cmd', cmd)] | q = [('cmd', cmd)] |