classification
Title: urllib2.urlopen() returns object missing context manager
Type: behavior Stage: committed/rejected
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: URLopener should support context manager protocol
View: 12365
Assigned To: Nosy List: Julian, orsenthil, scode
Priority: normal Keywords:

Created on 2011-07-04 10:18 by scode, last changed 2011-07-04 21:09 by orsenthil. This issue is now closed.

Messages (3)
msg139746 - (view) Author: Peter Schuller (scode) Date: 2011-07-04 10:18
The documentation states it returns a "file-like object". In Python 2.5+ I expect such file-like objects to have a context manager for use with the with statement.

In my particular use-case, the lack comes from urllib.addinfourl but I have not investigated what the possible types returned may be.
msg139797 - (view) Author: Julian Berman (Julian) Date: 2011-07-04 18:03
You probably should bring this up again on #4972 which is being worked on.


(and for the immediate future you have contextlib.closing too in case you hadn't seen it already)
msg139807 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-07-04 21:09
It should be documented that in 2.x series the file-like object does not support context management protocol. I have added the superseder issue number, please see the note as if you really want in 2.x, how you can have it using contextlib and in 3.x the context management protocol support is available.
History
Date User Action Args
2011-07-04 21:09:07orsenthilsetstatus: open -> closed
resolution: duplicate
messages: + msg139807

superseder: URLopener should support context manager protocol
stage: committed/rejected
2011-07-04 18:03:05Juliansetnosy: + Julian
messages: + msg139797
2011-07-04 16:34:50ned.deilysetnosy: + orsenthil
2011-07-04 10:18:24scodecreate