##// END OF EJS Templates
Defer import of urllib
Thomas Kluyver -
Show More
@@ -20,8 +20,6 b' Authors:'
20 20 import os
21 21 from shutil import copyfile
22 22 import sys
23 from urllib import urlretrieve
24 from urlparse import urlparse
25 23
26 24 from IPython.core.error import UsageError
27 25 from IPython.config.configurable import Configurable
@@ -171,6 +169,8 b' class ExtensionManager(Configurable):'
171 169 src_filename = os.path.basename(url)
172 170 copy = copyfile
173 171 else:
172 from urllib import urlretrieve # Deferred imports
173 from urlparse import urlparse
174 174 src_filename = urlparse(url).path.split('/')[-1]
175 175 copy = urlretrieve
176 176
@@ -28,7 +28,6 b' import runpy'
28 28 import sys
29 29 import tempfile
30 30 import types
31 import urllib
32 31 from io import open as io_open
33 32
34 33 from IPython.config.configurable import SingletonConfigurable
@@ -2989,7 +2988,8 b' class InteractiveShell(SingletonConfigurable):'
2989 2988 return openpy.read_py_url(utarget, skip_encoding_cookie=skip_encoding_cookie)
2990 2989 except UnicodeDecodeError:
2991 2990 if not py_only :
2992 response = urllib.urlopen(target)
2991 from urllib import urlopen # Deferred import
2992 response = urlopen(target)
2993 2993 return response.read().decode('latin1')
2994 2994 raise ValueError(("'%s' seem to be unreadable.") % utarget)
2995 2995
@@ -19,7 +19,6 b' import json'
19 19 import os
20 20 import re
21 21 import sys
22 from urllib2 import urlopen
23 22
24 23 # Our own packages
25 24 from IPython.core.error import TryNext, StdinNotImplementedError, UsageError
@@ -151,6 +150,7 b' class CodeMagics(Magics):'
151 150 }
152 151 }).encode('utf-8')
153 152
153 from urllib2 import urlopen # Deferred import
154 154 response = urlopen("https://api.github.com/gists", post_data)
155 155 response_data = json.loads(response.read().decode('utf-8'))
156 156 return response_data['html_url']
@@ -2,8 +2,6 b''
2 2
3 3 Authors : MinRK, gregcaporaso, dannystaple
4 4 """
5 import urllib
6
7 5 from os.path import exists, isfile, splitext, abspath, join, isdir
8 6 from os import walk, sep
9 7
@@ -41,7 +39,8 b' class YouTubeVideo(object):'
41 39 def _repr_html_(self):
42 40 """return YouTube embed iframe for this video id"""
43 41 if self.params:
44 params = "?" + urllib.urlencode(self.params)
42 from urllib import urlencode # Deferred import
43 params = "?" + urlencode(self.params)
45 44 else:
46 45 params = ""
47 46 return """
@@ -9,7 +9,6 b' from __future__ import absolute_import'
9 9 import io
10 10 from io import TextIOWrapper, BytesIO
11 11 import re
12 import urllib
13 12
14 13 cookie_re = re.compile(ur"coding[:=]\s*([-\w.]+)", re.UNICODE)
15 14 cookie_comment_re = re.compile(ur"^\s*#.*coding[:=]\s*([-\w.]+)", re.UNICODE)
@@ -205,7 +204,8 b" def read_py_url(url, errors='replace', skip_encoding_cookie=True):"
205 204 -------
206 205 A unicode string containing the contents of the file.
207 206 """
208 response = urllib.urlopen(url)
207 from urllib import urlopen # Deferred import for faster start
208 response = urlopen(url)
209 209 buffer = io.BytesIO(response.read())
210 210 return source_to_unicode(buffer, errors, skip_encoding_cookie)
211 211
General Comments 0
You need to be logged in to leave comments. Login now