##// END OF EJS Templates
urllib2.urlopen is not a contextmanager
MinRK -
Show More
@@ -2163,6 +2163,7 Currently the magic system has the following functions:\n"""
2163 2163 raise ValueError('%%load only works with .py files: %s' % arg_s)
2164 2164 if remote_url:
2165 2165 import urllib2
2166 fileobj = urllib2.urlopen(arg_s)
2166 2167 # While responses have a .info().getencoding() way of asking for
2167 2168 # their encoding, in *many* cases the return value is bogus. In
2168 2169 # the wild, servers serving utf-8 but declaring latin-1 are
@@ -2171,8 +2172,8 Currently the magic system has the following functions:\n"""
2171 2172 # rely on the headers. Short of building complex encoding-guessing
2172 2173 # logic, going with utf-8 is a simple solution likely to be right
2173 2174 # in most real-world cases.
2174 with urllib2.urlopen(arg_s) as fileobj:
2175 2175 linesource = fileobj.read().decode('utf-8', 'replace').splitlines()
2176 fileobj.close()
2176 2177 else:
2177 2178 with open(arg_s) as fileobj:
2178 2179 linesource = fileobj.read().splitlines()
General Comments 0
You need to be logged in to leave comments. Login now