3232import numpy as np
3333import os
3434import sys
35- import urllib
36- import urllib2
35+
36+ if sys .version_info .major == 3 :
37+ from urllib .request import urlopen , urlparse , url2pathname
38+ from urllib .parse import unquote
39+ else :
40+ from urllib import url2pathname
41+ from urllib2 import urlopen , urlparse , unquote
42+ urlparse = urlparse .urlparse
43+
3744import shutil
3845import tempfile
3946import traceback
@@ -546,7 +553,7 @@ def __init__(self, path=None, url=None, perform_init=True):
546553 self .url = url
547554 self .using_temp_file = False
548555 if url is not None and url .lower ().startswith (file_scheme ):
549- utf8_url = urllib . url2pathname (url [len (file_scheme ):])
556+ utf8_url = url2pathname (url [len (file_scheme ):])
550557 if isinstance (utf8_url , str ):
551558 path = str (utf8_url , 'utf-8' )
552559 else :
@@ -593,7 +600,7 @@ def __init__(self, path=None, url=None, perform_init=True):
593600 # Other URLS, copy them to a tempfile location
594601 #
595602 ext = url [url .rfind ("." ):]
596- src = urllib2 . urlopen (url )
603+ src = urlopen (url )
597604 dest_fd , self .path = tempfile .mkstemp (suffix = ext )
598605 try :
599606 dest = os .fdopen (dest_fd , 'wb' )
@@ -605,8 +612,8 @@ def __init__(self, path=None, url=None, perform_init=True):
605612 self .using_temp_file = True
606613 src .close ()
607614 dest .close ()
608- urlpath = urllib2 . urlparse . urlparse (url )[2 ]
609- filename = urllib2 . unquote (urlpath .split ("/" )[- 1 ])
615+ urlpath = urlparse (url )[2 ]
616+ filename = unquote (urlpath .split ("/" )[- 1 ])
610617 else :
611618 if sys .platform .startswith ("win" ):
612619 self .path = self .path .replace ("/" , os .path .sep )
0 commit comments