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
17160fd6
Commit
17160fd6
authored
Mar 15, 2012
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #14314: Improved SMTP timeout handling.
parent
7cc7033c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
Lib/logging/handlers.py
Lib/logging/handlers.py
+5
-2
Lib/test/test_logging.py
Lib/test/test_logging.py
+2
-1
No files found.
Lib/logging/handlers.py
View file @
17160fd6
...
...
@@ -867,7 +867,7 @@ class SMTPHandler(logging.Handler):
A handler class which sends an SMTP email for each logging event.
"""
def
__init__
(
self
,
mailhost
,
fromaddr
,
toaddrs
,
subject
,
credentials
=
None
,
secure
=
None
):
credentials
=
None
,
secure
=
None
,
timeout
=
1.0
):
"""
Initialize the handler.
...
...
@@ -881,6 +881,8 @@ class SMTPHandler(logging.Handler):
will be either an empty tuple, or a single-value tuple with the name
of a keyfile, or a 2-value tuple with the names of the keyfile and
certificate file. (This tuple is passed to the `starttls` method).
A timeout in seconds can be specified for the SMTP connection (the
default is one second).
"""
logging
.
Handler
.
__init__
(
self
)
if
isinstance
(
mailhost
,
tuple
):
...
...
@@ -897,6 +899,7 @@ class SMTPHandler(logging.Handler):
self
.
toaddrs
=
toaddrs
self
.
subject
=
subject
self
.
secure
=
secure
self
.
timeout
=
timeout
def
getSubject
(
self
,
record
):
"""
...
...
@@ -919,7 +922,7 @@ class SMTPHandler(logging.Handler):
port
=
self
.
mailport
if
not
port
:
port
=
smtplib
.
SMTP_PORT
smtp
=
smtplib
.
SMTP
(
self
.
mailhost
,
port
)
smtp
=
smtplib
.
SMTP
(
self
.
mailhost
,
port
,
timeout
=
self
.
timeout
)
msg
=
self
.
format
(
record
)
msg
=
"From: %s
\
r
\
n
To: %s
\
r
\
n
Subject: %s
\
r
\
n
Date: %s
\
r
\
n
\
r
\
n
%s"
%
(
self
.
fromaddr
,
...
...
Lib/test/test_logging.py
View file @
17160fd6
...
...
@@ -936,8 +936,9 @@ class SMTPHandlerTest(BaseTest):
r = logging.makeLogRecord({'msg': 'Hello'})
self.handled = threading.Event()
h.handle(r)
self.handled.wait(
)
self.handled.wait(
5.0) # 14314: don't wait forever
server.stop()
self.assertTrue(self.handled.is_set())
self.assertEqual(len(self.messages), 1)
peer, mailfrom, rcpttos, data = self.messages[0]
self.assertEqual(mailfrom, 'me')
...
...
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