Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
http.cookiejar.DefaultCookiePolicy Class Reference
Inheritance diagram for http.cookiejar.DefaultCookiePolicy:
Inheritance graph
[legend]
Collaboration diagram for http.cookiejar.DefaultCookiePolicy:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def blocked_domains
def set_blocked_domains
def is_blocked
def allowed_domains
def set_allowed_domains
def is_not_allowed
def set_ok
def set_ok_version
def set_ok_verifiability
def set_ok_name
def set_ok_path
def set_ok_domain
def set_ok_port
def return_ok
def return_ok_version
def return_ok_verifiability
def return_ok_secure
def return_ok_expires
def return_ok_port
def return_ok_domain
def domain_return_ok
def path_return_ok

Public Attributes

 netscape
 rfc2965
 rfc2109_as_netscape
 hide_cookie2
 strict_domain
 strict_rfc2965_unverifiable
 strict_ns_unverifiable
 strict_ns_domain
 strict_ns_set_initial_dollar
 strict_ns_set_path

Static Public Attributes

int DomainStrictNoDots = 1
int DomainStrictNonDomain = 2
int DomainRFC2965Match = 4
int DomainLiberal = 0
 DomainStrict = DomainStrictNoDots|DomainStrictNonDomain

Private Attributes

 _blocked_domains
 _allowed_domains

Detailed Description

Implements the standard rules for accepting and returning cookies.

Definition at line 844 of file cookiejar.py.


Constructor & Destructor Documentation

def http.cookiejar.DefaultCookiePolicy.__init__ (   self,
  blocked_domains = None,
  allowed_domains = None,
  netscape = True,
  rfc2965 = False,
  rfc2109_as_netscape = None,
  hide_cookie2 = False,
  strict_domain = False,
  strict_rfc2965_unverifiable = True,
  strict_ns_unverifiable = False,
  strict_ns_domain = DomainLiberal,
  strict_ns_set_initial_dollar = False,
  strict_ns_set_path = False 
)
Constructor arguments should be passed as keyword arguments only.

Definition at line 865 of file cookiejar.py.

00865 
00866                  ):
00867         """Constructor arguments should be passed as keyword arguments only."""
00868         self.netscape = netscape
00869         self.rfc2965 = rfc2965
00870         self.rfc2109_as_netscape = rfc2109_as_netscape
00871         self.hide_cookie2 = hide_cookie2
00872         self.strict_domain = strict_domain
00873         self.strict_rfc2965_unverifiable = strict_rfc2965_unverifiable
00874         self.strict_ns_unverifiable = strict_ns_unverifiable
00875         self.strict_ns_domain = strict_ns_domain
00876         self.strict_ns_set_initial_dollar = strict_ns_set_initial_dollar
00877         self.strict_ns_set_path = strict_ns_set_path
00878 
00879         if blocked_domains is not None:
00880             self._blocked_domains = tuple(blocked_domains)
00881         else:
00882             self._blocked_domains = ()
00883 
00884         if allowed_domains is not None:
00885             allowed_domains = tuple(allowed_domains)
00886         self._allowed_domains = allowed_domains

Here is the caller graph for this function:


Member Function Documentation

Return None, or the sequence of allowed domains (as a tuple).

Definition at line 900 of file cookiejar.py.

00900 
00901     def allowed_domains(self):
00902         """Return None, or the sequence of allowed domains (as a tuple)."""
        return self._allowed_domains
Return the sequence of blocked domains (as a tuple).

Definition at line 887 of file cookiejar.py.

00887 
00888     def blocked_domains(self):
00889         """Return the sequence of blocked domains (as a tuple)."""
        return self._blocked_domains
def http.cookiejar.DefaultCookiePolicy.domain_return_ok (   self,
  domain,
  request 
)
Return false if cookies should not be returned, given cookie domain.

Reimplemented from http.cookiejar.CookiePolicy.

Definition at line 1150 of file cookiejar.py.

01150 
01151     def domain_return_ok(self, domain, request):
01152         # Liberal check of.  This is here as an optimization to avoid
01153         # having to load lots of MSIE cookie files unless necessary.
01154         req_host, erhn = eff_request_host(request)
01155         if not req_host.startswith("."):
01156             req_host = "."+req_host
01157         if not erhn.startswith("."):
01158             erhn = "."+erhn
01159         if not (req_host.endswith(domain) or erhn.endswith(domain)):
01160             #_debug("   request domain %s does not match cookie domain %s",
01161             #       req_host, domain)
01162             return False
01163 
01164         if self.is_blocked(domain):
01165             _debug("   domain %s is in user block-list", domain)
01166             return False
01167         if self.is_not_allowed(domain):
01168             _debug("   domain %s is not in user allow-list", domain)
01169             return False
01170 
01171         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.is_blocked (   self,
  domain 
)

Definition at line 894 of file cookiejar.py.

00894 
00895     def is_blocked(self, domain):
00896         for blocked_domain in self._blocked_domains:
00897             if user_domain_match(domain, blocked_domain):
00898                 return True
00899         return False

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 909 of file cookiejar.py.

00909 
00910     def is_not_allowed(self, domain):
00911         if self._allowed_domains is None:
00912             return False
00913         for allowed_domain in self._allowed_domains:
00914             if user_domain_match(domain, allowed_domain):
00915                 return False
00916         return True

Here is the call graph for this function:

Here is the caller graph for this function:

def http.cookiejar.DefaultCookiePolicy.path_return_ok (   self,
  path,
  request 
)
Return false if cookies should not be returned, given cookie path.

Reimplemented from http.cookiejar.CookiePolicy.

Definition at line 1172 of file cookiejar.py.

01172 
01173     def path_return_ok(self, path, request):
01174         _debug("- checking cookie path=%s", path)
01175         req_path = request_path(request)
01176         if not req_path.startswith(path):
01177             _debug("  %s does not path-match %s", req_path, path)
01178             return False
01179         return True
01180 

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok (   self,
  cookie,
  request 
)
If you override .return_ok(), be sure to call this method.  If it
returns false, so should your subclass (assuming your subclass wants to
be more strict about which cookies to return).

Reimplemented from http.cookiejar.CookiePolicy.

Definition at line 1063 of file cookiejar.py.

01063 
01064     def return_ok(self, cookie, request):
01065         """
01066         If you override .return_ok(), be sure to call this method.  If it
01067         returns false, so should your subclass (assuming your subclass wants to
01068         be more strict about which cookies to return).
01069 
01070         """
01071         # Path has already been checked by .path_return_ok(), and domain
01072         # blocking done by .domain_return_ok().
01073         _debug(" - checking cookie %s=%s", cookie.name, cookie.value)
01074 
01075         for n in "version", "verifiability", "secure", "expires", "port", "domain":
01076             fn_name = "return_ok_"+n
01077             fn = getattr(self, fn_name)
01078             if not fn(cookie, request):
01079                 return False
01080         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok_domain (   self,
  cookie,
  request 
)

Definition at line 1128 of file cookiejar.py.

01128 
01129     def return_ok_domain(self, cookie, request):
01130         req_host, erhn = eff_request_host(request)
01131         domain = cookie.domain
01132 
01133         # strict check of non-domain cookies: Mozilla does this, MSIE5 doesn't
01134         if (cookie.version == 0 and
01135             (self.strict_ns_domain & self.DomainStrictNonDomain) and
01136             not cookie.domain_specified and domain != erhn):
01137             _debug("   cookie with unspecified domain does not string-compare "
01138                    "equal to request domain")
01139             return False
01140 
01141         if cookie.version > 0 and not domain_match(erhn, domain):
01142             _debug("   effective request-host name %s does not domain-match "
01143                    "RFC 2965 cookie domain %s", erhn, domain)
01144             return False
01145         if cookie.version == 0 and not ("."+erhn).endswith(domain):
01146             _debug("   request-host %s does not match Netscape cookie domain "
01147                    "%s", req_host, domain)
01148             return False
01149         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok_expires (   self,
  cookie,
  request 
)

Definition at line 1108 of file cookiejar.py.

01108 
01109     def return_ok_expires(self, cookie, request):
01110         if cookie.is_expired(self._now):
01111             _debug("   cookie expired")
01112             return False
01113         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok_port (   self,
  cookie,
  request 
)

Definition at line 1114 of file cookiejar.py.

01114 
01115     def return_ok_port(self, cookie, request):
01116         if cookie.port:
01117             req_port = request_port(request)
01118             if req_port is None:
01119                 req_port = "80"
01120             for p in cookie.port.split(","):
01121                 if p == req_port:
01122                     break
01123             else:
01124                 _debug("   request port %s does not match cookie port %s",
01125                        req_port, cookie.port)
01126                 return False
01127         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok_secure (   self,
  cookie,
  request 
)

Definition at line 1102 of file cookiejar.py.

01102 
01103     def return_ok_secure(self, cookie, request):
01104         if cookie.secure and request.get_type() != "https":
01105             _debug("   secure cookie with non-secure request")
01106             return False
01107         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok_verifiability (   self,
  cookie,
  request 
)

Definition at line 1090 of file cookiejar.py.

01090 
01091     def return_ok_verifiability(self, cookie, request):
01092         if request.is_unverifiable() and is_third_party(request):
01093             if cookie.version > 0 and self.strict_rfc2965_unverifiable:
01094                 _debug("   third-party RFC 2965 cookie during unverifiable "
01095                        "transaction")
01096                 return False
01097             elif cookie.version == 0 and self.strict_ns_unverifiable:
01098                 _debug("   third-party Netscape cookie during unverifiable "
01099                        "transaction")
01100                 return False
01101         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.return_ok_version (   self,
  cookie,
  request 
)

Definition at line 1081 of file cookiejar.py.

01081 
01082     def return_ok_version(self, cookie, request):
01083         if cookie.version > 0 and not self.rfc2965:
01084             _debug("   RFC 2965 cookies are switched off")
01085             return False
01086         elif cookie.version == 0 and not self.netscape:
01087             _debug("   Netscape cookies are switched off")
01088             return False
01089         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_allowed_domains (   self,
  allowed_domains 
)
Set the sequence of allowed domains, or None.

Definition at line 903 of file cookiejar.py.

00903 
00904     def set_allowed_domains(self, allowed_domains):
00905         """Set the sequence of allowed domains, or None."""
00906         if allowed_domains is not None:
00907             allowed_domains = tuple(allowed_domains)
00908         self._allowed_domains = allowed_domains

def http.cookiejar.DefaultCookiePolicy.set_blocked_domains (   self,
  blocked_domains 
)
Set the sequence of blocked domains.

Definition at line 890 of file cookiejar.py.

00890 
00891     def set_blocked_domains(self, blocked_domains):
00892         """Set the sequence of blocked domains."""
00893         self._blocked_domains = tuple(blocked_domains)

def http.cookiejar.DefaultCookiePolicy.set_ok (   self,
  cookie,
  request 
)
If you override .set_ok(), be sure to call this method.  If it returns
false, so should your subclass (assuming your subclass wants to be more
strict about which cookies to accept).

Reimplemented from http.cookiejar.CookiePolicy.

Definition at line 917 of file cookiejar.py.

00917 
00918     def set_ok(self, cookie, request):
00919         """
00920         If you override .set_ok(), be sure to call this method.  If it returns
00921         false, so should your subclass (assuming your subclass wants to be more
00922         strict about which cookies to accept).
00923 
00924         """
00925         _debug(" - checking cookie %s=%s", cookie.name, cookie.value)
00926 
00927         assert cookie.name is not None
00928 
00929         for n in "version", "verifiability", "name", "path", "domain", "port":
00930             fn_name = "set_ok_"+n
00931             fn = getattr(self, fn_name)
00932             if not fn(cookie, request):
00933                 return False
00934 
00935         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_ok_domain (   self,
  cookie,
  request 
)

Definition at line 983 of file cookiejar.py.

00983 
00984     def set_ok_domain(self, cookie, request):
00985         if self.is_blocked(cookie.domain):
00986             _debug("   domain %s is in user block-list", cookie.domain)
00987             return False
00988         if self.is_not_allowed(cookie.domain):
00989             _debug("   domain %s is not in user allow-list", cookie.domain)
00990             return False
00991         if cookie.domain_specified:
00992             req_host, erhn = eff_request_host(request)
00993             domain = cookie.domain
00994             if self.strict_domain and (domain.count(".") >= 2):
00995                 # XXX This should probably be compared with the Konqueror
00996                 # (kcookiejar.cpp) and Mozilla implementations, but it's a
00997                 # losing battle.
00998                 i = domain.rfind(".")
00999                 j = domain.rfind(".", 0, i)
01000                 if j == 0:  # domain like .foo.bar
01001                     tld = domain[i+1:]
01002                     sld = domain[j+1:i]
01003                     if sld.lower() in ("co", "ac", "com", "edu", "org", "net",
01004                        "gov", "mil", "int", "aero", "biz", "cat", "coop",
01005                        "info", "jobs", "mobi", "museum", "name", "pro",
01006                        "travel", "eu") and len(tld) == 2:
01007                         # domain like .co.uk
01008                         _debug("   country-code second level domain %s", domain)
01009                         return False
01010             if domain.startswith("."):
01011                 undotted_domain = domain[1:]
01012             else:
01013                 undotted_domain = domain
01014             embedded_dots = (undotted_domain.find(".") >= 0)
01015             if not embedded_dots and domain != ".local":
01016                 _debug("   non-local domain %s contains no embedded dot",
01017                        domain)
01018                 return False
01019             if cookie.version == 0:
01020                 if (not erhn.endswith(domain) and
01021                     (not erhn.startswith(".") and
01022                      not ("."+erhn).endswith(domain))):
01023                     _debug("   effective request-host %s (even with added "
01024                            "initial dot) does not end end with %s",
01025                            erhn, domain)
01026                     return False
01027             if (cookie.version > 0 or
01028                 (self.strict_ns_domain & self.DomainRFC2965Match)):
01029                 if not domain_match(erhn, domain):
01030                     _debug("   effective request-host %s does not domain-match "
01031                            "%s", erhn, domain)
01032                     return False
01033             if (cookie.version > 0 or
01034                 (self.strict_ns_domain & self.DomainStrictNoDots)):
01035                 host_prefix = req_host[:-len(domain)]
01036                 if (host_prefix.find(".") >= 0 and
01037                     not IPV4_RE.search(req_host)):
01038                     _debug("   host prefix %s for domain %s contains a dot",
01039                            host_prefix, domain)
01040                     return False
01041         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_ok_name (   self,
  cookie,
  request 
)

Definition at line 963 of file cookiejar.py.

00963 
00964     def set_ok_name(self, cookie, request):
00965         # Try and stop servers setting V0 cookies designed to hack other
00966         # servers that know both V0 and V1 protocols.
00967         if (cookie.version == 0 and self.strict_ns_set_initial_dollar and
00968             cookie.name.startswith("$")):
00969             _debug("   illegal name (starts with '$'): '%s'", cookie.name)
00970             return False
00971         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_ok_path (   self,
  cookie,
  request 
)

Definition at line 972 of file cookiejar.py.

00972 
00973     def set_ok_path(self, cookie, request):
00974         if cookie.path_specified:
00975             req_path = request_path(request)
00976             if ((cookie.version > 0 or
00977                  (cookie.version == 0 and self.strict_ns_set_path)) and
00978                 not req_path.startswith(cookie.path)):
00979                 _debug("   path attribute %s is not a prefix of request "
00980                        "path %s", cookie.path, req_path)
00981                 return False
00982         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_ok_port (   self,
  cookie,
  request 
)

Definition at line 1042 of file cookiejar.py.

01042 
01043     def set_ok_port(self, cookie, request):
01044         if cookie.port_specified:
01045             req_port = request_port(request)
01046             if req_port is None:
01047                 req_port = "80"
01048             else:
01049                 req_port = str(req_port)
01050             for p in cookie.port.split(","):
01051                 try:
01052                     int(p)
01053                 except ValueError:
01054                     _debug("   bad port %s (not numeric)", p)
01055                     return False
01056                 if p == req_port:
01057                     break
01058             else:
01059                 _debug("   request port (%s) not found in %s",
01060                        req_port, cookie.port)
01061                 return False
01062         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_ok_verifiability (   self,
  cookie,
  request 
)

Definition at line 951 of file cookiejar.py.

00951 
00952     def set_ok_verifiability(self, cookie, request):
00953         if request.is_unverifiable() and is_third_party(request):
00954             if cookie.version > 0 and self.strict_rfc2965_unverifiable:
00955                 _debug("   third-party RFC 2965 cookie during "
00956                              "unverifiable transaction")
00957                 return False
00958             elif cookie.version == 0 and self.strict_ns_unverifiable:
00959                 _debug("   third-party Netscape cookie during "
00960                              "unverifiable transaction")
00961                 return False
00962         return True

Here is the call graph for this function:

def http.cookiejar.DefaultCookiePolicy.set_ok_version (   self,
  cookie,
  request 
)

Definition at line 936 of file cookiejar.py.

00936 
00937     def set_ok_version(self, cookie, request):
00938         if cookie.version is None:
00939             # Version is always set to 0 by parse_ns_headers if it's a Netscape
00940             # cookie, so this must be an invalid RFC 2965 cookie.
00941             _debug("   Set-Cookie2 without version attribute (%s=%s)",
00942                    cookie.name, cookie.value)
00943             return False
00944         if cookie.version > 0 and not self.rfc2965:
00945             _debug("   RFC 2965 cookies are switched off")
00946             return False
00947         elif cookie.version == 0 and not self.netscape:
00948             _debug("   Netscape cookies are switched off")
00949             return False
00950         return True

Here is the call graph for this function:


Member Data Documentation

Definition at line 885 of file cookiejar.py.

Definition at line 879 of file cookiejar.py.

Definition at line 851 of file cookiejar.py.

Definition at line 849 of file cookiejar.py.

Definition at line 852 of file cookiejar.py.

Definition at line 847 of file cookiejar.py.

Definition at line 848 of file cookiejar.py.

Definition at line 870 of file cookiejar.py.

Definition at line 867 of file cookiejar.py.

Definition at line 869 of file cookiejar.py.

Definition at line 868 of file cookiejar.py.

Definition at line 871 of file cookiejar.py.

Definition at line 874 of file cookiejar.py.

Definition at line 875 of file cookiejar.py.

Definition at line 876 of file cookiejar.py.

Definition at line 873 of file cookiejar.py.

Definition at line 872 of file cookiejar.py.


The documentation for this class was generated from the following file: