<s> """<STR_LIT>""" <EOL> import operator <EOL> import re <EOL> from grr . lib import aff4 <EOL> from grr . lib import utils <EOL> class IdentityFilter ( aff4 . AFF4Filter ) : <EOL> """<STR_LIT>""" <EOL> def FilterOne ( self , fd ) : <EOL> return fd <EOL> def Filter ( self , subjects ) : <EOL> return subjects <EOL> class HasPredicateFilter ( aff4 . AFF4Filter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attribute_name ) : <EOL> self . attribute_name = attribute_name <EOL> def FilterOne ( self , subject ) : <EOL> if subject . Get ( self . attribute_name ) : <EOL> return subject <EOL> return False <EOL> class AndFilter ( aff4 . AFF4Filter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * parts ) : <EOL> self . parts = parts <EOL> def FilterOne ( self , subject ) : <EOL> result = subject <EOL> for part in self . parts : <EOL> result = part . FilterOne ( result ) <EOL> if not result : <EOL> return False <EOL> return result <EOL> def Compile ( self , filter_cls ) : <EOL> return getattr ( filter_cls , self . __class__ . __name__ ) ( <EOL> * [ x . Compile ( filter_cls ) for x in self . args ] ) <EOL> class OrFilter ( AndFilter ) : <EOL> """<STR_LIT>""" <EOL> def FilterOne ( self , subject ) : <EOL> for part in self . parts : <EOL> result = part . FilterOne ( subject ) <EOL> if result : <EOL> return result <EOL> class PredicateLessThanFilter ( aff4 . AFF4Filter ) : <EOL> """<STR_LIT>""" <EOL> operator_function = operator . lt <EOL> def __init__ ( self , attribute_name , value ) : <EOL> self . value = value <EOL> self . attribute_name = attribute_name <EOL> def FilterOne ( self , subject ) : <EOL> predicate_value = subject . Get ( self . attribute_name ) <EOL> if predicate_value and self . operator_function ( <EOL> predicate_value , self . value ) : <EOL> return subject <EOL> class PredicateGreaterThanFilter ( PredicateLessThanFilter ) : <EOL> operator_function = operator . gt <EOL> class PredicateGreaterEqualFilter ( PredicateLessThanFilter ) : <EOL> operator_function = operator . ge <EOL> class PredicateLesserEqualFilter ( PredicateLessThanFilter ) : <EOL> operator_function = operator . le <EOL> class PredicateNumericEqualFilter ( PredicateLessThanFilter ) : <EOL> operator_function = operator . eq <EOL> class PredicateEqualFilter ( PredicateLessThanFilter ) : <EOL> operator_function = operator . eq <EOL> class PredicateContainsFilter ( PredicateLessThanFilter ) : <EOL> """<STR_LIT>""" <EOL> regex = None <EOL> def __init__ ( self , attribute_name , value ) : <EOL> super ( PredicateContainsFilter , self ) . __init__ ( attribute_name , value ) <EOL> if value : <EOL> self . regex = re . compile ( value ) <EOL> def FilterOne ( self , subject ) : <EOL> if self . regex is None : <EOL> return subject <EOL> else : <EOL> predicate_value = subject . Get ( self . attribute_name ) <EOL> if ( predicate_value and <EOL> self . regex . search ( utils . SmartUnicode ( predicate_value ) ) ) : <EOL> return subject <EOL> class SubjectContainsFilter ( aff4 . AFF4Filter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , regex ) : <EOL> """<STR_LIT>""" <EOL> self . regex_text = utils . SmartUnicode ( regex ) <EOL> self . regex = re . compile ( self . regex_text ) <EOL> super ( SubjectContainsFilter , self ) . __init__ ( ) <EOL> def FilterOne ( self , subject ) : <EOL> if self . regex . search ( utils . SmartUnicode ( subject . urn ) ) : <EOL> return subject </s>
