diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-14 12:17:43 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-14 12:24:40 -0600 |
commit | c70025a46d655a19c6c7d64dbbf96849093afb18 (patch) | |
tree | d1ed0a80aa0a9358ae52a3ac2f2ea28897f5101b /numpy/lib/_datasource.py | |
parent | 6c47259eec0ec20c1150c2b29994de59a3158964 (diff) | |
download | numpy-c70025a46d655a19c6c7d64dbbf96849093afb18.tar.gz |
2to3: Apply urllib fixer.
Various functions have been moved around in the stdlib for Python 3,
this fixes that up so that the code is valid in both Python 2 and
Python 3.
Note: monkey patching the stlib urlopen for testing looks a bit hokey
to me, but I don't see an easier, more reliable way to do the test.
Closes #3090.
Diffstat (limited to 'numpy/lib/_datasource.py')
-rw-r--r-- | numpy/lib/_datasource.py | 16 |
1 files changed, 12 insertions, 4 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): |