MCPcopy Index your code
hub / github.com/python/cpython / _really_load

Method _really_load

Lib/http/cookiejar.py:2013–2081  ·  view source on GitHub ↗
(self, f, filename, ignore_discard, ignore_expires)

Source from the content-addressed store, hash-verified

2011 """
2012
2013 def _really_load(self, f, filename, ignore_discard, ignore_expires):
2014 now = time.time()
2015
2016 if not NETSCAPE_MAGIC_RGX.match(f.readline()):
2017 raise LoadError(
2018 "%r does not look like a Netscape format cookies file" %
2019 filename)
2020
2021 try:
2022 while (line := f.readline()) != "":
2023 rest = {}
2024
2025 # httponly is a cookie flag as defined in rfc6265
2026 # when encoded in a netscape cookie file,
2027 # the line is prepended with "#HttpOnly_"
2028 if line.startswith(HTTPONLY_PREFIX):
2029 rest[HTTPONLY_ATTR] = ""
2030 line = line[len(HTTPONLY_PREFIX):]
2031
2032 # last field may be absent, so keep any trailing tab
2033 if line.endswith("\n"): line = line[:-1]
2034
2035 # skip comments and blank lines XXX what is $ for?
2036 if (line.strip().startswith(("#", "$")) or
2037 line.strip() == ""):
2038 continue
2039
2040 domain, domain_specified, path, secure, expires, name, value = \
2041 line.split("\t")
2042 secure = (secure == "TRUE")
2043 domain_specified = (domain_specified == "TRUE")
2044 if name == "":
2045 # cookies.txt regards 'Set-Cookie: foo' as a cookie
2046 # with no name, whereas http.cookiejar regards it as a
2047 # cookie with no value.
2048 name = value
2049 value = None
2050
2051 initial_dot = domain.startswith(".")
2052 assert domain_specified == initial_dot
2053
2054 discard = False
2055 if expires == "":
2056 expires = None
2057 discard = True
2058
2059 # assume path_specified is false
2060 c = Cookie(0, name, value,
2061 None, False,
2062 domain, domain_specified, initial_dot,
2063 path, False,
2064 secure,
2065 expires,
2066 discard,
2067 None,
2068 None,
2069 rest)
2070 if not ignore_discard and c.discard:

Callers

nothing calls this directly

Calls 12

is_expiredMethod · 0.95
LoadErrorClass · 0.85
CookieClass · 0.85
set_cookieMethod · 0.80
timeMethod · 0.45
matchMethod · 0.45
readlineMethod · 0.45
startswithMethod · 0.45
endswithMethod · 0.45
stripMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected