Mercurial > public > mercurial-scm > hg-stable
diff mercurial/httppeer.py @ 28883:032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
author | timeless <timeless@mozdev.org> |
---|---|
date | Wed, 06 Apr 2016 23:22:12 +0000 |
parents | ae53ecc47414 |
children | 269f7ea08983 |
line wrap: on
line diff
--- a/mercurial/httppeer.py Thu Apr 07 00:05:48 2016 +0000 +++ b/mercurial/httppeer.py Wed Apr 06 23:22:12 2016 +0000 @@ -13,8 +13,6 @@ import os import socket import tempfile -import urllib -import urllib2 import zlib from .i18n import _ @@ -29,6 +27,9 @@ wireproto, ) +urlerr = util.urlerr +urlreq = util.urlreq + def zgenerator(f): zd = zlib.decompressobj() try: @@ -59,7 +60,7 @@ self.ui.debug('using %s\n' % self._url) self.urlopener = url.opener(ui, authinfo) - self.requestbuilder = urllib2.Request + self.requestbuilder = urlreq.request def __del__(self): if self.urlopener: @@ -105,7 +106,7 @@ # object rather than a basestring canmungedata = not data or isinstance(data, basestring) if postargsok and canmungedata: - strargs = urllib.urlencode(sorted(args.items())) + strargs = urlreq.urlencode(sorted(args.items())) if strargs: if not data: data = strargs @@ -119,7 +120,7 @@ headersize = int(httpheader.split(',', 1)[0]) if headersize > 0: # The headers can typically carry more data than the URL. - encargs = urllib.urlencode(sorted(args.items())) + encargs = urlreq.urlencode(sorted(args.items())) headerfmt = 'X-HgArg-%s' contentlen = headersize - len(headerfmt % '000' + ': \r\n') headernum = 0 @@ -132,7 +133,7 @@ headers['Vary'] = ','.join(varyheaders) else: q += sorted(args.items()) - qs = '?%s' % urllib.urlencode(q) + qs = '?%s' % urlreq.urlencode(q) cu = "%s%s" % (self._url, qs) size = 0 if util.safehasattr(data, 'length'): @@ -150,7 +151,7 @@ req.add_unredirected_header('Content-Length', '%d' % size) try: resp = self.urlopener.open(req) - except urllib2.HTTPError as inst: + except urlerr.httperror as inst: if inst.code == 401: raise error.Abort(_('authorization failed')) raise