
Ic           @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k	 Z	 d  d k
 Z
 d  d k Z d  d k Z d  d k Z d  d k Z d Z y d  d k Z Wn e j
 o n Xd d d  Z e e _ e a e a e a e d  Z d   Z d   Z d   Z d   Z d	   Z d
   Z d e i  f d     YZ! d e i" f d     YZ# d e$ f d     YZ% d S(   iNs	   127.0.0.1c         C   sz   d } | d | | f 7} | d j o t i | |  i   n | } | o | d | 7} n | d | i |  f 7} | S(   s   Format warnings the IDLE ways!   
Warning (from warnings module):
s     File "%s", line %s
s       %s
s   %s: %s
N(   t   Nonet	   linecachet   getlinet   stript   __name__(   t   messaget   categoryt   filenamet   linenot   filet   linet   s(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   idle_formatwarning_subproc   s    ,c         C   s  |  a  d } t i d o t t i d  } n d g t i (t i d t d d d t | f f  } | i t	  | i
   xVy t o( y t   Wq t j
 o
 w q Xn y% t i i d t	 d	 d
  \ } } Wn t i j
 o
 w n X| \ } } } | | |   } t i i | | f  Wq t j
 o t o
 t	 a q q q t j
 o
   q t i   \ }	 }
 } y! t   t i i | d f  Wq t i |	 |
 | d t i t   qXq q Xq d S(   sj  Start the Python execution server in a subprocess

    In the Python subprocess, RPCServer is instantiated with handlerclass
    MyHandler, which inherits register/unregister methods from RPCHandler via
    the mix-in class SocketIO.

    When the RPCServer 'server' is instantiated, the TCPServer initialization
    creates an instance of run.MyHandler and calls its handle() method.
    handle() instantiates a run.Executive object, passing it a reference to the
    MyHandler object.  That reference is saved as attribute rpchandler of the
    Executive instance.  The Executive methods have access to the reference and
    can pass it on to entities that they command
    (e.g. RemoteDebugger.Debugger.start_debugger()).  The latter, in turn, can
    call MyHandler(SocketIO) register/unregister methods via the reference to
    register and unregister themselves.

    i"  i   t    t   targett   namet
   SockThreadt   argst   blockt   timeoutg?R	   N(   t   no_exitfunct   syst   argvt   intt	   threadingt   Threadt   manage_sockett	   LOCALHOSTt	   setDaemont   Truet   startt   exit_nowt   exitt   KeyboardInterruptt   rpct   request_queuet   gett   Queuet   Emptyt   response_queuet   putt   quittingt
   SystemExitt   exc_infot   print_exceptionR    t	   tracebackt
   __stderr__(   t   del_exitfunct   portt
   sockthreadt   seqt   requestt   methodR   t   kwargst   rett   typet   valuet   tb(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   main0   sN    
%
c         C   s   x t  d  D][ } t i |  y t |  t  } PWq t i j
 o" } t i d | d d IJq Xq Wt i d IJt	 | |   t
 a d  S| i   d  S(   Ni   s   IDLE Subprocess: socket error: i   s   , retrying....s8   IDLE Subprocess: Connection to IDLE GUI failed, exiting.(   t   ranget   timet   sleept   MyRPCServert	   MyHandlert   sockett   errorR   R.   t   show_socket_errorR   R   t   handle_request(   t   addresst   it   servert   err(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyR   q   s     c         C   s   d d  k  } d d  k } | i   } | i   |  d d j o$ d | } | i d | d | n | i d d |  d  | i   d  S(	   Nii    i=   s   IDLE's subprocess can't connect to %s:%d.  This may be due to your personal firewall configuration.  It is safe to allow this internal connection because no data is visible on external ports.s   IDLE Subprocess Errort   parents   Socket Error: %si   (   t   Tkintert   tkMessageBoxt   Tkt   withdrawt	   showerrort   destroy(   RG   RD   RI   RJ   t   roott   msg(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyRB      s    
c    
      C   s   d d  k  }  |  i   t   t i } t i   \ } } } } | \ t _ t _ t _ t	 i
 |  } | d IJd
 } t | |  t	 i | d	 | t	 i | |  } x | D] }	 | |	 Iq Wd  S(   Nis#   
Traceback (most recent call last):s   run.pys   rpc.pys   threading.pys   Queue.pys   RemoteDebugger.pys   bdb.pyR	   (   s   run.pys   rpc.pys   threading.pys   Queue.pys   RemoteDebugger.pys   bdb.py(   R   t
   checkcachet   flush_stdoutR   t   stderrR+   t	   last_typet
   last_valuet   last_tracebackR-   t
   extract_tbt   cleanup_tracebackt
   print_listt   format_exception_only(
   R   t   efilet   typt   valR9   t   excinfot   tbet   excludet   linesR
   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyR,      s     
	
  c   
      C   sk  |  } xB |  o: x, | D]# } |  d d i  |  o Pq q WP|  d =q
 WxB |  o: x, | D]# } |  d d i  |  o Pq] q] WP|  d =qO Wt |   d j o | |  (t i d IJn t i d i } x t t |    D] } |  | \ } } } }	 | d j o
 d } n |	 o2 | i d  o" | i	 d d	 | | f h   }	 n | | | |	 f |  | <q Wd
 S(   sA   Remove excluded traces from beginning/end of tb; get cached linesi    is   ** IDLE Internal Exception: t   exect   ?s
   -toplevel-s	   <pyshell#R   R   N(
   t   countt   lenR   RS   R"   t   objecttablet
   rpchandlerR;   t
   startswitht
   remotecall(
   R9   R`   t   orig_tbt   rpcfileRg   RE   t   fnt   lnt   nmR
   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyRX      s<      	  	 
c           C   sQ   y1 t  i i o  d t  i _ t  i i d  n Wn t t f j
 o n Xd  S(   Ni    s   
(   R   t   stdoutt	   softspacet   writet   AttributeErrort   EOFError(    (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyRR      s    c           C   s<   t  o$ y
 t ` Wq+ t j
 o q+ Xn t i d  d S(   s   Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    i    N(   R   R   t   exitfuncRr   R    (    (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyR       s    
	R>   c           B   s   e  Z d    Z RS(   c         C   s   y   Wn t  j
 o
   n t j
 o t a t i   n t i } | d d d IJ| d IJ| d t i	   i
   IJ| d I| IJ| d It |  IJt i d |  | d	 IJ| d d IJt a t i   n Xd
 S(   sr   Override RPCServer method for IDLE

        Interrupt the MainThread and exit server if link is dropped.

        s   
t   -i(   s   Unhandled server exception!s
   Thread: %ss   Client Address: s	   Request: R	   s#   
*** Unrecoverable, server exiting!N(   R*   Rs   R   R   t   threadt   interrupt_mainR   R.   R   t   currentThreadt   getNamet   reprR-   t	   print_excR)   (   t   selfR3   t   client_addresst   erf(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   handle_error   s&    	

(   R   t
   __module__R   (    (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyR>      s   R?   c           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   t  |   } |  i d |  |  i d  t _ |  _ |  i d  t _ |  i d  t _ d d k } | i	 t i _	 t i _	 t i _	 |  i d  |  _
 t i i |  d d d	 d
 d S(   s   Override base methodRb   t   stdinRo   RS   iNt   interpt   myseqt   waitg?(   t	   Executivet   registert   get_remote_proxyR   R   t   consoleRo   RS   t	   IOBindingt   encodingR   R"   t
   RPCHandlert   getresponseR    (   R|   t	   executiveR   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   handle   s    #c         C   s   t  i d  d S(   s>   override SocketIO method - wait for MainThread to shut us downi
   N(   R<   R=   (   R|   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   exithook  s    c         C   s   t  a t i   d S(   sE   Override SocketIO method - terminate wait on callback and exit threadN(   R   R)   Rv   Rw   (   R|   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   EOFhook
  s    c         C   s   t  a t i   d S(   s   interrupt awakened threadN(   R   R)   Rv   Rw   (   R|   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   decode_interrupthook  s    (   R   R   R   R   R   R   (    (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyR?      s   			R   c           B   sS   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z
 RS(	   c         C   s7   | |  _  t i |  _ t i   |  _ t i   |  _ d  S(   N(   Rg   t   __main__t   __dict__t   localst   CallTipst   calltipt   AutoCompletet   autocomplete(   R|   Rg   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   __init__  s    	c      	   B   s   y, d  |  _ e a z | |  i UWd  e a XWn_ e i   |  _ e o e	   n e
   |  i i i d  } | o |  i i i   q n Xe   d  S(   Ns   <<toggle-jit-stack-viewer>>(   R    t   usr_exc_infoR   t   interruptableR   t   FalseR   R+   R)   R    R,   Rg   R   t   getvarR   t   open_remote_stack_viewerRR   (   R|   t   codet   jit(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   runcode  s    	c         C   s   t  o t i   n d  S(   N(   R   Rv   Rw   (   R|   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   interrupt_the_server4  s    c         C   s   t  i |  i |  S(   N(   t   RemoteDebuggert   start_debuggerRg   (   R|   t   gui_adap_oid(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   start_the_debugger8  s    c         C   s   |  i  i |  d S(   sD   Unregister the Idb Adapter.  Link objects and Idb then subject to GCN(   Rg   t
   unregister(   R|   t   idb_adap_oid(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   stop_the_debugger;  s    c         C   s   |  i  i |  S(   N(   R   t	   fetch_tip(   R|   R   (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   get_the_calltip?  s    c         C   s   |  i  i | |  S(   N(   R   t   fetch_completions(   R|   t   whatt   mode(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   get_the_completion_listB  s    c         C   s   |  i  o |  i  \ } } } n d  Sd  } | d  j	 o |  i i |  } n x, | o$ | i i d d j o | i } qP W| t _ | t _	 t
 i | |  } t i |  S(   NR   R"   t   run(   s   rpcs   run(   R   R    Rg   R   t   tb_framet	   f_globalst   tb_nextR   RT   RU   t   StackViewert   StackTreeItemt   RemoteObjectBrowsert   remote_object_tree_item(   R|   t	   flist_oidR\   R]   R9   t   flistt   item(    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   stackviewerE  s    
 		N(   R   R   R   R   R   R   R   R   R   R    R   (    (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyR     s   							(&   R   R   R<   R@   R-   Rv   R   R%   R   R   R   R   R   R"   R   R   t   warningst   ImportErrorR    R   t   formatwarningR   R   R)   R   R:   R   RB   R,   RX   RR   R    t	   RPCServerR>   R   R?   t   objectR   (    (    (    s-   C:\graphics\Tools\python26\lib\idlelib\run.pyt   <module>   sD   
	A						 