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