Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../http
File: cookiejar.py
[2000] Fix | Delete
Note that though Mozilla and Netscape use the same format, they use
[2001] Fix | Delete
slightly different headers. The class saves cookies using the Netscape
[2002] Fix | Delete
header by default (Mozilla can cope with that).
[2003] Fix | Delete
[2004] Fix | Delete
"""
[2005] Fix | Delete
magic_re = re.compile("#( Netscape)? HTTP Cookie File")
[2006] Fix | Delete
header = """\
[2007] Fix | Delete
# Netscape HTTP Cookie File
[2008] Fix | Delete
# http://curl.haxx.se/rfc/cookie_spec.html
[2009] Fix | Delete
# This is a generated file! Do not edit.
[2010] Fix | Delete
[2011] Fix | Delete
"""
[2012] Fix | Delete
[2013] Fix | Delete
def _really_load(self, f, filename, ignore_discard, ignore_expires):
[2014] Fix | Delete
now = time.time()
[2015] Fix | Delete
[2016] Fix | Delete
magic = f.readline()
[2017] Fix | Delete
if not self.magic_re.search(magic):
[2018] Fix | Delete
raise LoadError(
[2019] Fix | Delete
"%r does not look like a Netscape format cookies file" %
[2020] Fix | Delete
filename)
[2021] Fix | Delete
[2022] Fix | Delete
try:
[2023] Fix | Delete
while 1:
[2024] Fix | Delete
line = f.readline()
[2025] Fix | Delete
if line == "": break
[2026] Fix | Delete
[2027] Fix | Delete
# last field may be absent, so keep any trailing tab
[2028] Fix | Delete
if line.endswith("\n"): line = line[:-1]
[2029] Fix | Delete
[2030] Fix | Delete
# skip comments and blank lines XXX what is $ for?
[2031] Fix | Delete
if (line.strip().startswith(("#", "$")) or
[2032] Fix | Delete
line.strip() == ""):
[2033] Fix | Delete
continue
[2034] Fix | Delete
[2035] Fix | Delete
domain, domain_specified, path, secure, expires, name, value = \
[2036] Fix | Delete
line.split("\t")
[2037] Fix | Delete
secure = (secure == "TRUE")
[2038] Fix | Delete
domain_specified = (domain_specified == "TRUE")
[2039] Fix | Delete
if name == "":
[2040] Fix | Delete
# cookies.txt regards 'Set-Cookie: foo' as a cookie
[2041] Fix | Delete
# with no name, whereas http.cookiejar regards it as a
[2042] Fix | Delete
# cookie with no value.
[2043] Fix | Delete
name = value
[2044] Fix | Delete
value = None
[2045] Fix | Delete
[2046] Fix | Delete
initial_dot = domain.startswith(".")
[2047] Fix | Delete
assert domain_specified == initial_dot
[2048] Fix | Delete
[2049] Fix | Delete
discard = False
[2050] Fix | Delete
if expires == "":
[2051] Fix | Delete
expires = None
[2052] Fix | Delete
discard = True
[2053] Fix | Delete
[2054] Fix | Delete
# assume path_specified is false
[2055] Fix | Delete
c = Cookie(0, name, value,
[2056] Fix | Delete
None, False,
[2057] Fix | Delete
domain, domain_specified, initial_dot,
[2058] Fix | Delete
path, False,
[2059] Fix | Delete
secure,
[2060] Fix | Delete
expires,
[2061] Fix | Delete
discard,
[2062] Fix | Delete
None,
[2063] Fix | Delete
None,
[2064] Fix | Delete
{})
[2065] Fix | Delete
if not ignore_discard and c.discard:
[2066] Fix | Delete
continue
[2067] Fix | Delete
if not ignore_expires and c.is_expired(now):
[2068] Fix | Delete
continue
[2069] Fix | Delete
self.set_cookie(c)
[2070] Fix | Delete
[2071] Fix | Delete
except OSError:
[2072] Fix | Delete
raise
[2073] Fix | Delete
except Exception:
[2074] Fix | Delete
_warn_unhandled_exception()
[2075] Fix | Delete
raise LoadError("invalid Netscape format cookies file %r: %r" %
[2076] Fix | Delete
(filename, line))
[2077] Fix | Delete
[2078] Fix | Delete
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
[2079] Fix | Delete
if filename is None:
[2080] Fix | Delete
if self.filename is not None: filename = self.filename
[2081] Fix | Delete
else: raise ValueError(MISSING_FILENAME_TEXT)
[2082] Fix | Delete
[2083] Fix | Delete
with open(filename, "w") as f:
[2084] Fix | Delete
f.write(self.header)
[2085] Fix | Delete
now = time.time()
[2086] Fix | Delete
for cookie in self:
[2087] Fix | Delete
if not ignore_discard and cookie.discard:
[2088] Fix | Delete
continue
[2089] Fix | Delete
if not ignore_expires and cookie.is_expired(now):
[2090] Fix | Delete
continue
[2091] Fix | Delete
if cookie.secure: secure = "TRUE"
[2092] Fix | Delete
else: secure = "FALSE"
[2093] Fix | Delete
if cookie.domain.startswith("."): initial_dot = "TRUE"
[2094] Fix | Delete
else: initial_dot = "FALSE"
[2095] Fix | Delete
if cookie.expires is not None:
[2096] Fix | Delete
expires = str(cookie.expires)
[2097] Fix | Delete
else:
[2098] Fix | Delete
expires = ""
[2099] Fix | Delete
if cookie.value is None:
[2100] Fix | Delete
# cookies.txt regards 'Set-Cookie: foo' as a cookie
[2101] Fix | Delete
# with no name, whereas http.cookiejar regards it as a
[2102] Fix | Delete
# cookie with no value.
[2103] Fix | Delete
name = ""
[2104] Fix | Delete
value = cookie.name
[2105] Fix | Delete
else:
[2106] Fix | Delete
name = cookie.name
[2107] Fix | Delete
value = cookie.value
[2108] Fix | Delete
f.write(
[2109] Fix | Delete
"\t".join([cookie.domain, initial_dot, cookie.path,
[2110] Fix | Delete
secure, expires, name, value])+
[2111] Fix | Delete
"\n")
[2112] Fix | Delete
[2113] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function