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
4d8eee97
Commit
4d8eee97
authored
Apr 14, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
Merge #17498: Defer SMTPServerDisconnected errors until the next command.
parents
7dc5f0af
afb151a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
Lib/smtplib.py
Lib/smtplib.py
+15
-3
Lib/test/test_smtplib.py
Lib/test/test_smtplib.py
+13
-0
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/smtplib.py
View file @
4d8eee97
...
...
@@ -478,6 +478,18 @@ class SMTP:
"""SMTP '
rset
' command -- resets session."""
return self.docmd("rset")
def _rset(self):
"""Internal '
rset
' command which ignores any SMTPServerDisconnected error.
Used internally in the library, since the server disconnected error
should appear to the application when the *next* command is issued, if
we are doing an internal "safety" reset.
"""
try:
self.rset()
except SMTPServerDisconnected:
pass
def noop(self):
"""SMTP '
noop
' command -- doesn'
t
do
anything
:
>
"""
return self.docmd("noop")
...
...
@@ -762,7 +774,7 @@ class SMTP:
if
code
==
421
:
self
.
close
()
else
:
self
.
rset
()
self
.
_
rset
()
raise
SMTPSenderRefused
(
code
,
resp
,
from_addr
)
senderrs
=
{}
if
isinstance
(
to_addrs
,
str
):
...
...
@@ -776,14 +788,14 @@ class SMTP:
raise
SMTPRecipientsRefused
(
senderrs
)
if
len
(
senderrs
)
==
len
(
to_addrs
):
# the server refused all our recipients
self
.
rset
()
self
.
_
rset
()
raise
SMTPRecipientsRefused
(
senderrs
)
(
code
,
resp
)
=
self
.
data
(
msg
)
if
code
!=
250
:
if
code
==
421
:
self
.
close
()
else
:
self
.
rset
()
self
.
_
rset
()
raise
SMTPDataError
(
code
,
resp
)
#if we got here then somebody got our mail
return
senderrs
...
...
Lib/test/test_smtplib.py
View file @
4d8eee97
...
...
@@ -619,6 +619,7 @@ class SimSMTPChannel(smtpd.SMTPChannel):
data_response
=
None
rcpt_count
=
0
rset_count
=
0
disconnect
=
0
def
__init__
(
self
,
extra_features
,
*
args
,
**
kw
):
self
.
_extrafeatures
=
''
.
join
(
...
...
@@ -684,6 +685,8 @@ class SimSMTPChannel(smtpd.SMTPChannel):
super
().
smtp_MAIL
(
arg
)
else
:
self
.
push
(
self
.
mail_response
)
if
self
.
disconnect
:
self
.
close_when_done
()
def
smtp_RCPT
(
self
,
arg
):
if
self
.
rcpt_response
is
None
:
...
...
@@ -875,6 +878,16 @@ class SMTPSimTests(unittest.TestCase):
#TODO: add tests for correct AUTH method fallback now that the
#test infrastructure can support it.
# Issue 17498: make sure _rset does not raise SMTPServerDisconnected exception
def
test__rest_from_mail_cmd
(
self
):
smtp
=
smtplib
.
SMTP
(
HOST
,
self
.
port
,
local_hostname
=
'localhost'
,
timeout
=
15
)
smtp
.
noop
()
self
.
serv
.
_SMTPchannel
.
mail_response
=
'451 Requested action aborted'
self
.
serv
.
_SMTPchannel
.
disconnect
=
True
with
self
.
assertRaises
(
smtplib
.
SMTPSenderRefused
):
smtp
.
sendmail
(
'John'
,
'Sally'
,
'test message'
)
self
.
assertIsNone
(
smtp
.
sock
)
# Issue 5713: make sure close, not rset, is called if we get a 421 error
def
test_421_from_mail_cmd
(
self
):
smtp
=
smtplib
.
SMTP
(
HOST
,
self
.
port
,
local_hostname
=
'localhost'
,
timeout
=
15
)
...
...
Misc/NEWS
View file @
4d8eee97
...
...
@@ -46,6 +46,11 @@ Core and Builtins
Library
-------
- Issue #17498: Some SMTP servers disconnect after certain errors, violating
strict RFC conformance. Instead of losing the error code when we issue the
subsequent RSET, smtplib now returns the error code and defers raising the
SMTPServerDisconnected error until the next command is issued.
- Issue #17826: setting an iterable side_effect on a mock function created by
create_autospec now works. Patch by Kushal Das.
...
...
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