Mercurial > public > mercurial-scm > hg
comparison mercurial/httppeer.py @ 37553:6b08cf6b900f
httppeer: allow opener to be passed to makepeer()
This allows us to use makepeer() in `hg debugwireproto`.
Differential Revision: https://phab.mercurial-scm.org/D3238
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 10 Apr 2018 13:07:13 -0700 |
parents | 8b8a845c85fc |
children | 301a1d2e8016 |
comparison
equal
deleted
inserted
replaced
37552:8b8a845c85fc | 37553:6b08cf6b900f |
---|---|
618 finally: | 618 finally: |
619 resp.close() | 619 resp.close() |
620 | 620 |
621 return respurl, set(rawcaps.split()) | 621 return respurl, set(rawcaps.split()) |
622 | 622 |
623 def makepeer(ui, path, requestbuilder=urlreq.request): | 623 def makepeer(ui, path, opener=None, requestbuilder=urlreq.request): |
624 """Construct an appropriate HTTP peer instance. | 624 """Construct an appropriate HTTP peer instance. |
625 | |
626 ``opener`` is an ``url.opener`` that should be used to establish | |
627 connections, perform HTTP requests. | |
625 | 628 |
626 ``requestbuilder`` is the type used for constructing HTTP requests. | 629 ``requestbuilder`` is the type used for constructing HTTP requests. |
627 It exists as an argument so extensions can override the default. | 630 It exists as an argument so extensions can override the default. |
628 """ | 631 """ |
629 u = util.url(path) | 632 u = util.url(path) |
633 | 636 |
634 # urllib cannot handle URLs with embedded user or passwd. | 637 # urllib cannot handle URLs with embedded user or passwd. |
635 url, authinfo = u.authinfo() | 638 url, authinfo = u.authinfo() |
636 ui.debug('using %s\n' % url) | 639 ui.debug('using %s\n' % url) |
637 | 640 |
638 opener = urlmod.opener(ui, authinfo) | 641 opener = opener or urlmod.opener(ui, authinfo) |
639 | 642 |
640 respurl, caps = performhandshake(ui, url, opener, requestbuilder) | 643 respurl, caps = performhandshake(ui, url, opener, requestbuilder) |
641 | 644 |
642 return httppeer(ui, path, respurl, opener, requestbuilder, caps) | 645 return httppeer(ui, path, respurl, opener, requestbuilder, caps) |
643 | 646 |