Skip to content

Commit d2367c6

Browse files
committed
Clean up urlopen doc string.
Clarifies what is returned when and that the methods are common between the two. Patch by Alexander Liu as part of #22797.
1 parent 13ee7d1 commit d2367c6

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

Lib/urllib/request.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,7 @@ def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
173173
The *cadefault* parameter is ignored.
174174
175175
For http and https urls, this function returns a http.client.HTTPResponse
176-
object which has the following HTTPResponse Objects methods.
177-
178-
For ftp, file, and data urls and requests explicitly handled by legacy
179-
URLopener and FancyURLopener classes, this function returns a
180-
urllib.response.addinfourl object which can work as context manager and has
181-
methods such as:
176+
object which has the following HTTPResponse Objects methods:
182177
183178
* geturl() - return the URL of the resource retrieved, commonly used to
184179
determine if a redirect was followed
@@ -190,6 +185,11 @@ def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
190185
* getcode() - return the HTTP status code of the response. Raises URLError
191186
on errors.
192187
188+
For ftp, file, and data urls and requests explicitly handled by legacy
189+
URLopener and FancyURLopener classes, this function returns a
190+
urllib.response.addinfourl object which can work as context manager and
191+
also support the geturl(), info(), getcode() methods listed above.
192+
193193
Note that *None& may be returned if no handler handles the request (though
194194
the default installed global OpenerDirector uses UnknownHandler to ensure
195195
this never happens).

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ Eric Lindvall
884884
Gregor Lingl
885885
Everett Lipman
886886
Mirko Liss
887+
Alexander Liu
887888
Nick Lockwood
888889
Stephanie Lockwood
889890
Martin von Löwis

0 commit comments

Comments
 (0)