(self, f, filename, ignore_discard, ignore_expires)
| 1902 | f.write(self.as_lwp_str(ignore_discard, ignore_expires)) |
| 1903 | |
| 1904 | def _really_load(self, f, filename, ignore_discard, ignore_expires): |
| 1905 | magic = f.readline() |
| 1906 | if not self.magic_re.search(magic): |
| 1907 | msg = ("%r does not look like a Set-Cookie3 (LWP) format " |
| 1908 | "file" % filename) |
| 1909 | raise LoadError(msg) |
| 1910 | |
| 1911 | now = time.time() |
| 1912 | |
| 1913 | header = "Set-Cookie3:" |
| 1914 | boolean_attrs = ("port_spec", "path_spec", "domain_dot", |
| 1915 | "secure", "discard") |
| 1916 | value_attrs = ("version", |
| 1917 | "port", "path", "domain", |
| 1918 | "expires", |
| 1919 | "comment", "commenturl") |
| 1920 | |
| 1921 | try: |
| 1922 | while (line := f.readline()) != "": |
| 1923 | if not line.startswith(header): |
| 1924 | continue |
| 1925 | line = line[len(header):].strip() |
| 1926 | |
| 1927 | for data in split_header_words([line]): |
| 1928 | name, value = data[0] |
| 1929 | standard = {} |
| 1930 | rest = {} |
| 1931 | for k in boolean_attrs: |
| 1932 | standard[k] = False |
| 1933 | for k, v in data[1:]: |
| 1934 | if k is not None: |
| 1935 | lc = k.lower() |
| 1936 | else: |
| 1937 | lc = None |
| 1938 | # don't lose case distinction for unknown fields |
| 1939 | if (lc in value_attrs) or (lc in boolean_attrs): |
| 1940 | k = lc |
| 1941 | if k in boolean_attrs: |
| 1942 | if v is None: v = True |
| 1943 | standard[k] = v |
| 1944 | elif k in value_attrs: |
| 1945 | standard[k] = v |
| 1946 | else: |
| 1947 | rest[k] = v |
| 1948 | |
| 1949 | h = standard.get |
| 1950 | expires = h("expires") |
| 1951 | discard = h("discard") |
| 1952 | if expires is not None: |
| 1953 | expires = iso2time(expires) |
| 1954 | if expires is None: |
| 1955 | discard = True |
| 1956 | domain = h("domain") |
| 1957 | domain_specified = domain.startswith(".") |
| 1958 | c = Cookie(h("version"), name, value, |
| 1959 | h("port"), h("port_spec"), |
| 1960 | domain, domain_specified, h("domain_dot"), |
| 1961 | h("path"), h("path_spec"), |
no test coverage detected