Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f7cddc

Browse files
committed
Issue839496: SimpleHTTPServer should open all files in binary mode.
Forward-port of 38255 (2005/01/15!)This was already fixed in 2.4, but never merged into trunk...py3k is already right, thanks to the bytes/str distinction!Should be backported to 2.5.
1 parentaaca978 commit0f7cddc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

‎Lib/SimpleHTTPServer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ def send_head(self):
7979
else:
8080
returnself.list_directory(path)
8181
ctype=self.guess_type(path)
82-
ifctype.startswith('text/'):
83-
mode='r'
84-
else:
85-
mode='rb'
8682
try:
87-
f=open(path,mode)
83+
# Always read in binary mode. Opening files in text mode may cause
84+
# newline translations, making the actual size of the content
85+
# transmitted *less* than the content-length!
86+
f=open(path,'rb')
8887
exceptIOError:
8988
self.send_error(404,"File not found")
9089
returnNone

‎Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #839496: SimpleHTTPServer used to open text files in text mode. This is
40+
both unnecessary (HTTP allows text content to be sent in several forms) and
41+
wrong because the actual transmitted size could differ with the
42+
content-length. The problem had been corrected in the 2.4 branch, but never
43+
merged into trunk.
44+
3945
- Issue #2663: add filtering capability to shutil.copytree().
4046

4147
- Issue #1622: Correct interpretation of various ZIP header fields.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp