diff mercurial/statichttprepo.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 2380889f8f52
children c1696430254f
line wrap: on
line diff
--- a/mercurial/statichttprepo.py	Thu Apr 07 00:05:48 2016 +0000
+++ b/mercurial/statichttprepo.py	Wed Apr 06 23:22:12 2016 +0000
@@ -11,8 +11,6 @@
 
 import errno
 import os
-import urllib
-import urllib2
 
 from .i18n import _
 from . import (
@@ -28,6 +26,9 @@
     util,
 )
 
+urlerr = util.urlerr
+urlreq = util.urlreq
+
 class httprangereader(object):
     def __init__(self, url, opener):
         # we assume opener has HTTPRangeHandler
@@ -45,7 +46,7 @@
     def seek(self, pos):
         self.pos = pos
     def read(self, bytes=None):
-        req = urllib2.Request(self.url)
+        req = urlreq.request(self.url)
         end = ''
         if bytes:
             end = self.pos + bytes - 1
@@ -56,10 +57,10 @@
             f = self.opener.open(req)
             data = f.read()
             code = f.code
-        except urllib2.HTTPError as inst:
+        except urlerr.httperror as inst:
             num = inst.code == 404 and errno.ENOENT or None
             raise IOError(num, inst)
-        except urllib2.URLError as inst:
+        except urlerr.urlerror as inst:
             raise IOError(None, inst.reason[1])
 
         if code == 200:
@@ -92,7 +93,7 @@
         def __call__(self, path, mode='r', *args, **kw):
             if mode not in ('r', 'rb'):
                 raise IOError('Permission denied')
-            f = "/".join((self.base, urllib.quote(path)))
+            f = "/".join((self.base, urlreq.quote(path)))
             return httprangereader(f, urlopener)
 
         def join(self, path):