(cookieJar)
Cleans cookies from a given cookie jar
Cleans cookies from a given cookie jar
Cleans cookies from a given cookie jar
def resetCookieJar(cookieJar):
    """
    Cleans cookies from a given cookie jar
    """

    if not conf.loadCookies:
        cookieJar.clear()
    else:
        try:
            if not cookieJar.filename:
                infoMsg = "loading cookies from '%s'" % conf.loadCookies
                logger.info(infoMsg)

                content = readCachedFileContent(conf.loadCookies)
                lines = filter(None, (line.strip() for line in content.split("\n") if not line.startswith('#')))
                handle, filename = tempfile.mkstemp(prefix="sqlmapcj-")
                os.close(handle)

                # Reference: http://www.hashbangcode.com/blog/netscape-http-cooke-file-parser-php-584.html
                with open(filename, "w+b") as f:
                    f.write("%s\n" % NETSCAPE_FORMAT_HEADER_COOKIES)
                    for line in lines:
                        _ = line.split("\t")
                        if len(_) == 7:
                            _[4] = FORCE_COOKIE_EXPIRATION_TIME
                            f.write("\n%s" % "\t".join(_))

                cookieJar.filename = filename

            cookieJar.load(cookieJar.filename, ignore_expires=True)

            for cookie in cookieJar:
                if cookie.expires < time.time():
                    warnMsg = "cookie '%s' has expired" % cookie
                    singleTimeWarnMessage(warnMsg)

            cookieJar.clear_expired_cookies()

            if not cookieJar._cookies:
                errMsg = "no valid cookies found"
                raise SqlmapGenericException(errMsg)

        except cookielib.LoadError, msg:
            errMsg = "there was a problem loading "
            errMsg += "cookies file ('%s')" % re.sub(r"(cookies) file '[^']+'", "\g<1>", str(msg))
            raise SqlmapGenericException(errMsg)
def resetCookieJar ( cookieJar ) : if not conf . loadCookies : cookieJar . clear ( ) else : try : if not cookieJar . filename : infoMsg = "loading cookies from '%s'" % conf . loadCookies logger . info ( infoMsg ) content = readCachedFileContent ( conf . loadCookies ) lines = filter ( None , ( line . strip ( ) for line in content . split ( "\n" ) if not line . startswith ( '#' ) ) ) handle , filename = tempfile . mkstemp ( prefix = "sqlmapcj-" ) os . close ( handle ) # Reference: http://www.hashbangcode.com/blog/netscape-http-cooke-file-parser-php-584.html with open ( filename , "w+b" ) as f : f . write ( "%s\n" % NETSCAPE_FORMAT_HEADER_COOKIES ) for line in lines : _ = line . split ( "\t" ) if len ( _ ) == 7 : _ [ 4 ] = FORCE_COOKIE_EXPIRATION_TIME f . write ( "\n%s" % "\t" . join ( _ ) ) cookieJar . filename = filename cookieJar . load ( cookieJar . filename , ignore_expires = True ) for cookie in cookieJar : if cookie . expires < time . time ( ) : warnMsg = "cookie '%s' has expired" % cookie singleTimeWarnMessage ( warnMsg ) cookieJar . clear_expired_cookies ( ) if not cookieJar . _cookies : errMsg = "no valid cookies found" raise SqlmapGenericException ( errMsg ) except cookielib . LoadError , msg : errMsg = "there was a problem loading " errMsg += "cookies file ('%s')" % re . sub ( r"(cookies) file '[^']+'" , "\g<1>" , str ( msg ) ) raise SqlmapGenericException ( errMsg )