classification
Title: smtplib context manager
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: barry Nosy List: SilentGhost, barry, giampaolo.rodola, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2011-02-22 17:05 by giampaolo.rodola, last changed 2011-03-15 19:28 by giampaolo.rodola. This issue is now closed.

Files
File name Uploaded Description Edit
smtplib_context_manager.patch giampaolo.rodola, 2011-02-22 17:18
Messages (11)
msg129096 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-02-22 17:05
Patch in attachment provides a context manager for SMTP class so that it can be used with the "with" statement.
msg129099 - (view) Author: SilentGhost (SilentGhost) Date: 2011-02-22 17:16
you didn't attach anything, Giampaolo.
msg129102 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-02-22 17:18
Ouch! Here. =)
msg129104 - (view) Author: SilentGhost (SilentGhost) Date: 2011-02-22 17:24
is print really necessary in the test?

Also, I think it would be better to unpack the tuple in test, rather then index it.
msg129105 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-02-22 17:26
> is print really necessary in the test?

no, my mistake
msg130971 - (view) Author: SilentGhost (SilentGhost) Date: 2011-03-15 13:32
A couple more minor issues:

1. Double space required at the beginning of the "Here is a ..." sentence in Doc/library/smtplib.rst
2. in __exit__ method: "msg" is the variable name assigned from docmd('QUIT') but "errmsg" is used when raising exception
3. in test I'd rather prefer seeing stmp.noop() unpacked:
    code, _ = smtp.noop()
4. extra line #118 in test_smtplib
5. is there any way to test SMTPResponseException?
msg131008 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2011-03-15 17:55
Thanks for the contribution!  It seems like a reasonable new feature, so I'll get this landed in 3.3.  Probably should use :versionadded: instead (thanks gps).  I'll address SilentGhost's issues in the commit.
msg131017 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-03-15 18:40
@barry I have commit privileges, but no problem if you want to commit it.
msg131019 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2011-03-15 18:50
On Mar 15, 2011, at 06:40 PM, Giampaolo Rodola' wrote:

>
>Giampaolo Rodola' <g.rodola@gmail.com> added the comment:
>
>@barry I have commit privileges, but no problem if you want to commit it.

@giampaolo: I'd like to do it (and am almost ready to), mostly to test out hg
workflow, but also because I have some additions which address SilentGhost's
comments.  Thanks!  (Don't worry, you'll get credit in NEWS :).
msg131020 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-03-15 18:51
Go on, no prob.
msg131025 - (view) Author: Roundup Robot (python-dev) Date: 2011-03-15 19:24
New changeset a6a94cfb75e9 by Barry Warsaw in branch 'default':
- Issue #11289: `smtp.SMTP` class becomes a context manager so it can be used
http://hg.python.org/cpython/rev/a6a94cfb75e9
History
Date User Action Args
2011-03-15 19:28:10giampaolo.rodolasetnosy: barry, pitrou, giampaolo.rodola, SilentGhost, python-dev
type: enhancement
stage: resolved
2011-03-15 19:27:38barrysetnosy: barry, pitrou, giampaolo.rodola, SilentGhost, python-dev
resolution: accepted
2011-03-15 19:27:25barrysetstatus: open -> closed
nosy: barry, pitrou, giampaolo.rodola, SilentGhost, python-dev
2011-03-15 19:24:06python-devsetnosy: + python-dev
messages: + msg131025
2011-03-15 18:51:51giampaolo.rodolasetnosy: barry, pitrou, giampaolo.rodola, SilentGhost
messages: + msg131020
2011-03-15 18:50:28barrysetnosy: barry, pitrou, giampaolo.rodola, SilentGhost
messages: + msg131019
2011-03-15 18:40:27giampaolo.rodolasetnosy: barry, pitrou, giampaolo.rodola, SilentGhost
messages: + msg131017
2011-03-15 18:33:13SilentGhostlinkissue4972 dependencies
2011-03-15 17:55:35barrysetassignee: barry

messages: + msg131008
nosy: + barry
2011-03-15 13:32:31SilentGhostsetnosy: pitrou, giampaolo.rodola, SilentGhost
messages: + msg130971
2011-02-22 17:26:00giampaolo.rodolasetnosy: pitrou, giampaolo.rodola, SilentGhost
messages: + msg129105
2011-02-22 17:24:26SilentGhostsetnosy: pitrou, giampaolo.rodola, SilentGhost
messages: + msg129104
2011-02-22 17:18:35giampaolo.rodolasetfiles: + smtplib_context_manager.patch

messages: + msg129102
keywords: + patch
nosy: pitrou, giampaolo.rodola, SilentGhost
2011-02-22 17:16:17SilentGhostsetnosy: + SilentGhost
messages: + msg129099
components: + Library (Lib)
2011-02-22 17:05:04giampaolo.rodolacreate