Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../http
File: cookiejar.py
# (discard is also set if expires is Absent)
[1500] Fix | Delete
discard = standard.get("discard", False)
[1501] Fix | Delete
comment = standard.get("comment", None)
[1502] Fix | Delete
comment_url = standard.get("commenturl", None)
[1503] Fix | Delete
[1504] Fix | Delete
# set default path
[1505] Fix | Delete
if path is not Absent and path != "":
[1506] Fix | Delete
path_specified = True
[1507] Fix | Delete
path = escape_path(path)
[1508] Fix | Delete
else:
[1509] Fix | Delete
path_specified = False
[1510] Fix | Delete
path = request_path(request)
[1511] Fix | Delete
i = path.rfind("/")
[1512] Fix | Delete
if i != -1:
[1513] Fix | Delete
if version == 0:
[1514] Fix | Delete
# Netscape spec parts company from reality here
[1515] Fix | Delete
path = path[:i]
[1516] Fix | Delete
else:
[1517] Fix | Delete
path = path[:i+1]
[1518] Fix | Delete
if len(path) == 0: path = "/"
[1519] Fix | Delete
[1520] Fix | Delete
# set default domain
[1521] Fix | Delete
domain_specified = domain is not Absent
[1522] Fix | Delete
# but first we have to remember whether it starts with a dot
[1523] Fix | Delete
domain_initial_dot = False
[1524] Fix | Delete
if domain_specified:
[1525] Fix | Delete
domain_initial_dot = bool(domain.startswith("."))
[1526] Fix | Delete
if domain is Absent:
[1527] Fix | Delete
req_host, erhn = eff_request_host(request)
[1528] Fix | Delete
domain = erhn
[1529] Fix | Delete
elif not domain.startswith("."):
[1530] Fix | Delete
domain = "."+domain
[1531] Fix | Delete
[1532] Fix | Delete
# set default port
[1533] Fix | Delete
port_specified = False
[1534] Fix | Delete
if port is not Absent:
[1535] Fix | Delete
if port is None:
[1536] Fix | Delete
# Port attr present, but has no value: default to request port.
[1537] Fix | Delete
# Cookie should then only be sent back on that port.
[1538] Fix | Delete
port = request_port(request)
[1539] Fix | Delete
else:
[1540] Fix | Delete
port_specified = True
[1541] Fix | Delete
port = re.sub(r"\s+", "", port)
[1542] Fix | Delete
else:
[1543] Fix | Delete
# No port attr present. Cookie can be sent back on any port.
[1544] Fix | Delete
port = None
[1545] Fix | Delete
[1546] Fix | Delete
# set default expires and discard
[1547] Fix | Delete
if expires is Absent:
[1548] Fix | Delete
expires = None
[1549] Fix | Delete
discard = True
[1550] Fix | Delete
elif expires <= self._now:
[1551] Fix | Delete
# Expiry date in past is request to delete cookie. This can't be
[1552] Fix | Delete
# in DefaultCookiePolicy, because can't delete cookies there.
[1553] Fix | Delete
try:
[1554] Fix | Delete
self.clear(domain, path, name)
[1555] Fix | Delete
except KeyError:
[1556] Fix | Delete
pass
[1557] Fix | Delete
_debug("Expiring cookie, domain='%s', path='%s', name='%s'",
[1558] Fix | Delete
domain, path, name)
[1559] Fix | Delete
return None
[1560] Fix | Delete
[1561] Fix | Delete
return Cookie(version,
[1562] Fix | Delete
name, value,
[1563] Fix | Delete
port, port_specified,
[1564] Fix | Delete
domain, domain_specified, domain_initial_dot,
[1565] Fix | Delete
path, path_specified,
[1566] Fix | Delete
secure,
[1567] Fix | Delete
expires,
[1568] Fix | Delete
discard,
[1569] Fix | Delete
comment,
[1570] Fix | Delete
comment_url,
[1571] Fix | Delete
rest)
[1572] Fix | Delete
[1573] Fix | Delete
def _cookies_from_attrs_set(self, attrs_set, request):
[1574] Fix | Delete
cookie_tuples = self._normalized_cookie_tuples(attrs_set)
[1575] Fix | Delete
[1576] Fix | Delete
cookies = []
[1577] Fix | Delete
for tup in cookie_tuples:
[1578] Fix | Delete
cookie = self._cookie_from_cookie_tuple(tup, request)
[1579] Fix | Delete
if cookie: cookies.append(cookie)
[1580] Fix | Delete
return cookies
[1581] Fix | Delete
[1582] Fix | Delete
def _process_rfc2109_cookies(self, cookies):
[1583] Fix | Delete
rfc2109_as_ns = getattr(self._policy, 'rfc2109_as_netscape', None)
[1584] Fix | Delete
if rfc2109_as_ns is None:
[1585] Fix | Delete
rfc2109_as_ns = not self._policy.rfc2965
[1586] Fix | Delete
for cookie in cookies:
[1587] Fix | Delete
if cookie.version == 1:
[1588] Fix | Delete
cookie.rfc2109 = True
[1589] Fix | Delete
if rfc2109_as_ns:
[1590] Fix | Delete
# treat 2109 cookies as Netscape cookies rather than
[1591] Fix | Delete
# as RFC2965 cookies
[1592] Fix | Delete
cookie.version = 0
[1593] Fix | Delete
[1594] Fix | Delete
def make_cookies(self, response, request):
[1595] Fix | Delete
"""Return sequence of Cookie objects extracted from response object."""
[1596] Fix | Delete
# get cookie-attributes for RFC 2965 and Netscape protocols
[1597] Fix | Delete
headers = response.info()
[1598] Fix | Delete
rfc2965_hdrs = headers.get_all("Set-Cookie2", [])
[1599] Fix | Delete
ns_hdrs = headers.get_all("Set-Cookie", [])
[1600] Fix | Delete
self._policy._now = self._now = int(time.time())
[1601] Fix | Delete
[1602] Fix | Delete
rfc2965 = self._policy.rfc2965
[1603] Fix | Delete
netscape = self._policy.netscape
[1604] Fix | Delete
[1605] Fix | Delete
if ((not rfc2965_hdrs and not ns_hdrs) or
[1606] Fix | Delete
(not ns_hdrs and not rfc2965) or
[1607] Fix | Delete
(not rfc2965_hdrs and not netscape) or
[1608] Fix | Delete
(not netscape and not rfc2965)):
[1609] Fix | Delete
return [] # no relevant cookie headers: quick exit
[1610] Fix | Delete
[1611] Fix | Delete
try:
[1612] Fix | Delete
cookies = self._cookies_from_attrs_set(
[1613] Fix | Delete
split_header_words(rfc2965_hdrs), request)
[1614] Fix | Delete
except Exception:
[1615] Fix | Delete
_warn_unhandled_exception()
[1616] Fix | Delete
cookies = []
[1617] Fix | Delete
[1618] Fix | Delete
if ns_hdrs and netscape:
[1619] Fix | Delete
try:
[1620] Fix | Delete
# RFC 2109 and Netscape cookies
[1621] Fix | Delete
ns_cookies = self._cookies_from_attrs_set(
[1622] Fix | Delete
parse_ns_headers(ns_hdrs), request)
[1623] Fix | Delete
except Exception:
[1624] Fix | Delete
_warn_unhandled_exception()
[1625] Fix | Delete
ns_cookies = []
[1626] Fix | Delete
self._process_rfc2109_cookies(ns_cookies)
[1627] Fix | Delete
[1628] Fix | Delete
# Look for Netscape cookies (from Set-Cookie headers) that match
[1629] Fix | Delete
# corresponding RFC 2965 cookies (from Set-Cookie2 headers).
[1630] Fix | Delete
# For each match, keep the RFC 2965 cookie and ignore the Netscape
[1631] Fix | Delete
# cookie (RFC 2965 section 9.1). Actually, RFC 2109 cookies are
[1632] Fix | Delete
# bundled in with the Netscape cookies for this purpose, which is
[1633] Fix | Delete
# reasonable behaviour.
[1634] Fix | Delete
if rfc2965:
[1635] Fix | Delete
lookup = {}
[1636] Fix | Delete
for cookie in cookies:
[1637] Fix | Delete
lookup[(cookie.domain, cookie.path, cookie.name)] = None
[1638] Fix | Delete
[1639] Fix | Delete
def no_matching_rfc2965(ns_cookie, lookup=lookup):
[1640] Fix | Delete
key = ns_cookie.domain, ns_cookie.path, ns_cookie.name
[1641] Fix | Delete
return key not in lookup
[1642] Fix | Delete
ns_cookies = filter(no_matching_rfc2965, ns_cookies)
[1643] Fix | Delete
[1644] Fix | Delete
if ns_cookies:
[1645] Fix | Delete
cookies.extend(ns_cookies)
[1646] Fix | Delete
[1647] Fix | Delete
return cookies
[1648] Fix | Delete
[1649] Fix | Delete
def set_cookie_if_ok(self, cookie, request):
[1650] Fix | Delete
"""Set a cookie if policy says it's OK to do so."""
[1651] Fix | Delete
self._cookies_lock.acquire()
[1652] Fix | Delete
try:
[1653] Fix | Delete
self._policy._now = self._now = int(time.time())
[1654] Fix | Delete
[1655] Fix | Delete
if self._policy.set_ok(cookie, request):
[1656] Fix | Delete
self.set_cookie(cookie)
[1657] Fix | Delete
[1658] Fix | Delete
[1659] Fix | Delete
finally:
[1660] Fix | Delete
self._cookies_lock.release()
[1661] Fix | Delete
[1662] Fix | Delete
def set_cookie(self, cookie):
[1663] Fix | Delete
"""Set a cookie, without checking whether or not it should be set."""
[1664] Fix | Delete
c = self._cookies
[1665] Fix | Delete
self._cookies_lock.acquire()
[1666] Fix | Delete
try:
[1667] Fix | Delete
if cookie.domain not in c: c[cookie.domain] = {}
[1668] Fix | Delete
c2 = c[cookie.domain]
[1669] Fix | Delete
if cookie.path not in c2: c2[cookie.path] = {}
[1670] Fix | Delete
c3 = c2[cookie.path]
[1671] Fix | Delete
c3[cookie.name] = cookie
[1672] Fix | Delete
finally:
[1673] Fix | Delete
self._cookies_lock.release()
[1674] Fix | Delete
[1675] Fix | Delete
def extract_cookies(self, response, request):
[1676] Fix | Delete
"""Extract cookies from response, where allowable given the request."""
[1677] Fix | Delete
_debug("extract_cookies: %s", response.info())
[1678] Fix | Delete
self._cookies_lock.acquire()
[1679] Fix | Delete
try:
[1680] Fix | Delete
for cookie in self.make_cookies(response, request):
[1681] Fix | Delete
if self._policy.set_ok(cookie, request):
[1682] Fix | Delete
_debug(" setting cookie: %s", cookie)
[1683] Fix | Delete
self.set_cookie(cookie)
[1684] Fix | Delete
finally:
[1685] Fix | Delete
self._cookies_lock.release()
[1686] Fix | Delete
[1687] Fix | Delete
def clear(self, domain=None, path=None, name=None):
[1688] Fix | Delete
"""Clear some cookies.
[1689] Fix | Delete
[1690] Fix | Delete
Invoking this method without arguments will clear all cookies. If
[1691] Fix | Delete
given a single argument, only cookies belonging to that domain will be
[1692] Fix | Delete
removed. If given two arguments, cookies belonging to the specified
[1693] Fix | Delete
path within that domain are removed. If given three arguments, then
[1694] Fix | Delete
the cookie with the specified name, path and domain is removed.
[1695] Fix | Delete
[1696] Fix | Delete
Raises KeyError if no matching cookie exists.
[1697] Fix | Delete
[1698] Fix | Delete
"""
[1699] Fix | Delete
if name is not None:
[1700] Fix | Delete
if (domain is None) or (path is None):
[1701] Fix | Delete
raise ValueError(
[1702] Fix | Delete
"domain and path must be given to remove a cookie by name")
[1703] Fix | Delete
del self._cookies[domain][path][name]
[1704] Fix | Delete
elif path is not None:
[1705] Fix | Delete
if domain is None:
[1706] Fix | Delete
raise ValueError(
[1707] Fix | Delete
"domain must be given to remove cookies by path")
[1708] Fix | Delete
del self._cookies[domain][path]
[1709] Fix | Delete
elif domain is not None:
[1710] Fix | Delete
del self._cookies[domain]
[1711] Fix | Delete
else:
[1712] Fix | Delete
self._cookies = {}
[1713] Fix | Delete
[1714] Fix | Delete
def clear_session_cookies(self):
[1715] Fix | Delete
"""Discard all session cookies.
[1716] Fix | Delete
[1717] Fix | Delete
Note that the .save() method won't save session cookies anyway, unless
[1718] Fix | Delete
you ask otherwise by passing a true ignore_discard argument.
[1719] Fix | Delete
[1720] Fix | Delete
"""
[1721] Fix | Delete
self._cookies_lock.acquire()
[1722] Fix | Delete
try:
[1723] Fix | Delete
for cookie in self:
[1724] Fix | Delete
if cookie.discard:
[1725] Fix | Delete
self.clear(cookie.domain, cookie.path, cookie.name)
[1726] Fix | Delete
finally:
[1727] Fix | Delete
self._cookies_lock.release()
[1728] Fix | Delete
[1729] Fix | Delete
def clear_expired_cookies(self):
[1730] Fix | Delete
"""Discard all expired cookies.
[1731] Fix | Delete
[1732] Fix | Delete
You probably don't need to call this method: expired cookies are never
[1733] Fix | Delete
sent back to the server (provided you're using DefaultCookiePolicy),
[1734] Fix | Delete
this method is called by CookieJar itself every so often, and the
[1735] Fix | Delete
.save() method won't save expired cookies anyway (unless you ask
[1736] Fix | Delete
otherwise by passing a true ignore_expires argument).
[1737] Fix | Delete
[1738] Fix | Delete
"""
[1739] Fix | Delete
self._cookies_lock.acquire()
[1740] Fix | Delete
try:
[1741] Fix | Delete
now = time.time()
[1742] Fix | Delete
for cookie in self:
[1743] Fix | Delete
if cookie.is_expired(now):
[1744] Fix | Delete
self.clear(cookie.domain, cookie.path, cookie.name)
[1745] Fix | Delete
finally:
[1746] Fix | Delete
self._cookies_lock.release()
[1747] Fix | Delete
[1748] Fix | Delete
def __iter__(self):
[1749] Fix | Delete
return deepvalues(self._cookies)
[1750] Fix | Delete
[1751] Fix | Delete
def __len__(self):
[1752] Fix | Delete
"""Return number of contained cookies."""
[1753] Fix | Delete
i = 0
[1754] Fix | Delete
for cookie in self: i = i + 1
[1755] Fix | Delete
return i
[1756] Fix | Delete
[1757] Fix | Delete
def __repr__(self):
[1758] Fix | Delete
r = []
[1759] Fix | Delete
for cookie in self: r.append(repr(cookie))
[1760] Fix | Delete
return "<%s[%s]>" % (self.__class__.__name__, ", ".join(r))
[1761] Fix | Delete
[1762] Fix | Delete
def __str__(self):
[1763] Fix | Delete
r = []
[1764] Fix | Delete
for cookie in self: r.append(str(cookie))
[1765] Fix | Delete
return "<%s[%s]>" % (self.__class__.__name__, ", ".join(r))
[1766] Fix | Delete
[1767] Fix | Delete
[1768] Fix | Delete
# derives from OSError for backwards-compatibility with Python 2.4.0
[1769] Fix | Delete
class LoadError(OSError): pass
[1770] Fix | Delete
[1771] Fix | Delete
class FileCookieJar(CookieJar):
[1772] Fix | Delete
"""CookieJar that can be loaded from and saved to a file."""
[1773] Fix | Delete
[1774] Fix | Delete
def __init__(self, filename=None, delayload=False, policy=None):
[1775] Fix | Delete
"""
[1776] Fix | Delete
Cookies are NOT loaded from the named file until either the .load() or
[1777] Fix | Delete
.revert() method is called.
[1778] Fix | Delete
[1779] Fix | Delete
"""
[1780] Fix | Delete
CookieJar.__init__(self, policy)
[1781] Fix | Delete
if filename is not None:
[1782] Fix | Delete
filename = os.fspath(filename)
[1783] Fix | Delete
self.filename = filename
[1784] Fix | Delete
self.delayload = bool(delayload)
[1785] Fix | Delete
[1786] Fix | Delete
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
[1787] Fix | Delete
"""Save cookies to a file."""
[1788] Fix | Delete
raise NotImplementedError()
[1789] Fix | Delete
[1790] Fix | Delete
def load(self, filename=None, ignore_discard=False, ignore_expires=False):
[1791] Fix | Delete
"""Load cookies from a file."""
[1792] Fix | Delete
if filename is None:
[1793] Fix | Delete
if self.filename is not None: filename = self.filename
[1794] Fix | Delete
else: raise ValueError(MISSING_FILENAME_TEXT)
[1795] Fix | Delete
[1796] Fix | Delete
with open(filename) as f:
[1797] Fix | Delete
self._really_load(f, filename, ignore_discard, ignore_expires)
[1798] Fix | Delete
[1799] Fix | Delete
def revert(self, filename=None,
[1800] Fix | Delete
ignore_discard=False, ignore_expires=False):
[1801] Fix | Delete
"""Clear all cookies and reload cookies from a saved file.
[1802] Fix | Delete
[1803] Fix | Delete
Raises LoadError (or OSError) if reversion is not successful; the
[1804] Fix | Delete
object's state will not be altered if this happens.
[1805] Fix | Delete
[1806] Fix | Delete
"""
[1807] Fix | Delete
if filename is None:
[1808] Fix | Delete
if self.filename is not None: filename = self.filename
[1809] Fix | Delete
else: raise ValueError(MISSING_FILENAME_TEXT)
[1810] Fix | Delete
[1811] Fix | Delete
self._cookies_lock.acquire()
[1812] Fix | Delete
try:
[1813] Fix | Delete
[1814] Fix | Delete
old_state = copy.deepcopy(self._cookies)
[1815] Fix | Delete
self._cookies = {}
[1816] Fix | Delete
try:
[1817] Fix | Delete
self.load(filename, ignore_discard, ignore_expires)
[1818] Fix | Delete
except OSError:
[1819] Fix | Delete
self._cookies = old_state
[1820] Fix | Delete
raise
[1821] Fix | Delete
[1822] Fix | Delete
finally:
[1823] Fix | Delete
self._cookies_lock.release()
[1824] Fix | Delete
[1825] Fix | Delete
[1826] Fix | Delete
def lwp_cookie_str(cookie):
[1827] Fix | Delete
"""Return string representation of Cookie in the LWP cookie file format.
[1828] Fix | Delete
[1829] Fix | Delete
Actually, the format is extended a bit -- see module docstring.
[1830] Fix | Delete
[1831] Fix | Delete
"""
[1832] Fix | Delete
h = [(cookie.name, cookie.value),
[1833] Fix | Delete
("path", cookie.path),
[1834] Fix | Delete
("domain", cookie.domain)]
[1835] Fix | Delete
if cookie.port is not None: h.append(("port", cookie.port))
[1836] Fix | Delete
if cookie.path_specified: h.append(("path_spec", None))
[1837] Fix | Delete
if cookie.port_specified: h.append(("port_spec", None))
[1838] Fix | Delete
if cookie.domain_initial_dot: h.append(("domain_dot", None))
[1839] Fix | Delete
if cookie.secure: h.append(("secure", None))
[1840] Fix | Delete
if cookie.expires: h.append(("expires",
[1841] Fix | Delete
time2isoz(float(cookie.expires))))
[1842] Fix | Delete
if cookie.discard: h.append(("discard", None))
[1843] Fix | Delete
if cookie.comment: h.append(("comment", cookie.comment))
[1844] Fix | Delete
if cookie.comment_url: h.append(("commenturl", cookie.comment_url))
[1845] Fix | Delete
[1846] Fix | Delete
keys = sorted(cookie._rest.keys())
[1847] Fix | Delete
for k in keys:
[1848] Fix | Delete
h.append((k, str(cookie._rest[k])))
[1849] Fix | Delete
[1850] Fix | Delete
h.append(("version", str(cookie.version)))
[1851] Fix | Delete
[1852] Fix | Delete
return join_header_words([h])
[1853] Fix | Delete
[1854] Fix | Delete
class LWPCookieJar(FileCookieJar):
[1855] Fix | Delete
"""
[1856] Fix | Delete
The LWPCookieJar saves a sequence of "Set-Cookie3" lines.
[1857] Fix | Delete
"Set-Cookie3" is the format used by the libwww-perl library, not known
[1858] Fix | Delete
to be compatible with any browser, but which is easy to read and
[1859] Fix | Delete
doesn't lose information about RFC 2965 cookies.
[1860] Fix | Delete
[1861] Fix | Delete
Additional methods
[1862] Fix | Delete
[1863] Fix | Delete
as_lwp_str(ignore_discard=True, ignore_expired=True)
[1864] Fix | Delete
[1865] Fix | Delete
"""
[1866] Fix | Delete
[1867] Fix | Delete
def as_lwp_str(self, ignore_discard=True, ignore_expires=True):
[1868] Fix | Delete
"""Return cookies as a string of "\\n"-separated "Set-Cookie3" headers.
[1869] Fix | Delete
[1870] Fix | Delete
ignore_discard and ignore_expires: see docstring for FileCookieJar.save
[1871] Fix | Delete
[1872] Fix | Delete
"""
[1873] Fix | Delete
now = time.time()
[1874] Fix | Delete
r = []
[1875] Fix | Delete
for cookie in self:
[1876] Fix | Delete
if not ignore_discard and cookie.discard:
[1877] Fix | Delete
continue
[1878] Fix | Delete
if not ignore_expires and cookie.is_expired(now):
[1879] Fix | Delete
continue
[1880] Fix | Delete
r.append("Set-Cookie3: %s" % lwp_cookie_str(cookie))
[1881] Fix | Delete
return "\n".join(r+[""])
[1882] Fix | Delete
[1883] Fix | Delete
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
[1884] Fix | Delete
if filename is None:
[1885] Fix | Delete
if self.filename is not None: filename = self.filename
[1886] Fix | Delete
else: raise ValueError(MISSING_FILENAME_TEXT)
[1887] Fix | Delete
[1888] Fix | Delete
with open(filename, "w") as f:
[1889] Fix | Delete
# There really isn't an LWP Cookies 2.0 format, but this indicates
[1890] Fix | Delete
# that there is extra information in here (domain_dot and
[1891] Fix | Delete
# port_spec) while still being compatible with libwww-perl, I hope.
[1892] Fix | Delete
f.write("#LWP-Cookies-2.0\n")
[1893] Fix | Delete
f.write(self.as_lwp_str(ignore_discard, ignore_expires))
[1894] Fix | Delete
[1895] Fix | Delete
def _really_load(self, f, filename, ignore_discard, ignore_expires):
[1896] Fix | Delete
magic = f.readline()
[1897] Fix | Delete
if not self.magic_re.search(magic):
[1898] Fix | Delete
msg = ("%r does not look like a Set-Cookie3 (LWP) format "
[1899] Fix | Delete
"file" % filename)
[1900] Fix | Delete
raise LoadError(msg)
[1901] Fix | Delete
[1902] Fix | Delete
now = time.time()
[1903] Fix | Delete
[1904] Fix | Delete
header = "Set-Cookie3:"
[1905] Fix | Delete
boolean_attrs = ("port_spec", "path_spec", "domain_dot",
[1906] Fix | Delete
"secure", "discard")
[1907] Fix | Delete
value_attrs = ("version",
[1908] Fix | Delete
"port", "path", "domain",
[1909] Fix | Delete
"expires",
[1910] Fix | Delete
"comment", "commenturl")
[1911] Fix | Delete
[1912] Fix | Delete
try:
[1913] Fix | Delete
while 1:
[1914] Fix | Delete
line = f.readline()
[1915] Fix | Delete
if line == "": break
[1916] Fix | Delete
if not line.startswith(header):
[1917] Fix | Delete
continue
[1918] Fix | Delete
line = line[len(header):].strip()
[1919] Fix | Delete
[1920] Fix | Delete
for data in split_header_words([line]):
[1921] Fix | Delete
name, value = data[0]
[1922] Fix | Delete
standard = {}
[1923] Fix | Delete
rest = {}
[1924] Fix | Delete
for k in boolean_attrs:
[1925] Fix | Delete
standard[k] = False
[1926] Fix | Delete
for k, v in data[1:]:
[1927] Fix | Delete
if k is not None:
[1928] Fix | Delete
lc = k.lower()
[1929] Fix | Delete
else:
[1930] Fix | Delete
lc = None
[1931] Fix | Delete
# don't lose case distinction for unknown fields
[1932] Fix | Delete
if (lc in value_attrs) or (lc in boolean_attrs):
[1933] Fix | Delete
k = lc
[1934] Fix | Delete
if k in boolean_attrs:
[1935] Fix | Delete
if v is None: v = True
[1936] Fix | Delete
standard[k] = v
[1937] Fix | Delete
elif k in value_attrs:
[1938] Fix | Delete
standard[k] = v
[1939] Fix | Delete
else:
[1940] Fix | Delete
rest[k] = v
[1941] Fix | Delete
[1942] Fix | Delete
h = standard.get
[1943] Fix | Delete
expires = h("expires")
[1944] Fix | Delete
discard = h("discard")
[1945] Fix | Delete
if expires is not None:
[1946] Fix | Delete
expires = iso2time(expires)
[1947] Fix | Delete
if expires is None:
[1948] Fix | Delete
discard = True
[1949] Fix | Delete
domain = h("domain")
[1950] Fix | Delete
domain_specified = domain.startswith(".")
[1951] Fix | Delete
c = Cookie(h("version"), name, value,
[1952] Fix | Delete
h("port"), h("port_spec"),
[1953] Fix | Delete
domain, domain_specified, h("domain_dot"),
[1954] Fix | Delete
h("path"), h("path_spec"),
[1955] Fix | Delete
h("secure"),
[1956] Fix | Delete
expires,
[1957] Fix | Delete
discard,
[1958] Fix | Delete
h("comment"),
[1959] Fix | Delete
h("commenturl"),
[1960] Fix | Delete
rest)
[1961] Fix | Delete
if not ignore_discard and c.discard:
[1962] Fix | Delete
continue
[1963] Fix | Delete
if not ignore_expires and c.is_expired(now):
[1964] Fix | Delete
continue
[1965] Fix | Delete
self.set_cookie(c)
[1966] Fix | Delete
except OSError:
[1967] Fix | Delete
raise
[1968] Fix | Delete
except Exception:
[1969] Fix | Delete
_warn_unhandled_exception()
[1970] Fix | Delete
raise LoadError("invalid Set-Cookie3 format file %r: %r" %
[1971] Fix | Delete
(filename, line))
[1972] Fix | Delete
[1973] Fix | Delete
[1974] Fix | Delete
class MozillaCookieJar(FileCookieJar):
[1975] Fix | Delete
"""
[1976] Fix | Delete
[1977] Fix | Delete
WARNING: you may want to backup your browser's cookies file if you use
[1978] Fix | Delete
this class to save cookies. I *think* it works, but there have been
[1979] Fix | Delete
bugs in the past!
[1980] Fix | Delete
[1981] Fix | Delete
This class differs from CookieJar only in the format it uses to save and
[1982] Fix | Delete
load cookies to and from a file. This class uses the Mozilla/Netscape
[1983] Fix | Delete
`cookies.txt' format. lynx uses this file format, too.
[1984] Fix | Delete
[1985] Fix | Delete
Don't expect cookies saved while the browser is running to be noticed by
[1986] Fix | Delete
the browser (in fact, Mozilla on unix will overwrite your saved cookies if
[1987] Fix | Delete
you change them on disk while it's running; on Windows, you probably can't
[1988] Fix | Delete
save at all while the browser is running).
[1989] Fix | Delete
[1990] Fix | Delete
Note that the Mozilla/Netscape format will downgrade RFC2965 cookies to
[1991] Fix | Delete
Netscape cookies on saving.
[1992] Fix | Delete
[1993] Fix | Delete
In particular, the cookie version and port number information is lost,
[1994] Fix | Delete
together with information about whether or not Path, Port and Discard were
[1995] Fix | Delete
specified by the Set-Cookie2 (or Set-Cookie) header, and whether or not the
[1996] Fix | Delete
domain as set in the HTTP header started with a dot (yes, I'm aware some
[1997] Fix | Delete
domains in Netscape files start with a dot and some don't -- trust me, you
[1998] Fix | Delete
really don't want to know any more about this).
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function