syshttp.cookies
syshttp.cookies
Netscape cookie-file I/O and curl's cookie rules: CookieSpec,
load_netscape, save_netscape, cookie_applies, set_cookie_specs
and the host groups of host_aliases. The client keeps its cookies as these
rows; a curl front end's -b / -c run on them too.
CookieLike
Bases: Protocol
What :func:save_netscape reads off a cookie: a CookieSpec, an
http.cookiejar.Cookie or any object with these attributes.
cookie_applies(cookie, url, now=None)
Does cookie go with a request to url, as curl decides: the
domain (the host itself, or a subdomain for a leading dot or the
include-subdomains flag -- never for an IP address, which only matches
itself), the path (RFC 6265 path-match), Secure only over https or to
localhost / a loopback address, and not expired (0 / None is a
session cookie).
Source code in src/syshttp/cookies.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
domain_covers(domain, host)
Does a cookie domain apply to host: the host itself, or a
subdomain when the domain has a leading dot (the Netscape flag).
Source code in src/syshttp/cookies.py
361 362 363 364 365 366 367 368 369 | |
host_aliases(groups)
Each host of groups mapped to its group's first host: hosts a user
declares to be one for cookies. A group of one host is no alias. A host
that is not a name or an IP address (a port, a path, a blank), or that
appears in two groups, raises ValueError.
Source code in src/syshttp/cookies.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
load_netscape(path)
The rows of the Netscape cookie file path ([] when it is
missing). Lines end at \n only, one trailing \r taken off, and a
row whose name or value holds a control character is skipped: other
characters str.splitlines honours (\x0b, \x0c, \x85) are
part of a value, not the end of a row.
Source code in src/syshttp/cookies.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
save_netscape(session_cookies, path)
Writes session_cookies to path as a Netscape cookie file, owner
only and replaced whole. A cookie with no name, or with a control character
or a tab in a field, is not written: it would split its row.
Source code in src/syshttp/cookies.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
set_cookie_specs(values, default_domain, now=None, *, request_path='/', aliases=None)
(cookie, gone) for every cookie the Set-Cookie header
values carry, read as RFC 6265 section 5.2 does.
default_domain is the host asked. A Domain attribute is kept only
when that host domain-matches it and it is not a public suffix (judged
without the Public Suffix List: a top level domain or a co.uk-style
registry); it then covers subdomains (subdomains=True). Without one
the cookie is host-only. A cookie with no Path gets the directory of
request_path. gone marks a cookie the server expires: an empty
value, Max-Age of zero or less, a past date. A header that is not a
cookie, or names a foreign domain, is skipped. An expiry beyond 400 days
is cut to 400 days. aliases (:func:host_aliases) makes a group of
hosts one: a cookie a member sets with no Domain, or with a Domain naming
a member, belongs to the group's first host.
Source code in src/syshttp/cookies.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |