Skip to content

Commit

Permalink
MAINT: Revise imports from urllib modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Jan 23, 2020
1 parent 883de8f commit 3493d1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
20 changes: 5 additions & 15 deletions numpy/lib/_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,7 @@ def _isurl(self, path):
"""Test if path is a net location. Tests the scheme and netloc."""

# We do this here to reduce the 'import numpy' initial import time.
if sys.version_info[0] >= 3:
from urllib.parse import urlparse
else:
from urlparse import urlparse
from urllib.parse import urlparse

# BUG : URLs require a scheme string ('http://') to be used.
# www.google.com will fail.
Expand All @@ -325,14 +322,10 @@ def _cache(self, path):
Creates a copy of the file in the datasource cache.
"""
# We import these here because importing urllib2 is slow and
# We import these here because importing urllib is slow and
# a significant fraction of numpy's total import time.
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
from urllib.request import urlopen
from urllib.error import URLError

upath = self.abspath(path)

Expand Down Expand Up @@ -407,10 +400,7 @@ def abspath(self, path):
"""
# We do this here to reduce the 'import numpy' initial import time.
if sys.version_info[0] >= 3:
from urllib.parse import urlparse
else:
from urlparse import urlparse
from urllib.parse import urlparse

# TODO: This should be more robust. Handles case where path includes
# the destpath, but not other sub-paths. Failing case:
Expand Down
8 changes: 2 additions & 6 deletions tools/openblas_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
import shutil
import textwrap
import platform
try:
from urllib.request import urlopen
from urllib.error import HTTPError
except:
#Python2
from urllib2 import urlopen, HTTPError

from tempfile import mkstemp, gettempdir
from urllib.request import urlopen
from urllib.error import HTTPError
import zipfile
import tarfile

Expand Down

0 comments on commit 3493d1b

Please sign in to comment.