@@ -100,7 +100,7 @@ The following classes are provided:
100100
101101.. seealso ::
102102
103- Module :mod: `urllib2 `
103+ Module :mod: `urllib.request `
104104 URL opening with automatic cookie handling.
105105
106106 Module :mod: `http.cookies `
@@ -149,11 +149,11 @@ contained :class:`Cookie` objects.
149149 the :class: `CookieJar `'s :class: `CookiePolicy ` instance are true and false
150150 respectively), the :mailheader: `Cookie2 ` header is also added when appropriate.
151151
152- The *request * object (usually a :class: `urllib2. Request ` instance) must support
153- the methods :meth: `get_full_url `, :meth: `get_host `, :meth: ` get_type `,
154- :meth: `unverifiable `, :meth: `get_origin_req_host `, :meth: `has_header `,
155- :meth: `get_header `, :meth: `header_items `, and :meth: `add_unredirected_header `,as
156- documented by :mod: `urllib2 `.
152+ The *request * object (usually a :class: `urllib.request.. Request ` instance)
153+ must support the methods :meth: `get_full_url `, :meth: `get_host `,
154+ :meth: `get_type `, :meth: `unverifiable `, :meth: `get_origin_req_host `,
155+ :meth: `has_header `, :meth: `get_header `, :meth: `header_items `, and
156+ :meth: ` add_unredirected_header `, as documented by :mod: `urllib.request `.
157157
158158
159159.. method :: CookieJar.extract_cookies(response, request)
@@ -166,14 +166,15 @@ contained :class:`Cookie` objects.
166166 as appropriate (subject to the :meth: `CookiePolicy.set_ok ` method's approval).
167167
168168 The *response * object (usually the result of a call to
169- :meth: `urllib2. urlopen `, or similar) should support an :meth: `info ` method,
170- which returns a :class: `email.message.Message ` instance.
169+ :meth: `urllib.request. urlopen `, or similar) should support an :meth: `info `
170+ method, which returns a :class: `email.message.Message ` instance.
171171
172- The *request * object (usually a :class: `urllib2.Request ` instance) must support
173- the methods :meth: `get_full_url `, :meth: `get_host `, :meth: `unverifiable `, and
174- :meth: `get_origin_req_host `, as documented by :mod: `urllib2 `. The request is
175- used to set default values for cookie-attributes as well as for checking that
176- the cookie is allowed to be set.
172+ The *request * object (usually a :class: `urllib.request.Request ` instance)
173+ must support the methods :meth: `get_full_url `, :meth: `get_host `,
174+ :meth: `unverifiable `, and :meth: `get_origin_req_host `, as documented by
175+ :mod: `urllib.request `. The request is used to set default values for
176+ cookie-attributes as well as for checking that the cookie is allowed to be
177+ set.
177178
178179
179180.. method :: CookieJar.set_policy(policy)
@@ -715,31 +716,31 @@ Examples
715716
716717The first example shows the most common usage of :mod: `http.cookiejar `::
717718
718- import http.cookiejar, urllib2
719+ import http.cookiejar, urllib.request
719720 cj = http.cookiejar.CookieJar()
720- opener = urllib2. build_opener(urllib2 .HTTPCookieProcessor(cj))
721+ opener = urllib.request. build_opener(urllib.request .HTTPCookieProcessor(cj))
721722 r = opener.open("http://example.com/")
722723
723724This example illustrates how to open a URL using your Netscape, Mozilla, or Lynx
724725cookies (assumes Unix/Netscape convention for location of the cookies file)::
725726
726- import os, http.cookiejar, urllib2
727+ import os, http.cookiejar, urllib.request
727728 cj = http.cookiejar.MozillaCookieJar()
728729 cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
729- opener = urllib2. build_opener(urllib2 .HTTPCookieProcessor(cj))
730+ opener = urllib.request. build_opener(urllib.request .HTTPCookieProcessor(cj))
730731 r = opener.open("http://example.com/")
731732
732733The next example illustrates the use of :class: `DefaultCookiePolicy `. Turn on
733734RFC 2965 cookies, be more strict about domains when setting and returning
734735Netscape cookies, and block some domains from setting cookies or having them
735736returned::
736737
737- import urllib2
738+ import urllib.request
738739 from http.cookiejar import CookieJar, DefaultCookiePolicy
739740 policy = DefaultCookiePolicy(
740741 rfc2965=True, strict_ns_domain=Policy.DomainStrict,
741742 blocked_domains=["ads.net", ".ads.net"])
742743 cj = CookieJar(policy)
743- opener = urllib2. build_opener(urllib2 .HTTPCookieProcessor(cj))
744+ opener = urllib.request. build_opener(urllib.request .HTTPCookieProcessor(cj))
744745 r = opener.open("http://example.com/")
745746
0 commit comments