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
277640af
Commit
277640af
authored
Oct 17, 2015
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #25411: Improved Unicode support in SMTPHandler.
parent
4de9dae5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
12 deletions
+17
-12
Lib/logging/handlers.py
Lib/logging/handlers.py
+12
-10
Lib/test/test_logging.py
Lib/test/test_logging.py
+2
-2
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/logging/handlers.py
View file @
277640af
# Copyright 2001-201
3
by Vinay Sajip. All Rights Reserved.
# Copyright 2001-201
5
by Vinay Sajip. All Rights Reserved.
#
#
# Permission to use, copy, modify, and distribute this software and its
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# documentation for any purpose and without fee is hereby granted,
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
Additional handlers for the logging package for Python. The core package is
Additional handlers for the logging package for Python. The core package is
based on PEP 282 and comments thereto in comp.lang.python.
based on PEP 282 and comments thereto in comp.lang.python.
Copyright (C) 2001-201
3
Vinay Sajip. All Rights Reserved.
Copyright (C) 2001-201
5
Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
To use, simply 'import logging.handlers' and log away!
"""
"""
...
@@ -965,24 +965,26 @@ class SMTPHandler(logging.Handler):
...
@@ -965,24 +965,26 @@ class SMTPHandler(logging.Handler):
"""
"""
try
:
try
:
import
smtplib
import
smtplib
from
email.utils
import
formatdate
from
email.message
import
EmailMessage
import
email.utils
port
=
self
.
mailport
port
=
self
.
mailport
if
not
port
:
if
not
port
:
port
=
smtplib
.
SMTP_PORT
port
=
smtplib
.
SMTP_PORT
smtp
=
smtplib
.
SMTP
(
self
.
mailhost
,
port
,
timeout
=
self
.
timeout
)
smtp
=
smtplib
.
SMTP
(
self
.
mailhost
,
port
,
timeout
=
self
.
timeout
)
msg
=
self
.
format
(
record
)
msg
=
EmailMessage
(
)
msg
=
"From: %s
\
r
\
n
To: %s
\
r
\
n
Subject: %s
\
r
\
n
Date: %s
\
r
\
n
\
r
\
n
%s"
%
(
msg
[
'From'
]
=
self
.
fromaddr
self
.
fromaddr
,
msg
[
'To'
]
=
','
.
join
(
self
.
toaddrs
)
","
.
join
(
self
.
toaddrs
),
msg
[
'Subject'
]
=
self
.
getSubject
(
record
)
self
.
getSubject
(
record
),
msg
[
'Date'
]
=
email
.
utils
.
localtime
()
formatdate
(),
msg
)
msg
.
set_content
(
self
.
format
(
record
)
)
if
self
.
username
:
if
self
.
username
:
if
self
.
secure
is
not
None
:
if
self
.
secure
is
not
None
:
smtp
.
ehlo
()
smtp
.
ehlo
()
smtp
.
starttls
(
*
self
.
secure
)
smtp
.
starttls
(
*
self
.
secure
)
smtp
.
ehlo
()
smtp
.
ehlo
()
smtp
.
login
(
self
.
username
,
self
.
password
)
smtp
.
login
(
self
.
username
,
self
.
password
)
smtp
.
send
mail
(
self
.
fromaddr
,
self
.
toaddrs
,
msg
)
smtp
.
send
_message
(
msg
)
smtp
.
quit
()
smtp
.
quit
()
except
Exception
:
except
Exception
:
self
.
handleError
(
record
)
self
.
handleError
(
record
)
...
...
Lib/test/test_logging.py
View file @
277640af
...
@@ -935,7 +935,7 @@ class SMTPHandlerTest(BaseTest):
...
@@ -935,7 +935,7 @@ class SMTPHandlerTest(BaseTest):
timeout=self.TIMEOUT)
timeout=self.TIMEOUT)
self.assertEqual(h.toaddrs, ['you'])
self.assertEqual(h.toaddrs, ['you'])
self.messages = []
self.messages = []
r = logging.makeLogRecord({'msg': 'Hello'})
r = logging.makeLogRecord({'msg': 'Hello
\
u2713
'})
self.handled = threading.Event()
self.handled = threading.Event()
h.handle(r)
h.handle(r)
self.handled.wait(self.TIMEOUT) # 14314: don't wait forever
self.handled.wait(self.TIMEOUT) # 14314: don't wait forever
...
@@ -946,7 +946,7 @@ class SMTPHandlerTest(BaseTest):
...
@@ -946,7 +946,7 @@ class SMTPHandlerTest(BaseTest):
self.assertEqual(mailfrom, 'me')
self.assertEqual(mailfrom, 'me')
self.assertEqual(rcpttos, ['you'])
self.assertEqual(rcpttos, ['you'])
self.assertIn('
\
n
Subject: Log
\
n
', data)
self.assertIn('
\
n
Subject: Log
\
n
', data)
self.assertTrue(data.endswith('
\
n
\
n
Hello'))
self.assertTrue(data.endswith('
\
n
\
n
Hello
\
u2713
'))
h.close()
h.close()
def process_message(self, *args):
def process_message(self, *args):
...
...
Misc/NEWS
View file @
277640af
...
@@ -96,6 +96,9 @@ Core and Builtins
...
@@ -96,6 +96,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #25411: Improved Unicode support in SMTPHandler through better use of
the email package. Thanks to user simon04 for the patch.
- Issue #25380: Fixed protocol for the STACK_GLOBAL opcode in
- Issue #25380: Fixed protocol for the STACK_GLOBAL opcode in
pickletools.opcodes.
pickletools.opcodes.
...
...
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