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

Method save

Lib/http/cookiejar.py:2083–2122  ·  view source on GitHub ↗
(self, filename=None, ignore_discard=False, ignore_expires=False)

Source from the content-addressed store, hash-verified

2081 (filename, line))
2082
2083 def save(self, filename=None, ignore_discard=False, ignore_expires=False):
2084 if filename is None:
2085 if self.filename is not None: filename = self.filename
2086 else: raise ValueError(MISSING_FILENAME_TEXT)
2087
2088 with os.fdopen(
2089 os.open(filename, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
2090 'w',
2091 ) as f:
2092 f.write(NETSCAPE_HEADER_TEXT)
2093 now = time.time()
2094 for cookie in self:
2095 domain = cookie.domain
2096 if not ignore_discard and cookie.discard:
2097 continue
2098 if not ignore_expires and cookie.is_expired(now):
2099 continue
2100 if cookie.secure: secure = "TRUE"
2101 else: secure = "FALSE"
2102 if domain.startswith("."): initial_dot = "TRUE"
2103 else: initial_dot = "FALSE"
2104 if cookie.expires is not None:
2105 expires = str(cookie.expires)
2106 else:
2107 expires = ""
2108 if cookie.value is None:
2109 # cookies.txt regards 'Set-Cookie: foo' as a cookie
2110 # with no name, whereas http.cookiejar regards it as a
2111 # cookie with no value.
2112 name = ""
2113 value = cookie.name
2114 else:
2115 name = cookie.name
2116 value = cookie.value
2117 if cookie.has_nonstandard_attr(HTTPONLY_ATTR):
2118 domain = HTTPONLY_PREFIX + domain
2119 f.write(
2120 "\t".join([domain, initial_dot, cookie.path,
2121 secure, expires, name, value])+
2122 "\n")

Callers 2

test_missing_valueMethod · 0.95

Calls 8

strFunction · 0.85
is_expiredMethod · 0.80
has_nonstandard_attrMethod · 0.80
openMethod · 0.45
writeMethod · 0.45
timeMethod · 0.45
startswithMethod · 0.45
joinMethod · 0.45

Tested by 2

test_missing_valueMethod · 0.76