Patchwork D3232: httppeer: move requestbuilder defaults into makepeer() argument

login
register
mail settings
Submitter phabricator
Date April 11, 2018, 5:01 p.m.
Message ID <92b296ecda5205164a3b6bd28b791a1d@localhost.localdomain>
Download mbox | patch
Permalink /patch/30724/
State Not Applicable
Headers show

Comments

phabricator - April 11, 2018, 5:01 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG835ccc2a5ef1: httppeer: move requestbuilder defaults into makepeer() argument (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3232?vs=7950&id=7993

REVISION DETAIL
  https://phab.mercurial-scm.org/D3232

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/httppeer.py
  tests/test-check-interfaces.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/tests/test-check-interfaces.py b/tests/test-check-interfaces.py
--- a/tests/test-check-interfaces.py
+++ b/tests/test-check-interfaces.py
@@ -70,7 +70,7 @@ 
 # Facilitates testing sshpeer without requiring an SSH server.
 class badpeer(httppeer.httppeer):
     def __init__(self):
-        super(badpeer, self).__init__(None, None, None, dummyopener())
+        super(badpeer, self).__init__(None, None, None, dummyopener(), None)
         self.badattribute = True
 
     def badmethod(self):
@@ -89,7 +89,7 @@ 
 
     ziverify.verifyClass(repository.ipeerbaselegacycommands,
                          httppeer.httppeer)
-    checkzobject(httppeer.httppeer(None, None, None, dummyopener()))
+    checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None))
 
     ziverify.verifyClass(repository.ipeerbase,
                          localrepo.localpeer)
diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -139,15 +139,13 @@ 
         self._index = 0
 
 class httppeer(wireproto.wirepeer):
-    def __init__(self, ui, path, url, opener):
+    def __init__(self, ui, path, url, opener, requestbuilder):
         self.ui = ui
         self._path = path
         self._url = url
         self._caps = None
         self._urlopener = opener
-        # This is an its own attribute to facilitate extensions overriding
-        # the default type.
-        self._requestbuilder = urlreq.request
+        self._requestbuilder = requestbuilder
 
     def __del__(self):
         for h in self._urlopener.handlers:
@@ -570,7 +568,12 @@ 
 
         return results
 
-def makepeer(ui, path):
+def makepeer(ui, path, requestbuilder=urlreq.request):
+    """Construct an appropriate HTTP peer instance.
+
+    ``requestbuilder`` is the type used for constructing HTTP requests.
+    It exists as an argument so extensions can override the default.
+    """
     u = util.url(path)
     if u.query or u.fragment:
         raise error.Abort(_('unsupported URL component: "%s"') %
@@ -582,7 +585,7 @@ 
 
     opener = urlmod.opener(ui, authinfo)
 
-    return httppeer(ui, path, url, opener)
+    return httppeer(ui, path, url, opener, requestbuilder)
 
 def instance(ui, path, create):
     if create:
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2915,7 +2915,8 @@ 
             raise error.Abort(_('--peer %s not supported with HTTP peers') %
                               opts['peer'])
         else:
-            peer = httppeer.httppeer(ui, path, url, opener)
+            peer = httppeer.httppeer(ui, path, url, opener,
+                                     requestbuilder=httppeer.urlreq.request)
             peer._fetchcaps()
 
         # We /could/ populate stdin/stdout with sock.makefile()...