Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
04bc5b9e
Commit
04bc5b9e
authored
Mar 14, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #747320: Use email.utils.formatdate() to avoid code duplication
in BaseHTTPRequestHandler Initial patch by karlcow.
parent
0647ef05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
Lib/http/server.py
Lib/http/server.py
+2
-6
Lib/test/test_httpservers.py
Lib/test/test_httpservers.py
+14
-0
No files found.
Lib/http/server.py
View file @
04bc5b9e
...
...
@@ -87,6 +87,7 @@ __all__ = [
"SimpleHTTPRequestHandler"
,
"CGIHTTPRequestHandler"
,
]
import
email.utils
import
html
import
http.client
import
io
...
...
@@ -566,12 +567,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
"""Return the current date and time formatted for a message header."""
if
timestamp
is
None
:
timestamp
=
time
.
time
()
year
,
month
,
day
,
hh
,
mm
,
ss
,
wd
,
y
,
z
=
time
.
gmtime
(
timestamp
)
s
=
"%s, %02d %3s %4d %02d:%02d:%02d GMT"
%
(
self
.
weekdayname
[
wd
],
day
,
self
.
monthname
[
month
],
year
,
hh
,
mm
,
ss
)
return
s
return
email
.
utils
.
formatdate
(
timestamp
,
usegmt
=
True
)
def
log_date_time_string
(
self
):
"""Return the current time formatted for logging."""
...
...
Lib/test/test_httpservers.py
View file @
04bc5b9e
...
...
@@ -17,6 +17,7 @@ import urllib.parse
import
html
import
http.client
import
tempfile
import
time
from
io
import
BytesIO
import
unittest
...
...
@@ -873,6 +874,19 @@ class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
self
.
handler
.
handle
()
self
.
assertRaises
(
StopIteration
,
next
,
close_values
)
def
test_date_time_string
(
self
):
now
=
time
.
time
()
# this is the old code that formats the timestamp
year
,
month
,
day
,
hh
,
mm
,
ss
,
wd
,
y
,
z
=
time
.
gmtime
(
now
)
expected
=
"%s, %02d %3s %4d %02d:%02d:%02d GMT"
%
(
self
.
handler
.
weekdayname
[
wd
],
day
,
self
.
handler
.
monthname
[
month
],
year
,
hh
,
mm
,
ss
)
self
.
assertEqual
(
self
.
handler
.
date_time_string
(
timestamp
=
now
),
expected
)
class
SimpleHTTPRequestHandlerTestCase
(
unittest
.
TestCase
):
""" Test url parsing """
def
setUp
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment