<s> import sys <EOL> import re <EOL> import cPickle as pickle <EOL> from test_utils . testmaker import Testmaker <EOL> from test_utils . testmaker . processors . django_processor import Processor <EOL> class MockRequest ( dict ) : <EOL> '<STR_LIT>' <EOL> def __getattr__ ( self , name ) : <EOL> return self [ name ] <EOL> class Replay ( object ) : <EOL> def __init__ ( self , file_name , replay_file = '<STR_LIT>' ) : <EOL> self . file_name = file_name <EOL> self . stream = open ( self . file_name ) . readlines ( ) <EOL> self . tm = Testmaker ( ) <EOL> self . tm . setup_logging ( replay_file , '<STR_LIT>' ) <EOL> self . processor = Processor ( '<STR_LIT>' ) <EOL> self . serial_obj = pickle <EOL> def process ( self ) : <EOL> self . log = [ ] <EOL> buffer = [ ] <EOL> req_re = re . compile ( '<STR_LIT>' ) <EOL> res_re = re . compile ( '<STR_LIT>' ) <EOL> for line in self . stream : <EOL> if req_re . search ( line ) : <EOL> to_pickle = '<STR_LIT>' . join ( buffer ) <EOL> request = MockRequest ( self . serial_obj . loads ( to_pickle ) ) <EOL> self . processor . save_request ( request ) <EOL> print request [ '<STR_LIT:path>' ] , request [ '<STR_LIT:time>' ] <EOL> buffer = [ ] <EOL> elif res_re . search ( line ) : <EOL> to_pickle = '<STR_LIT>' . join ( buffer ) <EOL> response = MockRequest ( self . serial_obj . loads ( to_pickle ) ) <EOL> self . log . append ( request , response ) <EOL> self . processer . save_response ( request , response ) <EOL> print response [ '<STR_LIT>' ] , response [ '<STR_LIT:time>' ] <EOL> buffer = [ ] <EOL> else : <EOL> buffer . append ( line ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) == <NUM_LIT:2> : <EOL> in_file = sys . argv [ <NUM_LIT:1> ] <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> replay = Replay ( in_file ) <EOL> replay . process ( ) </s>
