<s> """<STR_LIT>""" <EOL> import abc <EOL> import binascii <EOL> import collections <EOL> import re <EOL> import logging <EOL> from grr . lib import lexer <EOL> from grr . lib import utils <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class MalformedQueryError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class ParseError ( Error , lexer . ParseError ) : <EOL> """<STR_LIT>""" <EOL> class InvalidNumberOfOperands ( Error ) : <EOL> """<STR_LIT>""" <EOL> class Filter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , arguments = None , value_expander = None ) : <EOL> """<STR_LIT>""" <EOL> self . value_expander = None <EOL> self . value_expander_cls = value_expander <EOL> if self . value_expander_cls : <EOL> if not issubclass ( self . value_expander_cls , ValueExpander ) : <EOL> raise Error ( "<STR_LIT>" % ( <EOL> self . value_expander_cls ) ) <EOL> self . value_expander = self . value_expander_cls ( ) <EOL> self . args = arguments or [ ] <EOL> logging . debug ( "<STR_LIT>" , arguments ) <EOL> @ abc . abstractmethod <EOL> def Matches ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> def Filter ( self , objects ) : <EOL> """<STR_LIT>""" <EOL> return filter ( self . Matches , objects ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> "<STR_LIT:U+002CU+0020>" . join ( [ str ( arg ) for arg in self . args ] ) ) <EOL> class AndFilter ( Filter ) : <EOL> """<STR_LIT>""" <EOL> def Matches ( self , obj ) : <EOL> for child_filter in self . args : <EOL> if not child_filter . Matches ( obj ) : <EOL> return False <EOL> return True <EOL> class OrFilter ( Filter ) : <EOL> """<STR_LIT>""" <EOL> def Matches ( self , obj ) : <EOL> if not self . args : return True <EOL> for child_filter in self . args : <EOL> if child_filter . Matches ( obj ) : <EOL> return True <EOL> return False <EOL> class Operator ( Filter ) : <EOL> """<STR_LIT>""" <EOL> class IdentityFilter ( Operator ) : <EOL> def Matches ( self , _ ) : <EOL> return True <EOL> class UnaryOperator ( Operator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , operand , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( UnaryOperator , self ) . __init__ ( arguments = [ operand ] , ** kwargs ) <EOL> if len ( self . args ) != <NUM_LIT:1> : <EOL> raise InvalidNumberOfOperands ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> len ( self . args ) ) ) <EOL> class BinaryOperator ( Operator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , arguments = None , ** kwargs ) : <EOL> super ( BinaryOperator , self ) . __init__ ( arguments = arguments , ** kwargs ) <EOL> if len ( self . args ) != <NUM_LIT:2> : <EOL> raise InvalidNumberOfOperands ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> len ( self . args ) ) ) <EOL> self . left_operand = self . args [ <NUM_LIT:0> ] <EOL> self . right_operand = self . args [ <NUM_LIT:1> ] <EOL> class GenericBinaryOperator ( BinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> """<STR_LIT>""" <EOL> def Operate ( self , values ) : <EOL> """<STR_LIT>""" <EOL> for val in values : <EOL> try : <EOL> logging . debug ( "<STR_LIT>" , <EOL> self . __class__ . __name__ , val , self . right_operand ) <EOL> if self . Operation ( val , self . right_operand ) : <EOL> return True <EOL> else : <EOL> continue <EOL> except ( ValueError , TypeError ) : <EOL> continue <EOL> return False <EOL> def Matches ( self , obj ) : <EOL> key = self . left_operand <EOL> values = self . value_expander . Expand ( obj , key ) <EOL> if values and self . Operate ( values ) : <EOL> return True <EOL> return False <EOL> class Equals ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> return x == y <EOL> class NotEquals ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operate ( self , values ) : <EOL> return not Equals ( arguments = self . args , <EOL> value_expander = self . value_expander_cls ) . Operate ( values ) <EOL> class Less ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> return x < y <EOL> class LessEqual ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> return x <= y <EOL> class Greater ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> return x > y <EOL> class GreaterEqual ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> return x >= y <EOL> class Contains ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> try : <EOL> return y in x <EOL> except TypeError : <EOL> return y == x <EOL> class NotContains ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operate ( self , values ) : <EOL> return not Contains ( arguments = self . args , <EOL> value_expander = self . value_expander_cls ) . Operate ( values ) <EOL> class InSet ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operation ( self , x , y ) : <EOL> """<STR_LIT>""" <EOL> if x in y : <EOL> return True <EOL> if ( isinstance ( x , basestring ) <EOL> or isinstance ( x , bytes ) ) : <EOL> return False <EOL> try : <EOL> for value in x : <EOL> if value not in y : <EOL> return False <EOL> return True <EOL> except TypeError : <EOL> return False <EOL> class NotInSet ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def Operate ( self , values ) : <EOL> return not InSet ( arguments = self . args , <EOL> value_expander = self . value_expander_cls ) . Operate ( values ) <EOL> class Regexp ( GenericBinaryOperator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * children , ** kwargs ) : <EOL> super ( Regexp , self ) . __init__ ( * children , ** kwargs ) <EOL> logging . debug ( "<STR_LIT>" , self . right_operand ) <EOL> try : <EOL> self . compiled_re = re . compile ( utils . SmartUnicode ( self . right_operand ) ) <EOL> except re . error : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> self . right_operand ) <EOL> def Operation ( self , x , y ) : <EOL> try : <EOL> if self . compiled_re . search ( utils . SmartUnicode ( x ) ) : <EOL> return True <EOL> except TypeError : <EOL> return False <EOL> class Context ( Operator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , arguments = None , ** kwargs ) : <EOL> if len ( arguments ) != <NUM_LIT:2> : <EOL> raise InvalidNumberOfOperands ( "<STR_LIT>" ) <EOL> super ( Context , self ) . __init__ ( arguments = arguments , ** kwargs ) <EOL> self . context , self . condition = self . args <EOL> def Matches ( self , obj ) : <EOL> for object_list in self . value_expander . Expand ( obj , self . context ) : <EOL> for sub_object in object_list : <EOL> if self . condition . Matches ( sub_object ) : <EOL> return True <EOL> return False <EOL> OP2FN = { "<STR_LIT>" : Equals , <EOL> "<STR_LIT>" : Equals , <EOL> "<STR_LIT>" : Equals , <EOL> "<STR_LIT>" : NotEquals , <EOL> "<STR_LIT>" : NotEquals , <EOL> "<STR_LIT>" : NotEquals , <EOL> "<STR_LIT>" : Contains , <EOL> "<STR_LIT>" : NotContains , <EOL> "<STR_LIT:>>" : Greater , <EOL> "<STR_LIT>" : GreaterEqual , <EOL> "<STR_LIT:<>" : Less , <EOL> "<STR_LIT>" : LessEqual , <EOL> "<STR_LIT>" : InSet , <EOL> "<STR_LIT>" : NotInSet , <EOL> "<STR_LIT>" : Regexp } <EOL> class ValueExpander ( object ) : <EOL> """<STR_LIT>""" <EOL> FIELD_SEPARATOR = "<STR_LIT:.>" <EOL> def _GetAttributeName ( self , path ) : <EOL> """<STR_LIT>""" <EOL> return path [ <NUM_LIT:0> ] <EOL> def _GetValue ( self , obj , attr_name ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def _AtLeaf ( self , attr_value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( attr_value , collections . Mapping ) : <EOL> for k , v in attr_value . items ( ) : <EOL> yield { k : v } <EOL> else : <EOL> yield attr_value <EOL> def _AtNonLeaf ( self , attr_value , path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if isinstance ( attr_value , collections . Mapping ) : <EOL> sub_obj = attr_value . get ( path [ <NUM_LIT:1> ] ) <EOL> if len ( path ) > <NUM_LIT:2> : <EOL> sub_obj = self . Expand ( sub_obj , path [ <NUM_LIT:2> : ] ) <EOL> if isinstance ( sub_obj , basestring ) : <EOL> yield sub_obj <EOL> elif isinstance ( sub_obj , collections . Mapping ) : <EOL> for k , v in sub_obj . items ( ) : <EOL> yield { k : v } <EOL> else : <EOL> for value in sub_obj : <EOL> yield value <EOL> else : <EOL> for sub_obj in attr_value : <EOL> for value in self . Expand ( sub_obj , path [ <NUM_LIT:1> : ] ) : <EOL> yield value <EOL> except TypeError : <EOL> for value in self . Expand ( attr_value , path [ <NUM_LIT:1> : ] ) : <EOL> yield value <EOL> def Expand ( self , obj , path ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( path , basestring ) : <EOL> path = path . split ( self . FIELD_SEPARATOR ) <EOL> attr_name = self . _GetAttributeName ( path ) <EOL> attr_value = self . _GetValue ( obj , attr_name ) <EOL> if attr_value is None : <EOL> return <EOL> if len ( path ) == <NUM_LIT:1> : <EOL> for value in self . _AtLeaf ( attr_value ) : <EOL> yield value <EOL> else : <EOL> for value in self . _AtNonLeaf ( attr_value , path ) : <EOL> yield value <EOL> class AttributeValueExpander ( ValueExpander ) : <EOL> """<STR_LIT>""" <EOL> def _GetValue ( self , obj , attr_name ) : <EOL> if isinstance ( obj , collections . Mapping ) : <EOL> return obj . get ( attr_name ) <EOL> return getattr ( obj , attr_name , None ) <EOL> class LowercaseAttributeValueExpander ( AttributeValueExpander ) : <EOL> """<STR_LIT>""" <EOL> def _GetAttributeName ( self , path ) : <EOL> return path [ <NUM_LIT:0> ] . lower ( ) <EOL> class DictValueExpander ( ValueExpander ) : <EOL> """<STR_LIT>""" <EOL> def _GetValue ( self , obj , attr_name ) : <EOL> return obj . get ( attr_name , None ) <EOL> class BasicExpression ( lexer . Expression ) : <EOL> def Compile ( self , filter_implementation ) : <EOL> arguments = [ self . attribute ] <EOL> op_str = self . operator . lower ( ) <EOL> operator = filter_implementation . OPS . get ( op_str , None ) <EOL> if not operator : <EOL> raise ParseError ( "<STR_LIT>" % self . operator ) <EOL> arguments . extend ( self . args ) <EOL> expander = filter_implementation . FILTERS [ "<STR_LIT>" ] <EOL> return operator ( arguments = arguments , value_expander = expander ) <EOL> class ContextExpression ( lexer . Expression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attribute = "<STR_LIT>" , part = None ) : <EOL> self . attribute = attribute <EOL> self . args = [ ] <EOL> if part : self . args . append ( part ) <EOL> super ( ContextExpression , self ) . __init__ ( ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . attribute , [ str ( x ) for x in self . args ] ) <EOL> def SetExpression ( self , expression ) : <EOL> if isinstance ( expression , lexer . Expression ) : <EOL> self . args = [ expression ] <EOL> else : <EOL> raise ParseError ( "<STR_LIT>" % expression ) <EOL> def Compile ( self , filter_implementation ) : <EOL> arguments = [ self . attribute ] <EOL> for arg in self . args : <EOL> arguments . append ( arg . Compile ( filter_implementation ) ) <EOL> expander = filter_implementation . FILTERS [ "<STR_LIT>" ] <EOL> context_cls = filter_implementation . FILTERS [ "<STR_LIT>" ] <EOL> return context_cls ( arguments = arguments , <EOL> value_expander = expander ) <EOL> class BinaryExpression ( lexer . BinaryExpression ) : <EOL> def Compile ( self , filter_implemention ) : <EOL> """<STR_LIT>""" <EOL> operator = self . operator . lower ( ) <EOL> if operator == "<STR_LIT>" or operator == "<STR_LIT>" : <EOL> method = "<STR_LIT>" <EOL> elif operator == "<STR_LIT>" or operator == "<STR_LIT>" : <EOL> method = "<STR_LIT>" <EOL> else : <EOL> raise ParseError ( "<STR_LIT>" % operator ) <EOL> args = [ x . Compile ( filter_implemention ) for x in self . args ] <EOL> return filter_implemention . FILTERS [ method ] ( arguments = args ) <EOL> class IdentityExpression ( lexer . Expression ) : <EOL> def Compile ( self , filter_implementation ) : <EOL> return filter_implementation . FILTERS [ "<STR_LIT>" ] ( ) <EOL> class Parser ( lexer . SearchParser ) : <EOL> """<STR_LIT>""" <EOL> expression_cls = BasicExpression <EOL> binary_expression_cls = BinaryExpression <EOL> context_cls = ContextExpression <EOL> identity_expression_cls = IdentityExpression <EOL> list_args = [ ] <EOL> tokens = [ <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT:'>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT:]>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT:'>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT:U+002C>" , None , None ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT:'>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lexer . Token ( "<STR_LIT>" , r"<STR_LIT>" , None , None ) , <EOL> lexer . Token ( "<STR_LIT>" , "<STR_LIT:.>" , "<STR_LIT>" , None ) , <EOL> lexer . Token ( "<STR_LIT:.>" , r"<STR_LIT>" , None , None ) , <EOL> ] <EOL> def InsertArg ( self , string = "<STR_LIT>" , ** _ ) : <EOL> """<STR_LIT>""" <EOL> logging . debug ( "<STR_LIT>" , string ) <EOL> if self . state == "<STR_LIT>" : <EOL> self . list_args . append ( string ) <EOL> elif self . current_expression . AddArg ( string ) : <EOL> self . stack . append ( self . current_expression ) <EOL> self . current_expression = self . expression_cls ( ) <EOL> return "<STR_LIT>" <EOL> def InsertFloatArg ( self , string = "<STR_LIT>" , ** _ ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> float_value = float ( string ) <EOL> return self . InsertArg ( float_value ) <EOL> except ( TypeError , ValueError ) : <EOL> raise ParseError ( "<STR_LIT>" % string ) <EOL> def InsertIntArg ( self , string = "<STR_LIT>" , ** _ ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> int_value = int ( string ) <EOL> return self . InsertArg ( int_value ) <EOL> except ( TypeError , ValueError ) : <EOL> raise ParseError ( "<STR_LIT>" % string ) <EOL> def InsertInt16Arg ( self , string = "<STR_LIT>" , ** _ ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> int_value = int ( string , <NUM_LIT:16> ) <EOL> return self . InsertArg ( int_value ) <EOL> except ( TypeError , ValueError ) : <EOL> raise ParseError ( "<STR_LIT>" % string ) <EOL> def ListStart ( self , ** _ ) : <EOL> self . list_args = [ ] <EOL> def ListFinish ( self , ** _ ) : <EOL> return self . InsertArg ( string = self . list_args ) <EOL> def StringFinish ( self , ** _ ) : <EOL> if self . state == "<STR_LIT>" : <EOL> return self . StoreAttribute ( string = self . string ) <EOL> elif self . state == "<STR_LIT>" or "<STR_LIT>" : <EOL> return self . InsertArg ( string = self . string ) <EOL> def StringEscape ( self , string , match , ** _ ) : <EOL> """<STR_LIT>""" <EOL> if self . current_expression . operator == "<STR_LIT>" : <EOL> self . string += string . decode ( "<STR_LIT>" ) <EOL> elif match . group ( <NUM_LIT:1> ) in "<STR_LIT>" : <EOL> self . string += string . decode ( "<STR_LIT>" ) <EOL> else : <EOL> raise ParseError ( "<STR_LIT>" % string ) <EOL> def HexEscape ( self , string , match , ** _ ) : <EOL> """<STR_LIT>""" <EOL> logging . debug ( "<STR_LIT>" , string ) <EOL> hex_string = match . group ( <NUM_LIT:1> ) <EOL> try : <EOL> self . string += binascii . unhexlify ( hex_string ) <EOL> except TypeError : <EOL> raise ParseError ( "<STR_LIT>" % string ) <EOL> def ContextOperator ( self , string = "<STR_LIT>" , ** _ ) : <EOL> self . stack . append ( self . context_cls ( string [ <NUM_LIT:1> : ] ) ) <EOL> def Reduce ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . state != "<STR_LIT>" and self . state != "<STR_LIT>" : <EOL> self . Error ( "<STR_LIT>" ) <EOL> length = len ( self . stack ) <EOL> while length > <NUM_LIT:1> : <EOL> self . _CombineParenthesis ( ) <EOL> self . _CombineBinaryExpressions ( "<STR_LIT>" ) <EOL> self . _CombineBinaryExpressions ( "<STR_LIT>" ) <EOL> self . _CombineContext ( ) <EOL> if len ( self . stack ) == length : break <EOL> length = len ( self . stack ) <EOL> if length != <NUM_LIT:1> : <EOL> self . Error ( "<STR_LIT>" ) <EOL> return self . stack [ <NUM_LIT:0> ] <EOL> def Error ( self , message = None , _ = None ) : <EOL> raise ParseError ( "<STR_LIT>" % ( <EOL> message , len ( self . processed_buffer ) , self . processed_buffer , <EOL> self . buffer ) ) <EOL> def _CombineBinaryExpressions ( self , operator ) : <EOL> for i in range ( <NUM_LIT:1> , len ( self . stack ) - <NUM_LIT:1> ) : <EOL> item = self . stack [ i ] <EOL> if ( isinstance ( item , lexer . BinaryExpression ) and <EOL> item . operator . lower ( ) == operator . lower ( ) and <EOL> isinstance ( self . stack [ i - <NUM_LIT:1> ] , lexer . Expression ) and <EOL> isinstance ( self . stack [ i + <NUM_LIT:1> ] , lexer . Expression ) ) : <EOL> lhs = self . stack [ i - <NUM_LIT:1> ] <EOL> rhs = self . stack [ i + <NUM_LIT:1> ] <EOL> self . stack [ i ] . AddOperands ( lhs , rhs ) <EOL> self . stack [ i - <NUM_LIT:1> ] = None <EOL> self . stack [ i + <NUM_LIT:1> ] = None <EOL> self . stack = filter ( None , self . stack ) <EOL> def _CombineContext ( self ) : <EOL> for i in range ( len ( self . stack ) - <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> item = self . stack [ i - <NUM_LIT:1> ] <EOL> if ( isinstance ( item , ContextExpression ) and <EOL> isinstance ( self . stack [ i ] , lexer . Expression ) ) : <EOL> expression = self . stack [ i ] <EOL> self . stack [ i - <NUM_LIT:1> ] . SetExpression ( expression ) <EOL> self . stack [ i ] = None <EOL> self . stack = filter ( None , self . stack ) <EOL> class BaseFilterImplementation ( object ) : <EOL> """<STR_LIT>""" <EOL> OPS = OP2FN <EOL> FILTERS = { "<STR_LIT>" : AttributeValueExpander , <EOL> "<STR_LIT>" : AndFilter , <EOL> "<STR_LIT>" : OrFilter , <EOL> "<STR_LIT>" : IdentityFilter , <EOL> "<STR_LIT>" : Context } <EOL> class LowercaseAttributeFilterImplementation ( BaseFilterImplementation ) : <EOL> """<STR_LIT>""" <EOL> FILTERS = { } <EOL> FILTERS . update ( BaseFilterImplementation . FILTERS ) <EOL> FILTERS . update ( { "<STR_LIT>" : LowercaseAttributeValueExpander } ) <EOL> class DictFilterImplementation ( BaseFilterImplementation ) : <EOL> """<STR_LIT>""" <EOL> FILTERS = { } <EOL> FILTERS . update ( BaseFilterImplementation . FILTERS ) <EOL> FILTERS . update ( { "<STR_LIT>" : DictValueExpander } ) </s>
