Skip to content

Commit 7afbaa9

Browse files
committed
Update docs for dropped HTTP client code
In 02b79cd7#diff-5b5ad4c6a0c0168d28c2bf52c57980ca5883e83bbb44de82db6c9715307a49bcR26-R31, custom HTTP client code was dropped along with various parameters for customizing requests made by `feedparser`. However there are still various references to these parameters in the docs; this commit drops references to anything no longer supported and makes some minimal updates to reference what you should now do instead.
1 parent 89fde03 commit 7afbaa9

File tree

3 files changed

+25
-123
lines changed

3 files changed

+25
-123
lines changed

docs/http-authentication.rst

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Password-Protected Feeds
33

44
:program:`Universal Feed Parser` supports downloading and parsing
55
password-protected feeds that are protected by :abbr:`HTTP (Hypertext Transfer Protocol)`
6-
authentication. Both basic and digest authentication are supported.
6+
basic authentication. For any other types of authentication, you can handle the
7+
authentication yourself and then parse the retrieved feed.
78

89

910
Downloading a feed protected by basic authentication (the easy way)
@@ -21,85 +22,19 @@ In this example, the username is test and the password is basic.
2122
>>> d.feed.title
2223
'Sample Feed'
2324
24-
The same technique works for digest authentication. (Technically,
25-
:program:`Universal Feed Parser` will attempt basic authentication first, but
26-
if that fails and the server indicates that it requires digest authentication,
27-
:program:`Universal Feed Parser` will automatically re-request the feed with
28-
the appropriate digest authentication headers. *This means that this technique
29-
will send your password to the server in an easily decryptable form.*)
3025
26+
Downloading a feed with other types of authentication
27+
-----------------------------------------------------
3128

32-
.. _example.auth.inline.digest:
29+
For any other type of authentication, you should retrieve the feed yourself and
30+
handle authentication as needed (e.g. via `requests
31+
<https://requests.readthedocs.io>` - this is what :program:`Universal Feed Parser`
32+
uses internally), and then you can just call ``feedparser.parse`` on the
33+
retrieved feed content.
3334

34-
Downloading a feed protected by digest authentication (the easy but horribly insecure way)
35-
------------------------------------------------------------------------------------------
3635

37-
In this example, the username is test and the password is digest.
38-
39-
.. code-block:: pycon
40-
41-
>>> import feedparser
42-
>>> d = feedparser.parse('http://test:[email protected]/docs/examples/digest_auth.xml')
43-
>>> d.feed.title
44-
'Sample Feed'
45-
46-
47-
48-
You can also construct a HTTPBasicAuthHandler that contains the password
49-
information, then pass that as a handler to the ``parse`` function.
50-
HTTPBasicAuthHandler is part of the standard `urllib2 <http://docs.python.org/lib/module-urllib2.html>`_ module.
51-
52-
Downloading a feed protected by :abbr:`HTTP (Hypertext Transfer Protocol)` basic authentication (the hard way)
53-
--------------------------------------------------------------------------------------------------------------
54-
55-
.. code-block:: python
56-
57-
import urllib2, feedparser
58-
59-
# Construct the authentication handler
60-
auth = urllib2.HTTPBasicAuthHandler()
61-
62-
# Add password information: realm, host, user, password.
63-
# A single handler can contain passwords for multiple sites;
64-
# urllib2 will sort out which passwords get sent to which sites
65-
# based on the realm and host of the URL you're retrieving
66-
auth.add_password('BasicTest', 'feedparser.org', 'test', 'basic')
67-
68-
# Pass the authentication handler to the feed parser.
69-
# handlers is a list because there might be more than one
70-
# type of handler (urllib2 defines lots of different ones,
71-
# and you can build your own)
72-
d = feedparser.parse(
73-
'$READTHEDOCS_CANONICAL_URL/examples/basic_auth.xml',
74-
handlers=[auth],
75-
)
76-
77-
78-
79-
Digest authentication is handled in much the same way, by constructing an
80-
HTTPDigestAuthHandler and populating it with the necessary realm, host, user,
81-
and password information. This is more secure than
82-
:ref:`stuffing the username and password in the URL <example.auth.inline.digest>`,
83-
since the password will be encrypted before being sent to the server.
84-
85-
86-
Downloading a feed protected by :abbr:`HTTP (Hypertext Transfer Protocol)` digest authentication (the secure way)
87-
-----------------------------------------------------------------------------------------------------------------
88-
89-
.. code-block:: python
90-
91-
import urllib2, feedparser
92-
93-
auth = urllib2.HTTPDigestAuthHandler()
94-
auth.add_password('DigestTest', 'feedparser.org', 'test', 'digest')
95-
d = feedparser.parse(
96-
'$READTHEDOCS_CANONICAL_URL/examples/digest_auth.xml',
97-
handlers=[auth],
98-
)
99-
100-
101-
The examples so far have assumed that you know in advance that the feed is
102-
password-protected. But what if you don't know?
36+
Determining that a feed is password-protected
37+
---------------------------------------------
10338

10439
If you try to download a password-protected feed without sending all the proper
10540
password information, the server will return an
@@ -113,12 +48,7 @@ you will need to parse it yourself. Everything before the first space is the
11348
type of authentication (probably ``Basic`` or ``Digest``), which controls which
11449
type of handler you'll need to construct. The realm name is given as
11550
realm="foo" -- so foo would be your first argument to auth.add_password. Other
116-
information in the www-authenticate header is probably safe to ignore; the
117-
:file:`urllib2` module will handle it for you.
118-
119-
120-
Determining that a feed is password-protected
121-
---------------------------------------------
51+
information in the www-authenticate header is probably safe to ignore.
12252

12353
.. code-block:: pycon
12454

docs/http-other.rst

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
Other :abbr:`HTTP (Hypertext Transfer Protocol)` Headers
22
========================================================
33

4-
You can specify additional :abbr:`HTTP (Hypertext Transfer Protocol)` request
5-
headers as a dictionary. When you download a feed from a remote web server,
4+
When you download a feed from a remote web server,
65
:program:`Universal Feed Parser` exposes the complete set of
76
:abbr:`HTTP (Hypertext Transfer Protocol)` response headers as a dictionary.
87

98

10-
.. _example.http.headers.request:
11-
12-
Sending custom :abbr:`HTTP (Hypertext Transfer Protocol)` request headers
13-
-------------------------------------------------------------------------
14-
15-
.. code-block:: python
16-
17-
import feedparser
18-
d = feedparser.parse(
19-
'$READTHEDOCS_CANONICAL_URL/examples/atom03.xml',
20-
request_headers={'Cache-control': 'max-age=0'},
21-
)
22-
23-
24-
Accessing other :abbr:`HTTP (Hypertext Transfer Protocol)` response headers
25-
---------------------------------------------------------------------------
9+
Accessing :abbr:`HTTP (Hypertext Transfer Protocol)` response headers
10+
---------------------------------------------------------------------
2611

2712
.. code-block:: pycon
2813
@@ -39,3 +24,13 @@ Accessing other :abbr:`HTTP (Hypertext Transfer Protocol)` response headers
3924
'content-length': '883',
4025
'connection': 'close',
4126
'content-type': 'application/xml'}
27+
28+
29+
Customizing :abbr:`HTTP (Hypertext Transfer Protocol)` request headers
30+
----------------------------------------------------------------------
31+
32+
If you need to customize aspects of requests for a feed, such as the request
33+
headers used, you should retrieve the feed yourself with any settings you need
34+
(e.g. via `requests <https://requests.readthedocs.io>` - this is what
35+
:program:`Universal Feed Parser` uses internally), and then you can just call
36+
``feedparser.parse`` on the retrieved feed content.

docs/http-useragent.rst

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ you should change the User-Agent to your application name and
1919
Customizing the User-Agent
2020
--------------------------
2121

22-
.. code-block:: pycon
23-
24-
>>> import feedparser
25-
>>> d = feedparser.parse('$READTHEDOCS_CANONICAL_URL/examples/atom10.xml',
26-
... agent='MyApp/1.0 +http://example.com/')
27-
28-
You can also set the User-Agent once, globally, and then call the ``parse``
29-
function normally.
30-
31-
32-
Customizing the User-Agent permanently
33-
--------------------------------------
34-
3522
.. code-block:: pycon
3623
3724
>>> import feedparser
@@ -44,13 +31,3 @@ download a feed from a web server. This is discouraged, because it is a
4431
violation of `RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36>`_.
4532
The default behavior is to send a blank referrer, and you should never need to
4633
override this.
47-
48-
49-
Customizing the referrer
50-
------------------------
51-
52-
.. code-block:: pycon
53-
54-
>>> import feedparser
55-
>>> d = feedparser.parse('$READTHEDOCS_CANONICAL_URL/examples/atom10.xml',
56-
... referrer='http://example.com/')

0 commit comments

Comments
 (0)