[issue12955] urllib.request example should use with ... as:

2015-04-12 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 6d5336a193cc by Berker Peksag in branch '3.4':
Issue #12955: Change the urlopen() examples to use context managers where 
appropriate.
https://hg.python.org/cpython/rev/6d5336a193cc

New changeset 08adaaf08697 by Berker Peksag in branch 'default':
Issue #12955: Change the urlopen() examples to use context managers where 
appropriate.
https://hg.python.org/cpython/rev/08adaaf08697

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2015-04-12 Thread Berker Peksag

Berker Peksag added the comment:

Great patch. Thanks Martin.

--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2015-02-14 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
nosy: +berker.peksag
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2015-02-08 Thread Martin Panter

Martin Panter added the comment:

Issue 22755 is about the example arms race for contextlib.closing().

--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2015-02-08 Thread Martin Panter

Martin Panter added the comment:

Here is a patch to change the urlopen() examples to use context managers where 
appropriate.

There were also a few examples of handling HTTPError which I didn’t touch, 
because the whole file object versus exception object thing is probably a 
separate can of worms.

--
keywords: +patch
Added file: http://bugs.python.org/file38049/urlopen-with.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2014-07-14 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
versions: +Python 3.4, Python 3.5 -Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2013-12-05 Thread Alexander Boyd

Changes by Alexander Boyd a...@opengroove.org:


--
nosy: +javawizard

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2012-02-03 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

Senthil:
http://docs.python.org/dev/library/contextlib.html#contextlib.closing
currently has this example:

from urllib.request import urlopen
with closing(urlopen('http://www.python.org')) as page:

which is misleading in that the object returned from urlopen
class 'http.client.HTTPResponse'
has __enter__ and __exit__ methods and therefore is a c.m. in itself and does 
not need to be wrapped in closing(). I did not really understand from your 
comment whether there is any need to use closing() with anything returned in 
urllib. 

At the moment, shelves are not C.M.s, and would make better examples, but 
#13896 suggests 'fixing' that also.

--
nosy: +ncoghlan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2012-02-03 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Either we find a commonly used stdlib class that is not a context manager but 
has a close method and is not going to become a context manager (I can’t see 
why such a thing would be), or we can add something like: “closing is useful 
with code that you can’t change to add context management, for example 
urllib.urlopen before Python 3.3”.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2011-09-17 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

[Terry]
 But when I add 'http:www.python.org' as an argument, I get
 urllib.error.URLError: urlopen error no host given

Your URI lacks a host (netloc, in RFC parlance) component:
 urllib.parse.urlparse('http:python.org')
ParseResult(scheme='http', netloc='', path='python.org', params='', query='', 
fragment='')

--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2011-09-16 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

On 3.2.2, your example (adapted) produces
 
2945 characters fetched

So, as Senthil said, the requested feature already exists. But it cannot be 
added to the 2.7 series; the Python 2.7 *language* is feature frozen. 2.7.z bug 
fixes serve to make the implementation better match the intended language.

Prior to the addition of with..., the standard way to close things was with 
explicit .close() or implicit closing when the function returned or the program 
exited. In the 3.2 docs, 20.5.21. Examples, there are several examples with
  f = some opener
  do something with f
  (closing ignored)
Where possible, these could and should be changed in 3.2+ docs to
  with some opener as f:
do something with f
to promote the new idiom.  This had been done in other chapters. Perhaps there 
is also a need for 'X supports the context manager protocol' to be added here 
or there. But showing that in the examples would make the point.

I have changed the title of this issue to match.

--
components: +Documentation -Library (Lib)
stage: test needed - needs patch
title: urllib2.build_opener().open() is not friendly to with ... as: - 
urllib.request example should use with ... as:
versions: +Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2011-09-16 Thread Valery Khamenya

Valery Khamenya khame...@gmail.com added the comment:

Guys, in my item 2 the simplistic goal was stated clearly: open, read and close.

Do you confirm that this basic sequence is not supported by urllib2 under 2.7 ?

(I just requested for a tiny documentation update entry)

regards,
Valery

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12955] urllib.request example should use with ... as:

2011-09-16 Thread Senthil Kumaran

Senthil Kumaran sent...@uthcode.com added the comment:

Valery, yes. I shall update 2.7 documentation with this known limitation and 
3.x documentation with the example usage scenarios.

Thanks!

--
assignee: docs@python - orsenthil

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12955
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com