1+ :mod: `http.cookiejar ` --- Cookie handling for HTTP clients
2+ ==========================================================
13
2- :mod: `cookielib ` --- Cookie handling for HTTP clients
3- =====================================================
4-
5- .. module :: cookielib
4+ .. module :: http.cookiejar
65 :synopsis: Classes for automatic handling of HTTP cookies.
76..
moduleauthor ::
John J. Lee <[email protected] > 87..
sectionauthor ::
John J. Lee <[email protected] > 98
109
11- The :mod: `cookielib ` module defines classes for automatic handling of HTTP
10+ The :mod: `http.cookiejar ` module defines classes for automatic handling of HTTP
1211cookies. It is useful for accessing web sites that require small pieces of data
1312-- :dfn: `cookies ` -- to be set on the client machine by an HTTP response from a
1413web server, and then returned to the server in later HTTP requests.
@@ -18,7 +17,7 @@ Both the regular Netscape cookie protocol and the protocol defined by
1817:rfc: `2109 ` cookies are parsed as Netscape cookies and subsequently treated
1918either as Netscape or RFC 2965 cookies according to the 'policy' in effect.
2019Note that the great majority of cookies on the Internet are Netscape cookies.
21- :mod: `cookielib ` attempts to follow the de-facto Netscape cookie protocol (which
20+ :mod: `http.cookiejar ` attempts to follow the de-facto Netscape cookie protocol (which
2221differs substantially from that set out in the original Netscape specification),
2322including taking note of the ``max-age `` and ``port `` cookie-attributes
2423introduced with RFC 2965.
@@ -94,7 +93,7 @@ The following classes are provided:
9493.. class :: Cookie()
9594
9695 This class represents Netscape, RFC 2109 and RFC 2965 cookies. It is not
97- expected that users of :mod: `cookielib ` construct their own :class: `Cookie `
96+ expected that users of :mod: `http.cookiejar ` construct their own :class: `Cookie `
9897 instances. Instead, if necessary, call :meth: `make_cookies ` on a
9998 :class: `CookieJar ` instance.
10099
@@ -104,9 +103,10 @@ The following classes are provided:
104103 Module :mod: `urllib2 `
105104 URL opening with automatic cookie handling.
106105
107- Module :mod: `Cookie `
106+ Module :mod: `http.cookies `
108107 HTTP cookie classes, principally useful for server-side code. The
109- :mod: `cookielib ` and :mod: `Cookie ` modules do not depend on each other.
108+ :mod: `http.cookiejar ` and :mod: `http.cookies ` modules do not depend on each
109+ other.
110110
111111 http://wwwsearch.sf.net/ClientCookie/
112112 Extensions to this module, including a class for reading Microsoft Internet
@@ -115,7 +115,7 @@ The following classes are provided:
115115 http://wp.netscape.com/newsref/std/cookie_spec.html
116116 The specification of the original Netscape cookie protocol. Though this is
117117 still the dominant protocol, the 'Netscape cookie protocol' implemented by all
118- the major browsers (and :mod: `cookielib `) only bears a passing resemblance to
118+ the major browsers (and :mod: `http.cookiejar `) only bears a passing resemblance to
119119 the one sketched out in ``cookie_spec.html ``.
120120
121121 :rfc: `2109 ` - HTTP State Management Mechanism
@@ -339,7 +339,7 @@ methods:
339339
340340 Return boolean value indicating whether cookie should be accepted from server.
341341
342- *cookie * is a :class: `cookielib. Cookie ` instance. *request * is an object
342+ *cookie * is a :class: `Cookie ` instance. *request * is an object
343343 implementing the interface defined by the documentation for
344344 :meth: `CookieJar.extract_cookies `.
345345
@@ -348,7 +348,7 @@ methods:
348348
349349 Return boolean value indicating whether cookie should be returned to server.
350350
351- *cookie * is a :class: `cookielib. Cookie ` instance. *request * is an object
351+ *cookie * is a :class: `Cookie ` instance. *request * is an object
352352 implementing the interface defined by the documentation for
353353 :meth: `CookieJar.add_cookie_header `.
354354
@@ -424,10 +424,10 @@ The easiest way to provide your own policy is to override this class and call
424424its methods in your overridden implementations before adding your own additional
425425checks::
426426
427- import cookielib
428- class MyCookiePolicy(cookielib .DefaultCookiePolicy):
427+ import http.cookiejar
428+ class MyCookiePolicy(http.cookiejar .DefaultCookiePolicy):
429429 def set_ok(self, cookie, request):
430- if not cookielib .DefaultCookiePolicy.set_ok(self, cookie, request):
430+ if not http.cookiejar .DefaultCookiePolicy.set_ok(self, cookie, request):
431431 return False
432432 if i_dont_want_to_store_this_cookie(cookie):
433433 return False
@@ -584,8 +584,6 @@ combinations of the above flags:
584584 Equivalent to ``DomainStrictNoDots|DomainStrictNonDomain ``.
585585
586586
587- .. _cookielib-cookie-objects :
588-
589587Cookie Objects
590588--------------
591589
@@ -594,7 +592,7 @@ standard cookie-attributes specified in the various cookie standards. The
594592correspondence is not one-to-one, because there are complicated rules for
595593assigning default values, because the ``max-age `` and ``expires ``
596594cookie-attributes contain equivalent information, and because RFC 2109 cookies
597- may be 'downgraded' by :mod: `cookielib ` from version 1 to version 0 (Netscape)
595+ may be 'downgraded' by :mod: `http.cookiejar ` from version 1 to version 0 (Netscape)
598596cookies.
599597
600598Assignment to these attributes should not be necessary other than in rare
@@ -606,7 +604,7 @@ internal consistency, so you should know what you're doing if you do that.
606604
607605 Integer or :const: `None `. Netscape cookies have :attr: `version ` 0. RFC 2965 and
608606 RFC 2109 cookies have a ``version `` cookie-attribute of 1. However, note that
609- :mod: `cookielib ` may 'downgrade' RFC 2109 cookies to Netscape cookies, in which
607+ :mod: `http.cookiejar ` may 'downgrade' RFC 2109 cookies to Netscape cookies, in which
610608 case :attr: `version ` is 0.
611609
612610
@@ -664,7 +662,7 @@ internal consistency, so you should know what you're doing if you do that.
664662 True if this cookie was received as an RFC 2109 cookie (ie. the cookie
665663 arrived in a :mailheader: `Set-Cookie ` header, and the value of the Version
666664 cookie-attribute in that header was 1). This attribute is provided because
667- :mod: `cookielib ` may 'downgrade' RFC 2109 cookies to Netscape cookies, in
665+ :mod: `http.cookiejar ` may 'downgrade' RFC 2109 cookies to Netscape cookies, in
668666 which case :attr: `version ` is 0.
669667
670668
@@ -713,23 +711,21 @@ The :class:`Cookie` class also defines the following method:
713711 cookie has expired at the specified time.
714712
715713
716- .. _cookielib-examples :
717-
718714Examples
719715--------
720716
721- The first example shows the most common usage of :mod: `cookielib `::
717+ The first example shows the most common usage of :mod: `http.cookiejar `::
722718
723- import cookielib , urllib2
724- cj = cookielib .CookieJar()
719+ import http.cookiejar , urllib2
720+ cj = http.cookiejar .CookieJar()
725721 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
726722 r = opener.open("http://example.com/")
727723
728724This example illustrates how to open a URL using your Netscape, Mozilla, or Lynx
729725cookies (assumes Unix/Netscape convention for location of the cookies file)::
730726
731- import os, cookielib , urllib2
732- cj = cookielib .MozillaCookieJar()
727+ import os, http.cookiejar , urllib2
728+ cj = http.cookiejar .MozillaCookieJar()
733729 cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
734730 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
735731 r = opener.open("http://example.com/")
@@ -740,7 +736,7 @@ Netscape cookies, and block some domains from setting cookies or having them
740736returned::
741737
742738 import urllib2
743- from cookielib import CookieJar, DefaultCookiePolicy
739+ from http.cookiejar import CookieJar, DefaultCookiePolicy
744740 policy = DefaultCookiePolicy(
745741 rfc2965=True, strict_ns_domain=Policy.DomainStrict,
746742 blocked_domains=["ads.net", ".ads.net"])
0 commit comments