mercurial/httpconnection.py
changeset 28883 032c4c2f802a
parent 28526 47b0cee25e88
child 29227 dffe78d80a6c
--- a/mercurial/httpconnection.py	Thu Apr 07 00:05:48 2016 +0000
+++ b/mercurial/httpconnection.py	Wed Apr 06 23:22:12 2016 +0000
@@ -13,8 +13,6 @@
 import logging
 import os
 import socket
-import urllib
-import urllib2
 
 from .i18n import _
 from . import (
@@ -23,6 +21,9 @@
     util,
 )
 
+urlerr = util.urlerr
+urlreq = util.urlreq
+
 # moved here from url.py to avoid a cycle
 class httpsendfile(object):
     """This is a wrapper around the objects returned by python's "open".
@@ -123,10 +124,10 @@
 # Subclass BOTH of these because otherwise urllib2 "helpfully"
 # reinserts them since it notices we don't include any subclasses of
 # them.
-class http2handler(urllib2.HTTPHandler, urllib2.HTTPSHandler):
+class http2handler(urlreq.httphandler, urlreq.httpshandler):
     def __init__(self, ui, pwmgr):
         global _configuredlogging
-        urllib2.AbstractHTTPHandler.__init__(self)
+        urlreq.abstracthttphandler.__init__(self)
         self.ui = ui
         self.pwmgr = pwmgr
         self._connections = {}
@@ -187,7 +188,7 @@
             proxy = None
 
         if not host:
-            raise urllib2.URLError('no host given')
+            raise urlerr.urlerror('no host given')
 
         connkey = use_ssl, host, proxy
         allconns = self._connections.get(connkey, [])
@@ -217,13 +218,13 @@
             h.request(req.get_method(), path, req.data, headers)
             r = h.getresponse()
         except socket.error as err: # XXX what error?
-            raise urllib2.URLError(err)
+            raise urlerr.urlerror(err)
 
         # Pick apart the HTTPResponse object to get the addinfourl
         # object initialized properly.
         r.recv = r.read
 
-        resp = urllib.addinfourl(r, r.headers, req.get_full_url())
+        resp = urlreq.addinfourl(r, r.headers, req.get_full_url())
         resp.code = r.status
         resp.msg = r.reason
         return resp