Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f7ede4

Browse files
committed
Review the doc changes for the urllib package creation.
1 parent aca8fd7 commit 0f7ede4

9 files changed

Lines changed: 90 additions & 166 deletions

File tree

Doc/howto/urllib2.rst

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
*****************************************************
2-
HOWTO Fetch Internet Resources Using urllib package
3-
*****************************************************
1+
***********************************************************
2+
HOWTO Fetch Internet Resources Using The urllib Package
3+
***********************************************************
44

55
:Author: `Michael Foord <http://www.voidspace.org.uk/python/index.shtml>`_
66

77
.. note::
88

9-
There is an French translation of an earlier revision of this
9+
There is a French translation of an earlier revision of this
1010
HOWTO, available at `urllib2 - Le Manuel manquant
1111
<http://www.voidspace.org.uk/python/articles/urllib2_francais.shtml>`_.
1212

@@ -18,7 +18,7 @@ Introduction
1818
.. sidebar:: Related Articles
1919

2020
You may also find useful the following article on fetching web resources
21-
with Python :
21+
with Python:
2222

2323
* `Basic Authentication <http://www.voidspace.org.uk/python/articles/authentication.shtml>`_
2424

@@ -94,8 +94,8 @@ your browser does when you submit a HTML form that you filled in on the web. Not
9494
all POSTs have to come from forms: you can use a POST to transmit arbitrary data
9595
to your own application. In the common case of HTML forms, the data needs to be
9696
encoded in a standard way, and then passed to the Request object as the ``data``
97-
argument. The encoding is done using a function from the ``urllib.parse`` library
98-
*not* from ``urllib.request``. ::
97+
argument. The encoding is done using a function from the :mod:`urllib.parse`
98+
library. ::
9999

100100
import urllib.parse
101101
import urllib.request
@@ -115,7 +115,7 @@ forms - see `HTML Specification, Form Submission
115115
<http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13>`_ for more
116116
details).
117117

118-
If you do not pass the ``data`` argument, urllib.request uses a **GET** request. One
118+
If you do not pass the ``data`` argument, urllib uses a **GET** request. One
119119
way in which GET and POST requests differ is that POST requests often have
120120
"side-effects": they change the state of the system in some way (for example by
121121
placing an order with the website for a hundredweight of tinned spam to be
@@ -182,13 +182,15 @@ which comes after we have a look at what happens when things go wrong.
182182
Handling Exceptions
183183
===================
184184

185-
*urllib.error* raises ``URLError`` when it cannot handle a response (though as usual
185+
*urlopen* raises ``URLError`` when it cannot handle a response (though as usual
186186
with Python APIs, builtin exceptions such as ValueError, TypeError etc. may also
187187
be raised).
188188

189189
``HTTPError`` is the subclass of ``URLError`` raised in the specific case of
190190
HTTP URLs.
191191

192+
The exception classes are exported from the :mod:`urllib.error` module.
193+
192194
URLError
193195
--------
194196

@@ -214,7 +216,7 @@ Every HTTP response from the server contains a numeric "status code". Sometimes
214216
the status code indicates that the server is unable to fulfil the request. The
215217
default handlers will handle some of these responses for you (for example, if
216218
the response is a "redirection" that requests the client fetch the document from
217-
a different URL, urllib.request will handle that for you). For those it can't handle,
219+
a different URL, urllib will handle that for you). For those it can't handle,
218220
urlopen will raise an ``HTTPError``. Typical errors include '404' (page not
219221
found), '403' (request forbidden), and '401' (authentication required).
220222

@@ -380,15 +382,15 @@ info and geturl
380382

381383
The response returned by urlopen (or the ``HTTPError`` instance) has two useful
382384
methods ``info`` and ``geturl`` and is defined in the module
383-
``urllib.response``.
385+
:mod:`urllib.response`.
384386

385387
**geturl** - this returns the real URL of the page fetched. This is useful
386388
because ``urlopen`` (or the opener object used) may have followed a
387389
redirect. The URL of the page fetched may not be the same as the URL requested.
388390

389391
**info** - this returns a dictionary-like object that describes the page
390392
fetched, particularly the headers sent by the server. It is currently an
391-
``http.client.HTTPMessage`` instance.
393+
:class:`http.client.HTTPMessage` instance.
392394

393395
Typical headers include 'Content-length', 'Content-type', and so on. See the
394396
`Quick Reference to HTTP Headers <http://www.cs.tut.fi/~jkorpela/http.html>`_
@@ -508,7 +510,7 @@ not correct.
508510
Proxies
509511
=======
510512

511-
**urllib.request** will auto-detect your proxy settings and use those. This is through
513+
**urllib** will auto-detect your proxy settings and use those. This is through
512514
the ``ProxyHandler`` which is part of the normal handler chain. Normally that's
513515
a good thing, but there are occasions when it may not be helpful [#]_. One way
514516
to do this is to setup our own ``ProxyHandler``, with no proxies defined. This
@@ -528,8 +530,8 @@ is done using similar steps to setting up a `Basic Authentication`_ handler : ::
528530
Sockets and Layers
529531
==================
530532

531-
The Python support for fetching resources from the web is layered.
532-
urllib.request uses the http.client library, which in turn uses the socket library.
533+
The Python support for fetching resources from the web is layered. urllib uses
534+
the :mod:`http.client` library, which in turn uses the socket library.
533535

534536
As of Python 2.3 you can specify how long a socket should wait for a response
535537
before timing out. This can be useful in applications which have to fetch web
@@ -573,9 +575,9 @@ This document was reviewed and revised by John Lee.
573575
`Quick Reference to HTTP Headers`_.
574576
.. [#] In my case I have to use a proxy to access the internet at work. If you
575577
attempt to fetch *localhost* URLs through this proxy it blocks them. IE
576-
is set to use the proxy, which urllib2 picks up on. In order to test
577-
scripts with a localhost server, I have to prevent urllib2 from using
578+
is set to use the proxy, which urllib picks up on. In order to test
579+
scripts with a localhost server, I have to prevent urllib from using
578580
the proxy.
579-
.. [#] urllib2 opener for SSL proxy (CONNECT method): `ASPN Cookbook Recipe
581+
.. [#] urllib opener for SSL proxy (CONNECT method): `ASPN Cookbook Recipe
580582
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195>`_.
581583

Doc/library/contextlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ Functions provided:
9898
And lets you write code like this::
9999

100100
from contextlib import closing
101-
import urllib.request
101+
from urllib.request import urlopen
102102

103-
with closing(urllib.request.urlopen('http://www.python.org')) as page:
103+
with closing(urlopen('http://www.python.org')) as page:
104104
for line in page:
105105
print(line)
106106

Doc/library/http.client.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
This module defines classes which implement the client side of the HTTP and
1515
HTTPS protocols. It is normally not used directly --- the module
16-
:mod:`urllib.request`
17-
uses it to handle URLs that use HTTP and HTTPS.
16+
:mod:`urllib.request` uses it to handle URLs that use HTTP and HTTPS.
1817

1918
.. note::
2019

Doc/library/robotparser.rst

Lines changed: 0 additions & 73 deletions
This file was deleted.

Doc/library/urllib.error.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@
22
==================================================================
33

44
.. module:: urllib.error
5-
:synopsis: Next generation URL opening library.
5+
:synopsis: Exception classes raised by urllib.request.
66
.. moduleauthor:: Jeremy Hylton <[email protected]>
77
.. sectionauthor:: Senthil Kumaran <[email protected]>
88

99

10-
The :mod:`urllib.error` module defines exception classes raise by
11-
urllib.request. The base exception class is URLError, which inherits from
12-
IOError.
10+
The :mod:`urllib.error` module defines the exception classes for exceptions
11+
raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`,
12+
which inherits from :exc:`IOError`.
1313

1414
The following exceptions are raised by :mod:`urllib.error` as appropriate:
1515

16-
1716
.. exception:: URLError
1817

19-
The handlers raise this exception (or derived exceptions) when they run into a
20-
problem. It is a subclass of :exc:`IOError`.
18+
The handlers raise this exception (or derived exceptions) when they run into
19+
a problem. It is a subclass of :exc:`IOError`.
2120

2221
.. attribute:: reason
2322

24-
The reason for this error. It can be a message string or another exception
25-
instance (:exc:`socket.error` for remote URLs, :exc:`OSError` for local
26-
URLs).
23+
The reason for this error. It can be a message string or another
24+
exception instance (:exc:`socket.error` for remote URLs, :exc:`OSError`
25+
for local URLs).
2726

2827

2928
.. exception:: HTTPError
3029

31-
Though being an exception (a subclass of :exc:`URLError`), an :exc:`HTTPError`
32-
can also function as a non-exceptional file-like return value (the same thing
33-
that :func:`urlopen` returns). This is useful when handling exotic HTTP
34-
errors, such as requests for authentication.
30+
Though being an exception (a subclass of :exc:`URLError`), an
31+
:exc:`HTTPError` can also function as a non-exceptional file-like return
32+
value (the same thing that :func:`urlopen` returns). This is useful when
33+
handling exotic HTTP errors, such as requests for authentication.
3534

3635
.. attribute:: code
3736

38-
An HTTP status code as defined in `RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html>`_.
39-
This numeric value corresponds to a value found in the dictionary of
40-
codes as found in :attr:`http.server.BaseHTTPRequestHandler.responses`.
37+
An HTTP status code as defined in `RFC 2616
38+
<http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds
39+
to a value found in the dictionary of codes as found in
40+
:attr:`http.server.BaseHTTPRequestHandler.responses`.
4141

4242
.. exception:: ContentTooShortError(msg[, content])
4343

44-
This exception is raised when the :func:`urlretrieve` function detects that the
45-
amount of the downloaded data is less than the expected amount (given by the
46-
*Content-Length* header). The :attr:`content` attribute stores the downloaded
47-
(and supposedly truncated) data.
44+
This exception is raised when the :func:`urlretrieve` function detects that
45+
the amount of the downloaded data is less than the expected amount (given by
46+
the *Content-Length* header). The :attr:`content` attribute stores the
47+
downloaded (and supposedly truncated) data.
4848

0 commit comments

Comments
 (0)