Skip to content

Commit

Permalink
Merge pull request #15398 from mwtoews/urllib
Browse files Browse the repository at this point in the history
MAINT: Revise imports from urllib modules
  • Loading branch information
charris committed Jan 24, 2020
2 parents c61e667 + 3493d1b commit 4c32890
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 @@ -304,10 +304,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 @@ -324,14 +321,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 @@ -406,10 +399,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 4c32890

Please sign in to comment.