MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / _firefox_storage_state

Function _firefox_storage_state

scripts/website/export_storage_state.py:149–178  ·  view source on GitHub ↗
(cookies_db: Path, host_glob: str)

Source from the content-addressed store, hash-verified

147
148
149def _firefox_storage_state(cookies_db: Path, host_glob: str) -> dict:
150 # Copy to a temp file because Firefox holds a write lock on the live DB.
151 with tempfile.NamedTemporaryFile(suffix=".sqlite", delete=False) as tmp:
152 tmp_path = Path(tmp.name)
153 shutil.copy2(cookies_db, tmp_path)
154 try:
155 conn = sqlite3.connect(f"file:{tmp_path}?mode=ro", uri=True)
156 cur = conn.execute(
157 "SELECT name, value, host, path, expiry, isSecure, isHttpOnly, sameSite "
158 "FROM moz_cookies WHERE host LIKE ?",
159 (host_glob,),
160 )
161 rows = cur.fetchall()
162 conn.close()
163 finally:
164 tmp_path.unlink(missing_ok=True)
165 samesite_map = {0: "None", 1: "Lax", 2: "Strict"}
166 cookies = []
167 for name, value, host, path, expiry, is_secure, is_http_only, same_site in rows:
168 cookies.append({
169 "name": name,
170 "value": value,
171 "domain": host if host.startswith(".") else "." + host,
172 "path": path or "/",
173 "expires": _normalize_expiry(expiry),
174 "httpOnly": bool(is_http_only),
175 "secure": bool(is_secure),
176 "sameSite": samesite_map.get(int(same_site or 0), "None"),
177 })
178 return {"cookies": cookies, "origins": []}
179
180
181def _normalize_expiry(raw: float | int | None) -> float:

Callers 2

mainFunction · 0.85

Calls 7

_normalize_expiryFunction · 0.85
executeMethod · 0.65
closeMethod · 0.65
appendMethod · 0.65
getMethod · 0.65
PathClass · 0.50
connectMethod · 0.45

Tested by

no test coverage detected