summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornjsmith <njs@pobox.com>2013-04-15 02:45:47 -0700
committernjsmith <njs@pobox.com>2013-04-15 02:45:47 -0700
commita196d789fbb8e72672c73ffcf99c687b5fd3ec3d (patch)
treed1ed0a80aa0a9358ae52a3ac2f2ea28897f5101b
parent6c47259eec0ec20c1150c2b29994de59a3158964 (diff)
parentc70025a46d655a19c6c7d64dbbf96849093afb18 (diff)
downloadnumpy-a196d789fbb8e72672c73ffcf99c687b5fd3ec3d.tar.gz
Merge pull request #3248 from charris/2to3-apply-urllib-fixer
2to3: Apply urllib fixer.
-rw-r--r--numpy/lib/_datasource.py16
-rw-r--r--numpy/lib/tests/test__datasource.py16
-rwxr-xr-xtools/py3tool.py2
3 files changed, 23 insertions, 11 deletions
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py
index 2d35065b0..617acdac1 100644
--- a/numpy/lib/_datasource.py
+++ b/numpy/lib/_datasource.py
@@ -275,8 +275,12 @@ class DataSource (object):
"""
# We import these here because importing urllib2 is slow and
# a significant fraction of numpy's total import time.
- from urllib2 import urlopen
- from urllib2 import URLError
+ if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ from urllib.error import URLError
+ else:
+ from urllib2 import urlopen
+ from urllib2 import URLError
upath = self.abspath(path)
@@ -421,8 +425,12 @@ class DataSource (object):
"""
# We import this here because importing urllib2 is slow and
# a significant fraction of numpy's total import time.
- from urllib2 import urlopen
- from urllib2 import URLError
+ if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ from urllib.error import URLError
+ else:
+ from urllib2 import urlopen
+ from urllib2 import URLError
# Test local path
if os.path.exists(path):
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py
index 3933fdcde..8d3e32b1b 100644
--- a/numpy/lib/tests/test__datasource.py
+++ b/numpy/lib/tests/test__datasource.py
@@ -1,20 +1,21 @@
from __future__ import division, absolute_import, print_function
import os
-import urllib2
import sys
import numpy.lib._datasource as datasource
from tempfile import mkdtemp, mkstemp, NamedTemporaryFile
from shutil import rmtree
-from urllib2 import URLError
from numpy.compat import asbytes
from numpy.testing import *
-
if sys.version_info[0] >= 3:
+ import urllib.request as urllib_request
from urllib.parse import urlparse
+ from urllib.error import URLError
else:
+ import urllib2 as urllib_request
from urlparse import urlparse
+ from urllib2 import URLError
def urlopen_stub(url, data=None):
'''Stub to replace urlopen for testing.'''
@@ -24,14 +25,17 @@ def urlopen_stub(url, data=None):
else:
raise URLError('Name or service not known')
+# setup and teardown
old_urlopen = None
+
def setup():
global old_urlopen
- old_urlopen = urllib2.urlopen
- urllib2.urlopen = urlopen_stub
+
+ old_urlopen = urllib_request.urlopen
+ urllib_request.urlopen = urlopen_stub
def teardown():
- urllib2.urlopen = old_urlopen
+ urllib_request.urlopen = old_urlopen
# A valid website for more robust testing
http_path = 'http://www.google.com/'
diff --git a/tools/py3tool.py b/tools/py3tool.py
index a6fd5b3f4..d3eb60958 100755
--- a/tools/py3tool.py
+++ b/tools/py3tool.py
@@ -90,7 +90,7 @@ FIXES_TO_SKIP = [
'tuple_params',
# 'types',
# 'unicode',
-# 'urllib',
+ 'urllib',
# 'ws_comma',
'xrange',
'xreadlines',