<s> from __future__ import print_function <EOL> import argparse <EOL> import signal <EOL> import sys <EOL> from thrift . protocol . TBinaryProtocol import TBinaryProtocol <EOL> from thrift . protocol . TCompactProtocol import TCompactProtocol <EOL> from thrift . protocol . TJSONProtocol import TJSONProtocol <EOL> from . message_sniffer import MessageSnifferOptions , MessageSniffer <EOL> from . printer import FormatOptions , LatencyPrinter , PairedPrinter , Printer <EOL> VALID_PROTOCOLS = '<STR_LIT>' <EOL> def get_flags ( ) : <EOL> p = argparse . ArgumentParser ( <EOL> formatter_class = argparse . ArgumentDefaultsHelpFormatter ) <EOL> p . add_argument ( '<STR_LIT>' , type = str , default = '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT> , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT:20> * <NUM_LIT> , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT:10> * <NUM_LIT> , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , type = str , nargs = '<STR_LIT:+>' , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , type = str , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> p . add_argument ( '<STR_LIT>' , type = str , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' % <EOL> VALID_PROTOCOLS ) <EOL> cmds = p . add_subparsers ( dest = '<STR_LIT>' ) <EOL> dump = cmds . add_parser ( '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> dump . add_argument ( '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> stats = cmds . add_parser ( '<STR_LIT>' ) <EOL> stats . add_argument ( '<STR_LIT>' , type = int , default = <NUM_LIT:0> , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return p . parse_args ( ) <EOL> def main ( ) : <EOL> flags = get_flags ( ) <EOL> if flags . cmd == '<STR_LIT>' : <EOL> printer = LatencyPrinter ( expected_calls = flags . count ) <EOL> read_values = False <EOL> elif flags . cmd == '<STR_LIT>' : <EOL> printer_cls = Printer if flags . unpaired else PairedPrinter <EOL> format_opts = FormatOptions ( <EOL> flags . pretty , <EOL> flags . color , <EOL> flags . show_header or flags . show_all , <EOL> flags . show_fields or flags . show_all , <EOL> flags . json , <EOL> ) <EOL> printer = printer_cls ( format_opts ) <EOL> read_values = flags . show_values or flags . show_all <EOL> else : <EOL> print ( '<STR_LIT>' % flags . cmd ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if flags . protocol == '<STR_LIT>' : <EOL> protocol = None <EOL> elif flags . protocol == '<STR_LIT>' : <EOL> protocol = TBinaryProtocol <EOL> elif flags . protocol == '<STR_LIT>' : <EOL> protocol = TCompactProtocol <EOL> elif flags . protocol == '<STR_LIT>' : <EOL> protocol = TJSONProtocol <EOL> else : <EOL> print ( '<STR_LIT>' % flags . protocol ) <EOL> print ( '<STR_LIT>' % VALID_PROTOCOLS ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> options = MessageSnifferOptions ( <EOL> iface = flags . iface , <EOL> port = flags . port , <EOL> ip = flags . ip , <EOL> pcap_file = flags . pcap_file , <EOL> protocol = protocol , <EOL> finagle_thrift = flags . finagle_thrift , <EOL> read_values = read_values , <EOL> max_queued = flags . max_queued , <EOL> max_message_size = flags . max_message_size , <EOL> debug = flags . debug <EOL> ) <EOL> message_sniffer = MessageSniffer ( options , printer ) <EOL> def sigusr_handler ( * args ) : <EOL> print ( '<STR_LIT>' % message_sniffer . status ( ) , <EOL> file = sys . stderr ) <EOL> signal . signal ( signal . SIGUSR1 , sigusr_handler ) <EOL> try : <EOL> while message_sniffer . isAlive ( ) : <EOL> message_sniffer . join ( <NUM_LIT:1> ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> pass <EOL> finally : <EOL> message_sniffer . stop ( wait_for_stopped = True ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
