<s> """<STR_LIT>""" <EOL> import cStringIO <EOL> import types <EOL> from binplist import binplist <EOL> from grr . client import actions <EOL> from grr . client import vfs <EOL> from grr . lib import plist as plist_lib <EOL> from grr . lib . rdfvalues import plist as rdfplist <EOL> from grr . lib . rdfvalues import protodict <EOL> class PlistQuery ( actions . ActionPlugin ) : <EOL> """<STR_LIT>""" <EOL> in_rdfvalue = rdfplist . PlistRequest <EOL> out_rdfvalues = [ protodict . RDFValueArray ] <EOL> MAX_PLIST_SIZE = <NUM_LIT> * <NUM_LIT> * <NUM_LIT:100> <EOL> def Run ( self , args ) : <EOL> self . context = args . context <EOL> self . filter_query = args . query <EOL> with vfs . VFSOpen ( args . pathspec , progress_callback = self . Progress ) as fd : <EOL> data = fd . Read ( self . MAX_PLIST_SIZE ) <EOL> plist = binplist . readPlist ( cStringIO . StringIO ( data ) ) <EOL> parser = plist_lib . PlistFilterParser ( self . filter_query ) . Parse ( ) <EOL> filter_imp = plist_lib . PlistFilterImplementation <EOL> matcher = parser . Compile ( filter_imp ) <EOL> if self . context : <EOL> value_expander = filter_imp . FILTERS [ "<STR_LIT>" ] <EOL> iterator = value_expander ( ) . Expand ( plist , self . context ) <EOL> else : <EOL> iterator = [ plist ] <EOL> reply = protodict . RDFValueArray ( ) <EOL> for item in iterator : <EOL> if isinstance ( item , types . ListType ) : <EOL> for sub_item in item : <EOL> partial_plist = plist_lib . PlistValueToPlainValue ( sub_item ) <EOL> if matcher . Matches ( partial_plist ) : <EOL> reply . Append ( sub_item ) <EOL> else : <EOL> partial_plist = plist_lib . PlistValueToPlainValue ( item ) <EOL> if matcher . Matches ( partial_plist ) : <EOL> reply . Append ( partial_plist ) <EOL> self . SendReply ( reply ) </s>
