diff --git a/IPython/core/display.py b/IPython/core/display.py index c94b0b1..dd34e71 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -516,10 +516,8 @@ class DisplayObject(object): self.data = f.read() elif self.url is not None: try: - try: - from urllib.request import urlopen # Py3 - except ImportError: - from urllib2 import urlopen + # Deferred import + from urllib.request import urlopen response = urlopen(self.url) self.data = response.read() # extract encoding from header, if there is one: diff --git a/IPython/core/extensions.py b/IPython/core/extensions.py index a79fe24..76cab1a 100644 --- a/IPython/core/extensions.py +++ b/IPython/core/extensions.py @@ -155,12 +155,8 @@ class ExtensionManager(Configurable): copy = copyfile else: # Deferred imports - try: - from urllib.parse import urlparse # Py3 - from urllib.request import urlretrieve - except ImportError: - from urlparse import urlparse - from urllib import urlretrieve + from urllib.parse import urlparse + from urllib.request import urlretrieve src_filename = urlparse(url).path.split('/')[-1] copy = urlretrieve diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 970ef65..8b8409e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -3124,10 +3124,7 @@ class InteractiveShell(SingletonConfigurable): except UnicodeDecodeError: if not py_only : # Deferred import - try: - from urllib.request import urlopen # Py3 - except ImportError: - from urllib import urlopen + from urllib.request import urlopen response = urlopen(target) return response.read().decode('latin1') raise ValueError(("'%s' seem to be unreadable.") % target) diff --git a/IPython/lib/display.py b/IPython/lib/display.py index 63da80f..272d413 100644 --- a/IPython/lib/display.py +++ b/IPython/lib/display.py @@ -263,10 +263,9 @@ class YouTubeVideo(IFrame): super(YouTubeVideo, self).__init__(src, width, height, **kwargs) def _repr_jpeg_(self): - try: - from urllib.request import urlopen # Py3 - except ImportError: - from urllib2 import urlopen + # Deferred import + from urllib.request import urlopen + try: return urlopen("https://img.youtube.com/vi/{id}/hqdefault.jpg".format(id=self.id)).read() except IOError: