[PATCH] httppeer: allow extensions to replace urllib2.Request

Kyle Lippincott spectral at google.com
Mon Jun 8 19:06:46 CDT 2015


# HG changeset patch
# User Kyle Lippincott <spectral at google.com>
# Date 1433807721 25200
#      Mon Jun 08 16:55:21 2015 -0700
# Node ID 55354ae61290f56f85965964b66e6b7efaaa71ef
# Parent  378a8e700e02794e991d3521423a4f581b635666
httppeer: allow extensions to replace urllib2.Request

The authentication library my extension wants to use requires using a different
opener and a different request builder.  This change pulls the call to
urllib2.Request out so that my extension can replace it just like it can
replace urlopener.

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -30,6 +30,7 @@
         self.caps = None
         self.handler = None
         self.urlopener = None
+        self.requestbuilder = None
         u = util.url(path)
         if u.query or u.fragment:
             raise util.Abort(_('unsupported URL component: "%s"') %
@@ -42,6 +43,7 @@
         self.ui.debug('using %s\n' % self._url)
 
         self.urlopener = url.opener(ui, authinfo)
+        self.requestbuilder = urllib2.Request
 
     def __del__(self):
         if self.urlopener:
@@ -111,7 +113,7 @@
             q += sorted(args.items())
         qs = '?%s' % urllib.urlencode(q)
         cu = "%s%s" % (self._url, qs)
-        req = urllib2.Request(cu, data, headers)
+        req = self.requestbuilder(cu, data, headers)
         if data is not None:
             self.ui.debug("sending %s bytes\n" % size)
             req.add_unredirected_header('Content-Length', '%d' % size)


More information about the Mercurial-devel mailing list