<s> import os <EOL> import sys <EOL> from pyshark . capture . capture import Capture <EOL> if sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> basestring = str <EOL> class FileCapture ( Capture ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , input_file = None , keep_packets = True , display_filter = None , only_summaries = False , <EOL> decryption_key = None , encryption_type = '<STR_LIT>' , decode_as = None , tshark_path = None , <EOL> override_prefs = None ) : <EOL> """<STR_LIT>""" <EOL> super ( FileCapture , self ) . __init__ ( display_filter = display_filter , only_summaries = only_summaries , <EOL> decryption_key = decryption_key , encryption_type = encryption_type , <EOL> decode_as = decode_as , tshark_path = tshark_path , override_prefs = override_prefs ) <EOL> self . input_filename = input_file <EOL> if not isinstance ( input_file , basestring ) : <EOL> self . input_filename = input_file . name <EOL> if not os . path . exists ( self . input_filename ) : <EOL> raise Exception ( '<STR_LIT>' + str ( self . input_filename ) ) <EOL> self . keep_packets = keep_packets <EOL> self . _packet_generator = self . _packets_from_tshark_sync ( ) <EOL> def next ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . keep_packets : <EOL> return self . _packet_generator . send ( None ) <EOL> elif self . current_packet >= len ( self . _packets ) : <EOL> packet = self . _packet_generator . send ( None ) <EOL> self . _packets += [ packet ] <EOL> return super ( FileCapture , self ) . next_packet ( ) <EOL> def __getitem__ ( self , packet_index ) : <EOL> if not self . keep_packets : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> while packet_index >= len ( self . _packets ) : <EOL> try : <EOL> self . next ( ) <EOL> except StopIteration : <EOL> raise KeyError ( '<STR_LIT>' % packet_index ) <EOL> return super ( FileCapture , self ) . __getitem__ ( packet_index ) <EOL> def get_parameters ( self , packet_count = None ) : <EOL> return super ( FileCapture , self ) . get_parameters ( packet_count = packet_count ) + [ '<STR_LIT>' , self . input_filename ] <EOL> def __repr__ ( self ) : <EOL> if self . keep_packets : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . input_filename ) <EOL> else : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . input_filename , len ( self . _packets ) ) </s>
