mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
- Issue #11289: smtp.SMTP
class becomes a context manager so it can be used
in a `with` statement. Contributed by Giampaolo Rodola.
This commit is contained in:
parent
5eb3591a41
commit
1f5c958721
4 changed files with 66 additions and 2 deletions
|
@ -269,6 +269,19 @@ class SMTP:
|
|||
pass
|
||||
self.local_hostname = '[%s]' % addr
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
try:
|
||||
code, message = self.docmd("QUIT")
|
||||
if code != 221:
|
||||
raise SMTPResponseException(code, message)
|
||||
except SMTPServerDisconnected:
|
||||
pass
|
||||
finally:
|
||||
self.close()
|
||||
|
||||
def set_debuglevel(self, debuglevel):
|
||||
"""Set the debug output level.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue