source: trunk/essentials/dev-lang/python/Lib/_LWPCookieJar.py@ 3298

Last change on this file since 3298 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 6.4 KB
Line 
1"""Load / save to libwww-perl (LWP) format files.
2
3Actually, the format is slightly extended from that used by LWP's
4(libwww-perl's) HTTP::Cookies, to avoid losing some RFC 2965 information
5not recorded by LWP.
6
7It uses the version string "2.0", though really there isn't an LWP Cookies
82.0 format. This indicates that there is extra information in here
9(domain_dot and # port_spec) while still being compatible with
10libwww-perl, I hope.
11
12"""
13
14import time, re
15from cookielib import (_warn_unhandled_exception, FileCookieJar, LoadError,
16 Cookie, MISSING_FILENAME_TEXT,
17 join_header_words, split_header_words,
18 iso2time, time2isoz)
19
20def lwp_cookie_str(cookie):
21 """Return string representation of Cookie in an the LWP cookie file format.
22
23 Actually, the format is extended a bit -- see module docstring.
24
25 """
26 h = [(cookie.name, cookie.value),
27 ("path", cookie.path),
28 ("domain", cookie.domain)]
29 if cookie.port is not None: h.append(("port", cookie.port))
30 if cookie.path_specified: h.append(("path_spec", None))
31 if cookie.port_specified: h.append(("port_spec", None))
32 if cookie.domain_initial_dot: h.append(("domain_dot", None))
33 if cookie.secure: h.append(("secure", None))
34 if cookie.expires: h.append(("expires",
35 time2isoz(float(cookie.expires))))
36 if cookie.discard: h.append(("discard", None))
37 if cookie.comment: h.append(("comment", cookie.comment))
38 if cookie.comment_url: h.append(("commenturl", cookie.comment_url))
39
40 keys = cookie._rest.keys()
41 keys.sort()
42 for k in keys:
43 h.append((k, str(cookie._rest[k])))
44
45 h.append(("version", str(cookie.version)))
46
47 return join_header_words([h])
48
49class LWPCookieJar(FileCookieJar):
50 """
51 The LWPCookieJar saves a sequence of"Set-Cookie3" lines.
52 "Set-Cookie3" is the format used by the libwww-perl libary, not known
53 to be compatible with any browser, but which is easy to read and