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