This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Valery.Khamenya, docs@python, ezio.melotti, orsenthil, terry.reedy
Date 2011-09-16.17:23:32
SpamBayes Score 4.8268365e-08
Marked as misclassified No
Message-id <1316193813.57.0.779404227637.issue12955@psf.upfronthosting.co.za>
In-reply-to
Content
As I understand this, you are asking that 2.7 urllib2.build_opener().open(), which in 3.x is urllib.request.build_opener().open(), be upgraded to return an object that works as a context manager. Unless the docs say that this should already be the case, this is a feature request for 3.3.

I am unable to test whether this feature is already present (in 3.2.2). Your example line "with urllib2.build_opener().open() as:" has an obvious syntax error. When I correct that and adjust for 3.x

import urllib.request as ur
with ur.build_opener().open() as f:
    pass
#
TypeError: open() takes at least 2 arguments (1 given)

The doc for build_opener says it returns an OpenerDirector instance. help(ur.OpenerDirector.open) just says it needs a 'fullurl'. But when I add 'http:www.python.org' as an argument, I get
urllib.error.URLError: <urlopen error no host given>
I do not know what else is needed.

Please copy and paste the ACTUAL (minimal) code you ran to get the AttributeError.
History
Date User Action Args
2011-09-16 17:23:33terry.reedysetrecipients: + terry.reedy, orsenthil, ezio.melotti, docs@python, Valery.Khamenya
2011-09-16 17:23:33terry.reedysetmessageid: <1316193813.57.0.779404227637.issue12955@psf.upfronthosting.co.za>
2011-09-16 17:23:32terry.reedylinkissue12955 messages
2011-09-16 17:23:32terry.reedycreate