<s> """<STR_LIT>""" <EOL> from construct import * <EOL> import time <EOL> from datetime import datetime <EOL> class MicrosecAdapter ( Adapter ) : <EOL> def _decode ( self , obj , context ) : <EOL> return datetime . fromtimestamp ( obj [ <NUM_LIT:0> ] + ( obj [ <NUM_LIT:1> ] / <NUM_LIT> ) ) <EOL> def _encode ( self , obj , context ) : <EOL> offset = time . mktime ( * obj . timetuple ( ) ) <EOL> sec = int ( offset ) <EOL> usec = ( offset - sec ) * <NUM_LIT> <EOL> return ( sec , usec ) <EOL> packet = Struct ( "<STR_LIT>" , <EOL> MicrosecAdapter ( <EOL> Sequence ( "<STR_LIT:time>" , <EOL> ULInt32 ( "<STR_LIT:time>" ) , <EOL> ULInt32 ( "<STR_LIT>" ) , <EOL> ) <EOL> ) , <EOL> ULInt32 ( "<STR_LIT>" ) , <EOL> Padding ( <NUM_LIT:4> ) , <EOL> HexDumpAdapter ( Field ( "<STR_LIT:data>" , lambda ctx : ctx . length ) ) , <EOL> ) <EOL> cap_file = Struct ( "<STR_LIT>" , <EOL> Padding ( <NUM_LIT> ) , <EOL> Rename ( "<STR_LIT>" , OptionalGreedyRange ( packet ) ) , <EOL> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> obj = cap_file . parse_stream ( open ( "<STR_LIT>" , "<STR_LIT:rb>" ) ) <EOL> print len ( obj . packets ) </s>
