Open files in binary mode.

This commit is contained in:
Guido van Rossum 1997-04-11 19:01:48 +00:00
parent f4f756cf55
commit c511aee0e3
1 changed files with 4 additions and 4 deletions

View File

@ -183,7 +183,7 @@ def retrieve(self, url, filename=None):
result = filename, headers
if self.tempcache is not None:
self.tempcache[url] = result
tfp = open(filename, 'w')
tfp = open(filename, 'wb')
bs = 1024*8
block = fp.read(bs)
while block:
@ -284,12 +284,12 @@ def open_file(self, url):
def open_local_file(self, url):
host, file = splithost(url)
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)
if not port and socket.gethostbyname(host) in (
localhost(), thishost()):
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')
# Use FTP protocol
@ -785,7 +785,7 @@ def test():
print '======'
for k in h.keys(): print k + ':', h[k]
print '======'
fp = open(fn, 'r')
fp = open(fn, 'rb')
data = fp.read()
del fp
print regsub.gsub('\r', '', data)