[issue12365] URLopener should support context manager protocol

2012-03-13 Thread Jeff McNeil
Jeff McNeil j...@jmcneil.net added the comment: Documentation patch to outline the use of context manager protocol attached. Trying to cleanup any bugs with my name on them. -- keywords: +patch Added file: http://bugs.python.org/file24817/urllib_request_doc.patch

[issue12365] URLopener should support context manager protocol

2012-03-13 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: Thanks for the patch. - This function returns a file-like object with two additional methods from + This function returns a file-like object that supports the Context Manager + protocol, with two additional methods from The

[issue12365] URLopener should support context manager protocol

2012-03-13 Thread Jeff McNeil
Jeff McNeil j...@jmcneil.net added the comment: Yeah, updated with different wording and proper caps. I left the piece in regarding the use without the context manager as I think that's probably the more common use case still. -- Added file:

[issue12365] URLopener should support context manager protocol

2012-03-13 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 8625627969aa by Senthil Kumaran in branch '3.2': closes Issue12365 - Add an example explaining the context manager use case of urllib.urlopen http://hg.python.org/cpython/rev/8625627969aa New changeset 074e12441ed6

[issue12365] URLopener should support context manager protocol

2012-03-13 Thread Senthil Kumaran
Senthil Kumaran sent...@uthcode.com added the comment: Thanks for the patch, Jeff McNeil. I pushed the patches to 3.2 and 3.3 docs. Since it is a documentation change (an explaination rather), I did not update the NEWS. Thanks again! -- ___ Python

[issue12365] URLopener should support context manager protocol

2011-06-21 Thread Senthil Kumaran
Senthil Kumaran sent...@uthcode.com added the comment: I forgot completely, but in Python3, Issue5418 had already added support to addinfourl. It is now possible to write code like import urllib.request with urllib.request.urlopen('http://www.python.org') as req: res = req.read() But

[issue12365] URLopener should support context manager protocol

2011-06-20 Thread Senthil Kumaran
Senthil Kumaran sent...@uthcode.com added the comment: well, urlopen does return an file like object for socket connection which closes itself when it goes out of scope, as you raised this bug, I think a more explicit context manager like behavior can be tried. But I am afraid that it would

[issue12365] URLopener should support context manager protocol

2011-06-20 Thread Jeff McNeil
Jeff McNeil j...@jmcneil.net added the comment: Isn't that snippet (contextlib.closing(...)) passing the result of urllib.urlopen to closing? The urlopen call is a factory function of sorts, so there's really no context to manage on its part? Maybe it's just a matter of making that clear?

[issue12365] URLopener should support context manager protocol

2011-06-19 Thread Jeff McNeil
New submission from Jeff McNeil j...@jmcneil.net: Per discussion within Issue10050, URLopener ought to support the context manager protocol. That allows more idiomatic usage and doesn't require calls to contextlib.closing for use with the 'with' statement. If agreed, I'll create a patch.

[issue12365] URLopener should support context manager protocol

2011-06-19 Thread Jeff McNeil
Changes by Jeff McNeil j...@jmcneil.net: -- type: - feature request ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12365 ___ ___ Python-bugs-list

[issue12365] URLopener should support context manager protocol

2011-06-19 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: +1. -- nosy: +eric.araujo stage: - needs patch versions: +Python 3.3 -Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12365 ___

[issue12365] URLopener should support context manager protocol

2011-06-19 Thread Jeff McNeil
Jeff McNeil j...@jmcneil.net added the comment: In looking at this again, I may have spoken too soon. It seems that addinfobase HTTPResponse already handle this. As this is what's returned by the opener, then what I was shooting for should already be handled. -- status: open - closed