[Python-checkins] python/dist/src/Lib SimpleHTTPServer.py, 1.22, 1.22.2.1

jlgijsbers at users.sourceforge.net jlgijsbers at users.sourceforge.net
Mon Jan 10 10:27:20 CET 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2084

Modified Files:
      Tag: release24-maint
	SimpleHTTPServer.py 
Log Message:
Backport for bug #839496: always read files in binary mode. Opening files in
text mode may cause newline translations, making the actual size of the content
transmitted *less* than the content-length.


Index: SimpleHTTPServer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/SimpleHTTPServer.py,v
retrieving revision 1.22
retrieving revision 1.22.2.1
diff -u -d -r1.22 -r1.22.2.1
--- SimpleHTTPServer.py	21 Aug 2004 10:43:29 -0000	1.22
+++ SimpleHTTPServer.py	10 Jan 2005 09:27:17 -0000	1.22.2.1
@@ -70,12 +70,11 @@
             else:
                 return self.list_directory(path)
         ctype = self.guess_type(path)
-        if ctype.startswith('text/'):
-            mode = 'r'
-        else:
-            mode = 'rb'
         try:
-            f = open(path, mode)
+            # Always read in binary mode. Opening files in text mode may cause
+            # newline translations, making the actual size of the content
+            # transmitted *less* than the content-length!
+            f = open(path, 'rb')
         except IOError:
             self.send_error(404, "File not found")
             return None



More information about the Python-checkins mailing list