]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Open files in binary mode.
authorGuido van Rossum <guido@python.org>
Fri, 11 Apr 1997 19:01:48 +0000 (19:01 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 11 Apr 1997 19:01:48 +0000 (19:01 +0000)
Lib/urllib.py

index 49c9032b223a4f701f62e206c1fd6fed7cbeb7c8..e57311b519b5105d5c2788e56e038409ccc80cc4 100644 (file)
@@ -183,7 +183,7 @@ class URLopener:
                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 @@ class URLopener:
        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)