<s> import fileinput <EOL> class TcpParser ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . stream_id = False <EOL> self . data = bytearray ( ) <EOL> self . ts = <NUM_LIT:0> <EOL> def parse_line ( self , line ) : <EOL> stream_id , timestamp , data = line . split ( "<STR_LIT:\t>" ) <EOL> data = data [ : - <NUM_LIT:1> ] <EOL> if self . stream_id == False : <EOL> self . stream_id = stream_id <EOL> self . ts = timestamp <EOL> self . data = bytearray . fromhex ( data ) <EOL> elif stream_id != self . stream_id : <EOL> tcpData = TcpStreamData ( self . ts , self . stream_id , self . data ) <EOL> self . stream_id = stream_id <EOL> self . ts = timestamp <EOL> self . data = bytearray . fromhex ( data ) <EOL> return tcpData <EOL> else : <EOL> self . data . extend ( bytearray . fromhex ( data ) ) <EOL> return False <EOL> def finalize ( self ) : <EOL> """<STR_LIT>""" <EOL> tcpData = TcpStreamData ( self . ts , self . stream_id , self . data ) <EOL> self . __init__ ( ) <EOL> return tcpData <EOL> class TcpStreamData ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ts , stream_id , data ) : <EOL> self . timestamp = ts <EOL> self . _id = stream_id <EOL> self . data = data <EOL> t = TcpParser ( ) <EOL> for line in fileinput . input ( ) : <EOL> tcp_stream = t . parse_line ( line ) <EOL> if tcp_stream != False : <EOL> fn = '<STR_LIT>' . format ( int ( tcp_stream . _id ) ) <EOL> with open ( fn , '<STR_LIT:wb>' ) as f : <EOL> f . write ( tcp_stream . data ) <EOL> tcp_stream = t . finalize ( ) <EOL> fn = '<STR_LIT>' . format ( int ( tcp_stream . _id ) ) <EOL> with open ( fn , '<STR_LIT:wb>' ) as f : <EOL> f . write ( tcp_stream . data ) </s>
