def METHOD_NAME(self, filename=None, ignore_discard=False, ignore_expires=False):
    if filename is None:
        if self.filename is not None: filename = self.filename
        else: raise ValueError(MISSING_FILENAME_TEXT)
    f = open(filename, "w")
    try:
        f.write(self.header)
        now = time.time()
        for cookie in self:
            if not ignore_discard and cookie.discard:
                continue
            if not ignore_expires and cookie.is_expired(now):
                continue
            if cookie.secure: secure = "TRUE"
            else: secure = "FALSE"
            if cookie.domain.startswith("."): initial_dot = "TRUE"
            else: initial_dot = "FALSE"
            if cookie.expires is not None:
                expires = str(cookie.expires)
            else:
                expires = ""
            if cookie.value is None:
                # cookies.txt regards 'Set-Cookie: foo' as a cookie
                # with no name, whereas cookielib regards it as a
                # cookie with no value.
                name = ""
                value = cookie.name
            else:
                name = cookie.name
                value = cookie.value
            f.write(
                "\t".join([cookie.domain, initial_dot, cookie.path,
                           secure, expires, name, value])+
                "\n")
    finally:
        f.close()