<s> import sys <EOL> import io <EOL> import linecache <EOL> import time <EOL> import socket <EOL> import traceback <EOL> import thread <EOL> import threading <EOL> import Queue <EOL> from idlelib import CallTips <EOL> from idlelib import AutoComplete <EOL> from idlelib import RemoteDebugger <EOL> from idlelib import RemoteObjectBrowser <EOL> from idlelib import StackViewer <EOL> from idlelib import rpc <EOL> from idlelib import PyShell <EOL> from idlelib import IOBinding <EOL> import __main__ <EOL> LOCALHOST = '<STR_LIT:127.0.0.1>' <EOL> import warnings <EOL> def idle_showwarning_subproc ( <EOL> message , category , filename , lineno , file = None , line = None ) : <EOL> """<STR_LIT>""" <EOL> if file is None : <EOL> file = sys . stderr <EOL> try : <EOL> file . write ( PyShell . idle_formatwarning ( <EOL> message , category , filename , lineno , line ) ) <EOL> except IOError : <EOL> pass <EOL> _warnings_showwarning = None <EOL> def capture_warnings ( capture ) : <EOL> "<STR_LIT>" <EOL> global _warnings_showwarning <EOL> if capture : <EOL> if _warnings_showwarning is None : <EOL> _warnings_showwarning = warnings . showwarning <EOL> warnings . showwarning = idle_showwarning_subproc <EOL> else : <EOL> if _warnings_showwarning is not None : <EOL> warnings . showwarning = _warnings_showwarning <EOL> _warnings_showwarning = None <EOL> capture_warnings ( True ) <EOL> exit_now = False <EOL> quitting = False <EOL> interruptable = False <EOL> def main ( del_exitfunc = False ) : <EOL> """<STR_LIT>""" <EOL> global exit_now <EOL> global quitting <EOL> global no_exitfunc <EOL> no_exitfunc = del_exitfunc <EOL> try : <EOL> assert ( len ( sys . argv ) > <NUM_LIT:1> ) <EOL> port = int ( sys . argv [ - <NUM_LIT:1> ] ) <EOL> except : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> return <EOL> capture_warnings ( True ) <EOL> sys . argv [ : ] = [ "<STR_LIT>" ] <EOL> sockthread = threading . Thread ( target = manage_socket , <EOL> name = '<STR_LIT>' , <EOL> args = ( ( LOCALHOST , port ) , ) ) <EOL> sockthread . setDaemon ( True ) <EOL> sockthread . start ( ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> if exit_now : <EOL> try : <EOL> exit ( ) <EOL> except KeyboardInterrupt : <EOL> continue <EOL> try : <EOL> seq , request = rpc . request_queue . get ( block = True , timeout = <NUM_LIT> ) <EOL> except Queue . Empty : <EOL> continue <EOL> method , args , kwargs = request <EOL> ret = method ( * args , ** kwargs ) <EOL> rpc . response_queue . put ( ( seq , ret ) ) <EOL> except KeyboardInterrupt : <EOL> if quitting : <EOL> exit_now = True <EOL> continue <EOL> except SystemExit : <EOL> capture_warnings ( False ) <EOL> raise <EOL> except : <EOL> type , value , tb = sys . exc_info ( ) <EOL> try : <EOL> print_exception ( ) <EOL> rpc . response_queue . put ( ( seq , None ) ) <EOL> except : <EOL> traceback . print_exception ( type , value , tb , file = sys . __stderr__ ) <EOL> exit ( ) <EOL> else : <EOL> continue <EOL> def manage_socket ( address ) : <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> time . sleep ( i ) <EOL> try : <EOL> server = MyRPCServer ( address , MyHandler ) <EOL> break <EOL> except socket . error as err : <EOL> print >> sys . __stderr__ , "<STR_LIT>" + err . args [ <NUM_LIT:1> ] + "<STR_LIT>" <EOL> else : <EOL> print >> sys . __stderr__ , "<STR_LIT>" "<STR_LIT>" <EOL> show_socket_error ( err , address ) <EOL> global exit_now <EOL> exit_now = True <EOL> return <EOL> server . handle_request ( ) <EOL> def show_socket_error ( err , address ) : <EOL> import Tkinter <EOL> import tkMessageBox <EOL> root = Tkinter . Tk ( ) <EOL> root . withdraw ( ) <EOL> if err . args [ <NUM_LIT:0> ] == <NUM_LIT> : <EOL> msg = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % address <EOL> tkMessageBox . showerror ( "<STR_LIT>" , msg , parent = root ) <EOL> else : <EOL> tkMessageBox . showerror ( "<STR_LIT>" , <EOL> "<STR_LIT>" % err . args [ <NUM_LIT:1> ] ) <EOL> root . destroy ( ) <EOL> def print_exception ( ) : <EOL> import linecache <EOL> linecache . checkcache ( ) <EOL> flush_stdout ( ) <EOL> efile = sys . stderr <EOL> typ , val , tb = excinfo = sys . exc_info ( ) <EOL> sys . last_type , sys . last_value , sys . last_traceback = excinfo <EOL> tbe = traceback . extract_tb ( tb ) <EOL> print >> efile , '<STR_LIT>' <EOL> exclude = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> cleanup_traceback ( tbe , exclude ) <EOL> traceback . print_list ( tbe , file = efile ) <EOL> lines = traceback . format_exception_only ( typ , val ) <EOL> for line in lines : <EOL> print >> efile , line , <EOL> def cleanup_traceback ( tb , exclude ) : <EOL> "<STR_LIT>" <EOL> orig_tb = tb [ : ] <EOL> while tb : <EOL> for rpcfile in exclude : <EOL> if tb [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . count ( rpcfile ) : <EOL> break <EOL> else : <EOL> break <EOL> del tb [ <NUM_LIT:0> ] <EOL> while tb : <EOL> for rpcfile in exclude : <EOL> if tb [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] . count ( rpcfile ) : <EOL> break <EOL> else : <EOL> break <EOL> del tb [ - <NUM_LIT:1> ] <EOL> if len ( tb ) == <NUM_LIT:0> : <EOL> tb [ : ] = orig_tb [ : ] <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> rpchandler = rpc . objecttable [ '<STR_LIT>' ] . rpchandler <EOL> for i in range ( len ( tb ) ) : <EOL> fn , ln , nm , line = tb [ i ] <EOL> if nm == '<STR_LIT:?>' : <EOL> nm = "<STR_LIT>" <EOL> if not line and fn . startswith ( "<STR_LIT>" ) : <EOL> line = rpchandler . remotecall ( '<STR_LIT>' , '<STR_LIT>' , <EOL> ( fn , ln ) , { } ) <EOL> tb [ i ] = fn , ln , nm , line <EOL> def flush_stdout ( ) : <EOL> try : <EOL> if sys . stdout . softspace : <EOL> sys . stdout . softspace = <NUM_LIT:0> <EOL> sys . stdout . write ( "<STR_LIT:\n>" ) <EOL> except ( AttributeError , EOFError ) : <EOL> pass <EOL> def exit ( ) : <EOL> """<STR_LIT>""" <EOL> if no_exitfunc : <EOL> try : <EOL> del sys . exitfunc <EOL> except AttributeError : <EOL> pass <EOL> capture_warnings ( False ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> class MyRPCServer ( rpc . RPCServer ) : <EOL> def handle_error ( self , request , client_address ) : <EOL> """<STR_LIT>""" <EOL> global quitting <EOL> try : <EOL> raise <EOL> except SystemExit : <EOL> raise <EOL> except EOFError : <EOL> global exit_now <EOL> exit_now = True <EOL> thread . interrupt_main ( ) <EOL> except : <EOL> erf = sys . __stderr__ <EOL> print >> erf , '<STR_LIT:\n>' + '<STR_LIT:->' * <NUM_LIT> <EOL> print >> erf , '<STR_LIT>' <EOL> print >> erf , '<STR_LIT>' % threading . currentThread ( ) . getName ( ) <EOL> print >> erf , '<STR_LIT>' , client_address <EOL> print >> erf , '<STR_LIT>' , repr ( request ) <EOL> traceback . print_exc ( file = erf ) <EOL> print >> erf , '<STR_LIT>' <EOL> print >> erf , '<STR_LIT:->' * <NUM_LIT> <EOL> quitting = True <EOL> thread . interrupt_main ( ) <EOL> class MyHandler ( rpc . RPCHandler ) : <EOL> def handle ( self ) : <EOL> """<STR_LIT>""" <EOL> executive = Executive ( self ) <EOL> self . register ( "<STR_LIT>" , executive ) <EOL> self . console = self . get_remote_proxy ( "<STR_LIT>" ) <EOL> sys . stdin = PyShell . PseudoInputFile ( self . console , "<STR_LIT>" , <EOL> IOBinding . encoding ) <EOL> sys . stdout = PyShell . PseudoOutputFile ( self . console , "<STR_LIT>" , <EOL> IOBinding . encoding ) <EOL> sys . stderr = PyShell . PseudoOutputFile ( self . console , "<STR_LIT>" , <EOL> IOBinding . encoding ) <EOL> self . _keep_stdin = sys . stdin <EOL> self . interp = self . get_remote_proxy ( "<STR_LIT>" ) <EOL> rpc . RPCHandler . getresponse ( self , myseq = None , wait = <NUM_LIT> ) <EOL> def exithook ( self ) : <EOL> "<STR_LIT>" <EOL> time . sleep ( <NUM_LIT:10> ) <EOL> def EOFhook ( self ) : <EOL> "<STR_LIT>" <EOL> global quitting <EOL> quitting = True <EOL> thread . interrupt_main ( ) <EOL> def decode_interrupthook ( self ) : <EOL> "<STR_LIT>" <EOL> global quitting <EOL> quitting = True <EOL> thread . interrupt_main ( ) <EOL> class Executive ( object ) : <EOL> def __init__ ( self , rpchandler ) : <EOL> self . rpchandler = rpchandler <EOL> self . locals = __main__ . __dict__ <EOL> self . calltip = CallTips . CallTips ( ) <EOL> self . autocomplete = AutoComplete . AutoComplete ( ) <EOL> def runcode ( self , code ) : <EOL> global interruptable <EOL> try : <EOL> self . usr_exc_info = None <EOL> interruptable = True <EOL> try : <EOL> exec code in self . locals <EOL> finally : <EOL> interruptable = False <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> self . usr_exc_info = sys . exc_info ( ) <EOL> if quitting : <EOL> exit ( ) <EOL> print_exception ( ) <EOL> jit = self . rpchandler . console . getvar ( "<STR_LIT>" ) <EOL> if jit : <EOL> self . rpchandler . interp . open_remote_stack_viewer ( ) <EOL> else : <EOL> flush_stdout ( ) <EOL> def interrupt_the_server ( self ) : <EOL> if interruptable : <EOL> thread . interrupt_main ( ) <EOL> def start_the_debugger ( self , gui_adap_oid ) : <EOL> return RemoteDebugger . start_debugger ( self . rpchandler , gui_adap_oid ) <EOL> def stop_the_debugger ( self , idb_adap_oid ) : <EOL> "<STR_LIT>" <EOL> self . rpchandler . unregister ( idb_adap_oid ) <EOL> def get_the_calltip ( self , name ) : <EOL> return self . calltip . fetch_tip ( name ) <EOL> def get_the_completion_list ( self , what , mode ) : <EOL> return self . autocomplete . fetch_completions ( what , mode ) <EOL> def stackviewer ( self , flist_oid = None ) : <EOL> if self . usr_exc_info : <EOL> typ , val , tb = self . usr_exc_info <EOL> else : <EOL> return None <EOL> flist = None <EOL> if flist_oid is not None : <EOL> flist = self . rpchandler . get_remote_proxy ( flist_oid ) <EOL> while tb and tb . tb_frame . f_globals [ "<STR_LIT>" ] in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> tb = tb . tb_next <EOL> sys . last_type = typ <EOL> sys . last_value = val <EOL> item = StackViewer . StackTreeItem ( flist , tb ) <EOL> return RemoteObjectBrowser . remote_object_tree_item ( item ) <EOL> capture_warnings ( False ) </s>
