diff options
author | Georg Brandl <georg@python.org> | 2008-06-23 11:44:14 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-06-23 11:44:14 (GMT) |
commit | 029986af249f71a5603110a0f5f0b18d0f335828 (patch) | |
tree | 90fafdd902e370d05952d900b7270043ad4c0053 /Doc | |
parent | 0f7ede45693be57ba51c7aa23a0d841f160de874 (diff) | |
download | cpython-029986af249f71a5603110a0f5f0b18d0f335828.zip cpython-029986af249f71a5603110a0f5f0b18d0f335828.tar.gz cpython-029986af249f71a5603110a0f5f0b18d0f335828.tar.bz2 |
Fix old urllib/urllib2/urlparse usage.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/http.cookiejar.rst | 39 | ||||
-rw-r--r-- | Doc/library/urllib.request.rst | 4 |
2 files changed, 22 insertions, 21 deletions
diff --git a/Doc/library/http.cookiejar.rst b/Doc/library/http.cookiejar.rst index f8ffb82..79c89c7 100644 --- a/Doc/library/http.cookiejar.rst +++ b/Doc/library/http.cookiejar.rst @@ -100,7 +100,7 @@ The following classes are provided: .. seealso:: - Module :mod:`urllib2` + Module :mod:`urllib.request` URL opening with automatic cookie handling. Module :mod:`http.cookies` @@ -149,11 +149,11 @@ contained :class:`Cookie` objects. the :class:`CookieJar`'s :class:`CookiePolicy` instance are true and false respectively), the :mailheader:`Cookie2` header is also added when appropriate. - The *request* object (usually a :class:`urllib2.Request` instance) must support - the methods :meth:`get_full_url`, :meth:`get_host`, :meth:`get_type`, - :meth:`unverifiable`, :meth:`get_origin_req_host`, :meth:`has_header`, - :meth:`get_header`, :meth:`header_items`, and :meth:`add_unredirected_header`,as - documented by :mod:`urllib2`. + The *request* object (usually a :class:`urllib.request..Request` instance) + must support the methods :meth:`get_full_url`, :meth:`get_host`, + :meth:`get_type`, :meth:`unverifiable`, :meth:`get_origin_req_host`, + :meth:`has_header`, :meth:`get_header`, :meth:`header_items`, and + :meth:`add_unredirected_header`, as documented by :mod:`urllib.request`. .. method:: CookieJar.extract_cookies(response, request) @@ -166,14 +166,15 @@ contained :class:`Cookie` objects. as appropriate (subject to the :meth:`CookiePolicy.set_ok` method's approval). The *response* object (usually the result of a call to - :meth:`urllib2.urlopen`, or similar) should support an :meth:`info` method, - which returns a :class:`email.message.Message` instance. + :meth:`urllib.request.urlopen`, or similar) should support an :meth:`info` + method, which returns a :class:`email.message.Message` instance. - The *request* object (usually a :class:`urllib2.Request` instance) must support - the methods :meth:`get_full_url`, :meth:`get_host`, :meth:`unverifiable`, and - :meth:`get_origin_req_host`, as documented by :mod:`urllib2`. The request is - used to set default values for cookie-attributes as well as for checking that - the cookie is allowed to be set. + The *request* object (usually a :class:`urllib.request.Request` instance) + must support the methods :meth:`get_full_url`, :meth:`get_host`, + :meth:`unverifiable`, and :meth:`get_origin_req_host`, as documented by + :mod:`urllib.request`. The request is used to set default values for + cookie-attributes as well as for checking that the cookie is allowed to be + set. .. method:: CookieJar.set_policy(policy) @@ -715,18 +716,18 @@ Examples The first example shows the most common usage of :mod:`http.cookiejar`:: - import http.cookiejar, urllib2 + import http.cookiejar, urllib.request cj = http.cookiejar.CookieJar() - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) + opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) r = opener.open("http://example.com/") This example illustrates how to open a URL using your Netscape, Mozilla, or Lynx cookies (assumes Unix/Netscape convention for location of the cookies file):: - import os, http.cookiejar, urllib2 + import os, http.cookiejar, urllib.request cj = http.cookiejar.MozillaCookieJar() cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt")) - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) + opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) r = opener.open("http://example.com/") The next example illustrates the use of :class:`DefaultCookiePolicy`. Turn on @@ -734,12 +735,12 @@ RFC 2965 cookies, be more strict about domains when setting and returning Netscape cookies, and block some domains from setting cookies or having them returned:: - import urllib2 + import urllib.request from http.cookiejar import CookieJar, DefaultCookiePolicy policy = DefaultCookiePolicy( rfc2965=True, strict_ns_domain=Policy.DomainStrict, blocked_domains=["ads.net", ".ads.net"]) cj = CookieJar(policy) - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) + opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) r = opener.open("http://example.com/") diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index d124d9a..c506829 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1077,7 +1077,7 @@ Adding HTTP headers: Use the *headers* argument to the :class:`Request` constructor, or:: - import urllib + import urllib.request req = urllib.request.Request('http://www.example.com/') req.add_header('Referer', 'http://www.python.org/') r = urllib.request.urlopen(req) @@ -1085,7 +1085,7 @@ Use the *headers* argument to the :class:`Request` constructor, or:: :class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to every :class:`Request`. To change this:: - import urllib + import urllib.request opener = urllib.request.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] opener.open('http://www.example.com/') |