<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import datetime <EOL> import os <EOL> import Queue <EOL> import sys <EOL> import threading <EOL> import tkFont <EOL> from Tkinter import * <EOL> import tkMessageBox <EOL> import traceback <EOL> import addr_util <EOL> import base_ui <EOL> import conn_quality <EOL> import nameserver_list <EOL> import sys_nameservers <EOL> import util <EOL> THREAD_UNSAFE_TK = <NUM_LIT:0> <EOL> LOG_FILE_PATH = util . GenerateOutputFilename ( '<STR_LIT>' ) <EOL> def closedWindowHandler ( ) : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> global_message_queue = Queue . Queue ( ) <EOL> global_last_message = None <EOL> def AddMsg ( message , master = None , backup_notifier = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> global global_message_queue <EOL> global global_last_message <EOL> global THREAD_UNSAFE_TK <EOL> new_message = StatusMessage ( message , ** kwargs ) <EOL> if new_message != global_last_message : <EOL> global_message_queue . put ( new_message ) <EOL> if master : <EOL> try : <EOL> master . event_generate ( '<STR_LIT>' , when = '<STR_LIT>' ) <EOL> global_last_message = new_message <EOL> except TclError : <EOL> if not THREAD_UNSAFE_TK : <EOL> print '<STR_LIT>' <EOL> traceback . print_exc ( ) <EOL> try : <EOL> backup_notifier ( - <NUM_LIT:1> ) <EOL> THREAD_UNSAFE_TK = <NUM_LIT:1> <EOL> except : <EOL> print '<STR_LIT>' <EOL> traceback . print_exc ( ) <EOL> class StatusMessage ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , message , error = False , count = False , total = False , <EOL> enable_button = None , debug = False ) : <EOL> self . message = message <EOL> self . error = error <EOL> self . count = count <EOL> self . debug = debug <EOL> self . total = total <EOL> self . enable_button = enable_button <EOL> class WorkerThread ( threading . Thread , base_ui . BaseUI ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , supplied_ns , global_ns , regional_ns , options , data_source = None , master = None , <EOL> backup_notifier = None ) : <EOL> threading . Thread . __init__ ( self ) <EOL> self . SetupDataStructures ( ) <EOL> self . status_callback = self . msg <EOL> self . data_src = data_source <EOL> self . backup_notifier = backup_notifier <EOL> self . include_internal = False <EOL> self . supplied_ns = supplied_ns <EOL> self . global_ns = global_ns <EOL> self . regional_ns = regional_ns <EOL> self . master = master <EOL> self . options = options <EOL> self . resource_dir = os . path . dirname ( os . path . dirname ( __file__ ) ) <EOL> def msg ( self , message , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return AddMsg ( message , master = self . master , backup_notifier = self . backup_notifier , ** kwargs ) <EOL> def run ( self ) : <EOL> self . msg ( '<STR_LIT>' , enable_button = False ) <EOL> try : <EOL> self . PrepareTestRecords ( ) <EOL> self . PrepareNameServers ( ) <EOL> self . PrepareBenchmark ( ) <EOL> self . RunAndOpenReports ( ) <EOL> except nameserver_list . OutgoingUdpInterception : <EOL> ( exc_type , exception , tb ) = sys . exc_info ( ) <EOL> self . msg ( '<STR_LIT>' , error = exception ) <EOL> except nameserver_list . TooFewNameservers : <EOL> ( exc_type , exception , tb ) = sys . exc_info ( ) <EOL> self . msg ( '<STR_LIT>' , error = exception ) <EOL> except conn_quality . OfflineConnection : <EOL> ( exc_type , exception , tb ) = sys . exc_info ( ) <EOL> self . msg ( '<STR_LIT>' , error = exception ) <EOL> except : <EOL> ( exc_type , exception , tb ) = sys . exc_info ( ) <EOL> traceback . print_exc ( tb ) <EOL> error_msg = '<STR_LIT:\n>' . join ( traceback . format_tb ( tb ) [ - <NUM_LIT:4> : ] ) <EOL> self . msg ( exception , error = error_msg ) <EOL> self . msg ( None , enable_button = True ) <EOL> class NameBenchGui ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , options , supplied_ns , global_ns , regional_ns , version = None ) : <EOL> self . options = options <EOL> self . supplied_ns = supplied_ns <EOL> self . global_ns = global_ns <EOL> self . regional_ns = regional_ns <EOL> self . version = version <EOL> def Execute ( self ) : <EOL> self . root = Tk ( ) <EOL> app = MainWindow ( self . root , self . options , self . supplied_ns , self . global_ns , <EOL> self . regional_ns , self . version ) <EOL> app . DrawWindow ( ) <EOL> self . root . bind ( '<STR_LIT>' , app . MessageHandler ) <EOL> self . root . mainloop ( ) <EOL> class MainWindow ( Frame , base_ui . BaseUI ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , master , options , supplied_ns , global_ns , regional_ns , version = None ) : <EOL> """<STR_LIT>""" <EOL> Frame . __init__ ( self ) <EOL> self . SetupDataStructures ( ) <EOL> self . master = master <EOL> self . options = options <EOL> self . supplied_ns = supplied_ns <EOL> self . global_ns = global_ns <EOL> self . regional_ns = regional_ns <EOL> self . version = version <EOL> try : <EOL> self . log_file = open ( LOG_FILE_PATH , '<STR_LIT:w>' ) <EOL> except : <EOL> print '<STR_LIT>' % LOG_FILE_PATH <EOL> self . master . protocol ( '<STR_LIT>' , closedWindowHandler ) <EOL> def UpdateStatus ( self , message , count = None , total = None , error = None , debug = False ) : <EOL> """<STR_LIT>""" <EOL> if not message : <EOL> return None <EOL> if total : <EOL> state = '<STR_LIT>' % ( message , count , total ) <EOL> elif count : <EOL> state = '<STR_LIT>' % ( message , '<STR_LIT:.>' * count ) <EOL> else : <EOL> state = message <EOL> print '<STR_LIT>' % str ( state ) <EOL> try : <EOL> self . log_file . write ( '<STR_LIT>' % ( datetime . datetime . now ( ) , state ) ) <EOL> self . log_file . flush ( ) <EOL> except : <EOL> pass <EOL> if not debug : <EOL> self . status . set ( state [ <NUM_LIT:0> : <NUM_LIT> ] ) <EOL> def DrawWindow ( self ) : <EOL> """<STR_LIT>""" <EOL> self . nameserver_form = StringVar ( ) <EOL> self . status = StringVar ( ) <EOL> self . query_count = IntVar ( ) <EOL> self . data_source = StringVar ( ) <EOL> self . health_performance = StringVar ( ) <EOL> self . location = StringVar ( ) <EOL> self . use_global = IntVar ( ) <EOL> self . use_regional = IntVar ( ) <EOL> self . use_censor_checks = IntVar ( ) <EOL> self . share_results = IntVar ( ) <EOL> self . master . title ( '<STR_LIT>' ) <EOL> outer_frame = Frame ( self . master ) <EOL> outer_frame . grid ( row = <NUM_LIT:0> , padx = <NUM_LIT:16> , pady = <NUM_LIT:16> ) <EOL> inner_frame = Frame ( outer_frame , relief = GROOVE , bd = <NUM_LIT:2> , padx = <NUM_LIT:12> , pady = <NUM_LIT:12> ) <EOL> inner_frame . grid ( row = <NUM_LIT:0> , columnspan = <NUM_LIT:2> ) <EOL> status = Label ( outer_frame , text = '<STR_LIT>' , textvariable = self . status ) <EOL> status . grid ( row = <NUM_LIT:15> , sticky = W , column = <NUM_LIT:0> ) <EOL> if sys . platform [ : <NUM_LIT:3> ] == '<STR_LIT>' : <EOL> seperator_width = <NUM_LIT> <EOL> else : <EOL> seperator_width = <NUM_LIT> <EOL> bold_font = tkFont . Font ( font = status [ '<STR_LIT>' ] ) <EOL> bold_font [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ns_label = Label ( inner_frame , text = '<STR_LIT>' ) <EOL> ns_label . grid ( row = <NUM_LIT:0> , columnspan = <NUM_LIT:2> , sticky = W ) <EOL> ns_label [ '<STR_LIT>' ] = bold_font <EOL> nameservers = Entry ( inner_frame , bg = '<STR_LIT>' , <EOL> textvariable = self . nameserver_form , <EOL> width = <NUM_LIT> ) <EOL> nameservers . grid ( row = <NUM_LIT:1> , columnspan = <NUM_LIT:2> , sticky = W , padx = <NUM_LIT:4> , pady = <NUM_LIT:2> ) <EOL> self . nameserver_form . set ( '<STR_LIT:U+002CU+0020>' . join ( nameserver_list . InternalNameServers ( ) ) ) <EOL> global_button = Checkbutton ( inner_frame , <EOL> text = '<STR_LIT>' , <EOL> variable = self . use_global ) <EOL> global_button . grid ( row = <NUM_LIT:2> , columnspan = <NUM_LIT:2> , sticky = W ) <EOL> global_button . toggle ( ) <EOL> regional_button = Checkbutton ( inner_frame , <EOL> text = '<STR_LIT>' , <EOL> variable = self . use_regional ) <EOL> regional_button . grid ( row = <NUM_LIT:3> , columnspan = <NUM_LIT:2> , sticky = W ) <EOL> regional_button . toggle ( ) <EOL> separator = Frame ( inner_frame , height = <NUM_LIT:2> , width = seperator_width , bd = <NUM_LIT:1> , relief = SUNKEN ) <EOL> separator . grid ( row = <NUM_LIT:4> , padx = <NUM_LIT:5> , pady = <NUM_LIT:5> , columnspan = <NUM_LIT:2> ) <EOL> ds_label = Label ( inner_frame , text = '<STR_LIT>' ) <EOL> ds_label . grid ( row = <NUM_LIT:5> , column = <NUM_LIT:0> , sticky = W ) <EOL> ds_label [ '<STR_LIT>' ] = bold_font <EOL> censorship_button = Checkbutton ( inner_frame , text = '<STR_LIT>' , <EOL> variable = self . use_censor_checks ) <EOL> censorship_button . grid ( row = <NUM_LIT:6> , columnspan = <NUM_LIT:2> , sticky = W ) <EOL> share_button = Checkbutton ( inner_frame , <EOL> text = '<STR_LIT>' , <EOL> variable = self . share_results ) <EOL> try : <EOL> share_button . grid ( row = <NUM_LIT:7> , columnspan = <NUM_LIT:2> , sticky = W , pady = [ <NUM_LIT:0> , <NUM_LIT:10> ] ) <EOL> except TclError : <EOL> share_button . grid ( row = <NUM_LIT:7> , columnspan = <NUM_LIT:2> , sticky = W ) <EOL> loc_label = Label ( inner_frame , text = '<STR_LIT>' ) <EOL> loc_label . grid ( row = <NUM_LIT:10> , column = <NUM_LIT:0> , sticky = W ) <EOL> loc_label [ '<STR_LIT>' ] = bold_font <EOL> run_count_label = Label ( inner_frame , text = '<STR_LIT>' ) <EOL> run_count_label . grid ( row = <NUM_LIT:10> , column = <NUM_LIT:1> , sticky = W ) <EOL> run_count_label [ '<STR_LIT>' ] = bold_font <EOL> self . DiscoverLocation ( ) <EOL> self . LoadDataSources ( ) <EOL> source_titles = self . data_src . ListSourceTitles ( ) <EOL> left_dropdown_width = max ( [ len ( x ) for x in source_titles ] ) - <NUM_LIT:3> <EOL> location_choices = [ self . country , '<STR_LIT>' ] <EOL> location = OptionMenu ( inner_frame , self . location , * location_choices ) <EOL> location . configure ( width = left_dropdown_width ) <EOL> location . grid ( row = <NUM_LIT:11> , column = <NUM_LIT:0> , sticky = W ) <EOL> self . location . set ( location_choices [ <NUM_LIT:0> ] ) <EOL> mode_choices = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> right_dropdown_width = max ( [ len ( x ) for x in mode_choices ] ) - <NUM_LIT:3> <EOL> health_performance = OptionMenu ( inner_frame , self . health_performance , * mode_choices ) <EOL> health_performance . configure ( width = right_dropdown_width ) <EOL> health_performance . grid ( row = <NUM_LIT:11> , column = <NUM_LIT:1> , sticky = W ) <EOL> self . health_performance . set ( mode_choices [ <NUM_LIT:0> ] ) <EOL> ds_label = Label ( inner_frame , text = '<STR_LIT>' ) <EOL> ds_label . grid ( row = <NUM_LIT:12> , column = <NUM_LIT:0> , sticky = W ) <EOL> ds_label [ '<STR_LIT>' ] = bold_font <EOL> numqueries_label = Label ( inner_frame , text = '<STR_LIT>' ) <EOL> numqueries_label . grid ( row = <NUM_LIT:12> , column = <NUM_LIT:1> , sticky = W ) <EOL> numqueries_label [ '<STR_LIT>' ] = bold_font <EOL> data_source = OptionMenu ( inner_frame , self . data_source , * source_titles ) <EOL> data_source . configure ( width = left_dropdown_width ) <EOL> data_source . grid ( row = <NUM_LIT> , column = <NUM_LIT:0> , sticky = W ) <EOL> self . data_source . set ( source_titles [ <NUM_LIT:0> ] ) <EOL> query_count = Entry ( inner_frame , bg = '<STR_LIT>' , textvariable = self . query_count ) <EOL> query_count . grid ( row = <NUM_LIT> , column = <NUM_LIT:1> , sticky = W , padx = <NUM_LIT:4> ) <EOL> query_count . configure ( width = right_dropdown_width + <NUM_LIT:6> ) <EOL> self . query_count . set ( self . options . query_count ) <EOL> self . button = Button ( outer_frame , command = self . StartJob ) <EOL> self . button . grid ( row = <NUM_LIT:15> , sticky = E , column = <NUM_LIT:1> , pady = <NUM_LIT:4> , padx = <NUM_LIT:1> ) <EOL> self . UpdateRunState ( running = True ) <EOL> self . UpdateRunState ( running = False ) <EOL> self . UpdateStatus ( '<STR_LIT>' % self . version ) <EOL> def MessageHandler ( self , unused_event ) : <EOL> """<STR_LIT>""" <EOL> while global_message_queue . qsize ( ) : <EOL> m = global_message_queue . get ( ) <EOL> if m . error : <EOL> self . ErrorPopup ( m . message , m . error ) <EOL> elif m . enable_button == False : <EOL> self . UpdateRunState ( running = True ) <EOL> elif m . enable_button == True : <EOL> self . UpdateRunState ( running = False ) <EOL> self . UpdateStatus ( m . message , count = m . count , total = m . total , error = m . error , debug = m . debug ) <EOL> def ErrorPopup ( self , title , message ) : <EOL> print '<STR_LIT>' % title <EOL> tkMessageBox . showerror ( str ( title ) , str ( message ) , master = self . master ) <EOL> def UpdateRunState ( self , running = True ) : <EOL> """<STR_LIT>""" <EOL> global THREAD_UNSAFE_TK <EOL> if THREAD_UNSAFE_TK : <EOL> return <EOL> if running : <EOL> try : <EOL> self . button . config ( state = DISABLED ) <EOL> self . button . config ( text = '<STR_LIT>' ) <EOL> except TclError : <EOL> THREAD_UNSAFE_TK = True <EOL> self . UpdateStatus ( '<STR_LIT>' ) <EOL> self . UpdateStatus ( '<STR_LIT>' ) <EOL> else : <EOL> try : <EOL> self . button . config ( state = NORMAL ) <EOL> self . button . config ( text = '<STR_LIT>' ) <EOL> except TclError : <EOL> pass <EOL> def StartJob ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ProcessForm ( ) <EOL> thread = WorkerThread ( self . supplied_ns , self . global_ns , self . regional_ns , self . options , <EOL> data_source = self . data_src , <EOL> master = self . master , backup_notifier = self . MessageHandler ) <EOL> thread . start ( ) <EOL> def ProcessForm ( self ) : <EOL> """<STR_LIT>""" <EOL> self . supplied_ns = addr_util . ExtractIPTuplesFromString ( self . nameserver_form . get ( ) ) <EOL> if not self . use_global . get ( ) : <EOL> self . global_ns = [ ] <EOL> if not self . use_regional . get ( ) : <EOL> self . regional_ns = [ ] <EOL> if '<STR_LIT>' in self . health_performance . get ( ) : <EOL> self . options . health_thread_count = <NUM_LIT:10> <EOL> self . options . query_count = self . query_count . get ( ) <EOL> self . options . input_source = self . data_src . ConvertSourceTitleToType ( self . data_source . get ( ) ) <EOL> self . options . enable_censorship_checks = self . use_censor_checks . get ( ) <EOL> self . options . upload_results = self . share_results . get ( ) </s>
