WARNING: you may want to backup your browser's cookies file if you use this class to save cookies. I *think* it works, but there have been bugs in the past! This class differs from CookieJar only in the format it uses to save and load cookies to and from a file. This class u
| 1979 | |
| 1980 | |
| 1981 | class MozillaCookieJar(FileCookieJar): |
| 1982 | """ |
| 1983 | |
| 1984 | WARNING: you may want to backup your browser's cookies file if you use |
| 1985 | this class to save cookies. I *think* it works, but there have been |
| 1986 | bugs in the past! |
| 1987 | |
| 1988 | This class differs from CookieJar only in the format it uses to save and |
| 1989 | load cookies to and from a file. This class uses the Mozilla/Netscape |
| 1990 | 'cookies.txt' format. curl and lynx use this file format, too. |
| 1991 | |
| 1992 | Don't expect cookies saved while the browser is running to be noticed by |
| 1993 | the browser (in fact, Mozilla on unix will overwrite your saved cookies if |
| 1994 | you change them on disk while it's running; on Windows, you probably can't |
| 1995 | save at all while the browser is running). |
| 1996 | |
| 1997 | Note that the Mozilla/Netscape format will downgrade RFC2965 cookies to |
| 1998 | Netscape cookies on saving. |
| 1999 | |
| 2000 | In particular, the cookie version and port number information is lost, |
| 2001 | together with information about whether or not Path, Port and Discard were |
| 2002 | specified by the Set-Cookie2 (or Set-Cookie) header, and whether or not the |
| 2003 | domain as set in the HTTP header started with a dot (yes, I'm aware some |
| 2004 | domains in Netscape files start with a dot and some don't -- trust me, you |
| 2005 | really don't want to know any more about this). |
| 2006 | |
| 2007 | Note that though Mozilla and Netscape use the same format, they use |
| 2008 | slightly different headers. The class saves cookies using the Netscape |
| 2009 | header by default (Mozilla can cope with that). |
| 2010 | |
| 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 |
no outgoing calls
searching dependent graphs…