<s> import time <EOL> class Guard : <EOL> def __init__ ( self , db ) : <EOL> self . db = db <EOL> self . conf = db . conf . section ( "<STR_LIT>" ) <EOL> self . max_age = db . conf . getint ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def validate ( self , uri , comment ) : <EOL> if not self . conf . getboolean ( "<STR_LIT>" ) : <EOL> return True , "<STR_LIT>" <EOL> for func in ( self . _limit , self . _spam ) : <EOL> valid , reason = func ( uri , comment ) <EOL> if not valid : <EOL> return False , reason <EOL> return True , "<STR_LIT>" <EOL> @ classmethod <EOL> def ids ( cls , rv ) : <EOL> return [ str ( col [ <NUM_LIT:0> ] ) for col in rv ] <EOL> def _limit ( self , uri , comment ) : <EOL> rv = self . db . execute ( [ <EOL> '<STR_LIT>' <EOL> ] , ( comment [ "<STR_LIT>" ] , time . time ( ) ) ) . fetchall ( ) <EOL> if len ( rv ) >= self . conf . getint ( "<STR_LIT>" ) : <EOL> return False , "<STR_LIT>" . format ( <EOL> comment [ "<STR_LIT>" ] , '<STR_LIT:U+002CU+0020>' . join ( Guard . ids ( rv ) ) ) <EOL> if comment [ "<STR_LIT>" ] is None : <EOL> rv = self . db . execute ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , ( uri , comment [ "<STR_LIT>" ] ) ) . fetchall ( ) <EOL> if len ( rv ) >= self . conf . getint ( "<STR_LIT>" ) : <EOL> return False , "<STR_LIT>" % ( len ( rv ) , uri ) <EOL> elif self . conf . getboolean ( "<STR_LIT>" ) == False : <EOL> rv = self . db . execute ( [ <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , ( comment [ "<STR_LIT>" ] , comment [ "<STR_LIT>" ] , <EOL> time . time ( ) , self . max_age ) ) . fetchall ( ) <EOL> if len ( rv ) > <NUM_LIT:0> : <EOL> return False , "<STR_LIT>" <EOL> if self . conf . getboolean ( "<STR_LIT>" ) and not comment . get ( "<STR_LIT:email>" ) : <EOL> return False , "<STR_LIT>" <EOL> return True , "<STR_LIT>" <EOL> def _spam ( self , uri , comment ) : <EOL> return True , "<STR_LIT>" </s>
