##// END OF EJS Templates
Add encoding explanatory comment
Fernando Perez -
Show More
@@ -96,6 +96,7 b' def needs_local_scope(func):'
96 96 # Used for exception handling in magic_edit
97 97 class MacroToEdit(ValueError): pass
98 98
99 # Taken from PEP 263, this is the official encoding regexp.
99 100 _encoding_declaration_re = re.compile(r"^#.*coding[:=]\s*([-\w.]+)")
100 101
101 102 #***************************************************************************
@@ -2163,6 +2164,14 b' Currently the magic system has the following functions:\\n"""'
2163 2164 if remote_url:
2164 2165 import urllib2
2165 2166 fileobj = urllib2.urlopen(arg_s)
2167 # While responses have a .info().getencoding() way of asking for
2168 # their encoding, in *many* cases the return value is bogus. In
2169 # the wild, servers serving utf-8 but declaring latin-1 are
2170 # extremely common, as the old HTTP standards specify latin-1 as
2171 # the default but many modern filesystems use utf-8. So we can NOT
2172 # rely on the headers. Short of building complex encoding-guessing
2173 # logic, going with utf-8 is a simple solution likely to be right
2174 # in most real-world cases.
2166 2175 linesource = fileobj.read().decode('utf-8', 'replace').splitlines()
2167 2176 else:
2168 2177 fileobj = linesource = open(arg_s)
General Comments 0
You need to be logged in to leave comments. Login now