Commit c511aee0 authored by Guido van Rossum's avatar Guido van Rossum

Open files in binary mode.

parent f4f756cf
...@@ -183,7 +183,7 @@ class URLopener: ...@@ -183,7 +183,7 @@ class URLopener:
result = filename, headers result = filename, headers
if self.tempcache is not None: if self.tempcache is not None:
self.tempcache[url] = result self.tempcache[url] = result
tfp = open(filename, 'w') tfp = open(filename, 'wb')
bs = 1024*8 bs = 1024*8
block = fp.read(bs) block = fp.read(bs)
while block: while block:
...@@ -284,12 +284,12 @@ class URLopener: ...@@ -284,12 +284,12 @@ class URLopener:
def open_local_file(self, url): def open_local_file(self, url):
host, file = splithost(url) host, file = splithost(url)
if not host: if not host:
return addinfourl(open(url2pathname(file), 'r'), noheaders(), 'file:'+file) return addinfourl(open(url2pathname(file), 'rb'), noheaders(), 'file:'+file)
host, port = splitport(host) host, port = splitport(host)
if not port and socket.gethostbyname(host) in ( if not port and socket.gethostbyname(host) in (
localhost(), thishost()): localhost(), thishost()):
file = unquote(file) file = unquote(file)
return addinfourl(open(url2pathname(file), 'r'), noheaders(), 'file:'+file) return addinfourl(open(url2pathname(file), 'rb'), noheaders(), 'file:'+file)
raise IOError, ('local file error', 'not on local host') raise IOError, ('local file error', 'not on local host')
# Use FTP protocol # Use FTP protocol
...@@ -785,7 +785,7 @@ def test(): ...@@ -785,7 +785,7 @@ def test():
print '======' print '======'
for k in h.keys(): print k + ':', h[k] for k in h.keys(): print k + ':', h[k]
print '======' print '======'
fp = open(fn, 'r') fp = open(fn, 'rb')
data = fp.read() data = fp.read()
del fp del fp
print regsub.gsub('\r', '', data) print regsub.gsub('\r', '', data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment