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