o
    ǋ|c                  
   @   s,  d dl Z edkre jd e jd< zd dlT W n ey(   ede jd edw e jdkrKzd dl	Z	dZ
e	d	e
 W n eeefyJ   Y nw d d
lmZ edk rte at  d dlmZ et ejdde td edd dlmZ d dlZd dlZd dlZd dlZd dlmZ d dlZd dlZd dl Z d dl!m"Z" d dl#Z#d dl$Z$d dl%Z%d dl&Z&d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl-m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl-m7Z7 d dl-m8Z8 d dlm9Z9m:Z:m;Z; d dl<m=Z= da>d Z?d Z@z
d!ZAeAeB_AeAeC_AW n
 eDy   Y nw e jaE	d@d"d#ZFdaGd$d% ZHeHd& dejIfd'd(ZJeJe_IG d)d* d*e1ZKG d+d, d,e4ZLG d-d. d.e(ZMG d/d0 d0e=ZNG d1d2 d2e,ZOG d3d4 d4e8jPZQd5d6 ZRG d7d8 d8eZSG d9d: d:e6ZTd;d< ZUd=ZVd>d? ZWedkreW  eHd dS )A    N__main__zidlelib.pyshell)*zJ** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **file   win32Zshcore)
messageboxg      !@fix_scalingzIdle Cannot Startz"Idle requires tcl/tk 8.5+, not %s.parent)InteractiveInterpreter)python_version)TextWrapper)ColorDelegator)idleConf)	Delegatordebugger)
debugger_r)EditorWindowfixwordbreaks)FileList)OutputWindow)replace)rpc)idle_formatwarningStdInputFileStdOutputFile)UndoDelegatorFz	127.0.0.1zCtrl-D (end-of-file)c              	   C   sN   |du rt }z|t| ||||d |d W dS  ttfy&   Y dS w )a   Show Idle-format warning (after replacing warnings.showwarning).

    The differences are the formatter called, the file=None replacement,
    which can be None, the capture of the consequence AttributeError,
    and the output of a hard-coded prompt.
    N)linez>>> )warning_streamwriter   AttributeErrorOSError)messagecategoryfilenamelinenor   r     r)   !  /home/conda/feedstock_root/build_artifacts/python-split_1669104742391/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/python3.10/idlelib/pyshell.pyidle_showwarningR   s   
r+   c                 C   s:   | rt du rtja tt_dS dS t durt t_da dS dS )z>Replace warning.showwarning with idle_showwarning, or reverse.N)_warnings_showwarningwarningsshowwarningr+   )capturer)   r)   r*   capture_warningse   s   
r0   Tc                 C   sX   t j}i }t|D ]}|dd |dd  dkr ||||< q	||  || dS )ao  Extend linecache.checkcache to preserve the <pyshell#...> entries

    Rather than repeating the linecache code, patch it to save the
    <pyshell#...> entries, call the original linecache.checkcache()
    (skipping them), and then restore the saved entries.

    orig_checkcache is bound at definition time to the original
    method, allowing it to be patched.
    Nr   <>)	linecachecachelistpopupdate)r'   Zorig_checkcacher4   savekeyr)   r)   r*   extended_linecache_checkcachet   s   r:   c                   @   sv   e Zd ZdZdd Zg dZdddZdd	 ZdddZdddZ	dd Z
dd Zdd Zdd Zdd Zdd Zd
S )PyShellEditorWindowz6Regular text edit window in IDLE, supports breakpointsc                 G   s   g | _ tj| g|R   | jd| j | jd| j | jd| jj t	j
tjd| _| jj| fdd}| j| | jjrE|   |   d S )N<<set-breakpoint-here>><<clear-breakpoint-here>>z<<open-python-shell>>zbreakpoints.lstc                 S   s   |   |   d S N)restore_file_breaks)Zold_hookselfr)   r)   r*   filename_changed_hook      
z;PyShellEditorWindow.__init__.<locals>.filename_changed_hook)breakpointsr   __init__textbindset_breakpoint_hereclear_breakpoint_hereflist
open_shellospathjoinr   ZuserdirbreakpointPathioZfilename_change_hookZset_filename_change_hookr'   r?   color_breakpoint_text)r@   argsrA   r)   r)   r*   rD      s   
zPyShellEditorWindow.__init__))ZCutz<<cut>>rmenu_check_cut)Copyz<<copy>>rmenu_check_copy)ZPastez	<<paste>>rmenu_check_paste)NNN)zSet Breakpointr<   N)zClear Breakpointr=   NTc                 C   sD   | j du rdS |rt }t|d}nddd}| jd| dS )z,Turn colorizing of breakpoint text on or offNbreak )
foreground
backgroundBREAK)rO   r   CurrentThemeGetHighlightrE   Z
tag_config)r@   ZcolorthemeZcfgr)   r)   r*   rP      s   

z)PyShellEditorWindow.color_breakpoint_textc                 C   s   | j }| jj}|dd| d|d   z| j| W n ty+   | j| Y nw z| jj	j
j}||| W d S    Y d S )NrZ   z%d.0r   )rE   rO   r'   tag_addrC   index
ValueErrorappendrI   pyshellinterpr   rG   )r@   r(   rE   r'   debugr)   r)   r*   set_breakpoint   s   z"PyShellEditorWindow.set_breakpointNc                 C   s>   | j }| jj}|s|  d S tt|d}| | d S )Ninsert)rE   rO   r'   bellintfloatr_   re   )r@   eventrE   r'   r(   r)   r)   r*   rG      s   z'PyShellEditorWindow.set_breakpoint_herec                 C   s   | j }| jj}|s|  d S tt|d}z| j| W n   Y |	ddd z| j
jjj}||| W d S    Y d S )Nrf   rZ   insert linestartzinsert lineend +1char)rE   rO   r'   rg   rh   ri   r_   rC   remove
tag_removerI   rb   rc   r   rH   )r@   rj   rE   r'   r(   rd   r)   r)   r*   rH      s$   z)PyShellEditorWindow.clear_breakpoint_herec                 C   sf   | j r1| j}| jj}|s|  d S g | _ |ddt z| jjj	j
}|| W d S    Y d S d S )NrZ   1.0)rC   rE   rO   r'   rg   rm   ZENDrI   rb   rc   r   clear_file_breaks)r@   rE   r'   rd   r)   r)   r*   ro      s   z%PyShellEditorWindow.clear_file_breaksc              
   C   sZ  | j }| jj}zt| jd}| }W d   n1 sw   Y  W n ty.   g }Y nw zKt| jd:}|D ]}||d sG|| q9| 	  | j }|rg||d t
| d  W d   W dS W d   W dS 1 ssw   Y  W dS  ty } z&t| jddsd| j_tjd	d
t
| | jd W Y d}~dS W Y d}~dS d}~ww )z#Save breakpoints when file is savedrNw=
breakpoint_error_displayedFTz
IDLE Errorz$Unable to update breakpoint list:
%s)titler%   r   )rC   rO   r'   openrN   	readlinesr$   
startswithr"   update_breakpointsstrgetattrrootrt   r   	showerrorrE   )r@   Zbreaksr'   fplinesZnew_filer    errr)   r)   r*   store_file_breaks   sF   

&z%PyShellEditorWindow.store_file_breaksc                 C   s   | j   | jd u rd S | jj}|d u rd S tj| jrYt| jd}|	 }W d    n1 s2w   Y  |D ]!}|
|d rXt|t|d d  }|D ]}| | qPq9d S d S )Nrp   rr   r   )rE   r7   rO   r'   rK   rL   isfilerN   rv   rw   rx   evallenre   )r@   r'   r~   r   r    Zbreakpoint_linenumbersZbreakpoint_linenumberr)   r)   r*   r?     s$   


z'PyShellEditorWindow.restore_file_breaksc                 C   s$   | j }|d}| |}|| _dS )z3Retrieves all the breakpoints in the current windowrZ   N)rE   Z
tag_rangesranges_to_linenumbersrC   )r@   rE   rangesZlinenumber_listr)   r)   r*   ry   +  s   


z&PyShellEditorWindow.update_breakpointsc                 C   sh   g }t dt|dD ]'}tt|| j}tt||d  j}||k r1|| |d7 }||k s$q
|S )Nr      r   )ranger   rh   ri   stringra   )r@   r   r   r_   r(   endr)   r)   r*   r   2  s   
z)PyShellEditorWindow.ranges_to_linenumbersc                 C   s   |    t|  dS )z7Extend base method - clear breaks when module is closedN)ro   r   _closer@   r)   r)   r*   r   C  s   zPyShellEditorWindow._close)Tr>   )__name__
__module____qualname____doc__rD   rmenu_specsrP   re   rG   rH   ro   r   r?   ry   r   r   r)   r)   r)   r*   r;      s    
	

	*r;   c                   @   s"   e Zd ZdZeZdZdddZdS )PyShellFileListz8Extend base class: IDLE supports a shell and breakpointsNc                 C   s<   | j r| j j  | j S t| | _ | j r| j  sd S | j S r>   )rb   topwakeupPyShellbeginr@   rj   r)   r)   r*   rJ   R  s   

zPyShellFileList.open_shellr>   )r   r   r   r   r;   r   rb   rJ   r)   r)   r)   r*   r   I  s
    r   c                   @   s    e Zd ZdZdd Zdd ZdS )ModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfc                 C   s*   |  ddd | ddd t|  d S )NZTODOrn   iomarkZSYNC)rm   r^   r   recolorize_mainr   r)   r)   r*   r   _  s   z&ModifiedColorDelegator.recolorize_mainc                 C   s   | j D ]	}| |dd qd S )Nr   r   )Ztagdefsrm   )r@   tagr)   r)   r*   removecolorsd  s   
z#ModifiedColorDelegator.removecolorsN)r   r   r   r   r   r   r)   r)   r)   r*   r   ]  s    r   c                       s4   e Zd ZdZd	ddZd	ddZ fddZ  ZS )
ModifiedUndoDelegatorz;Extend base class: forbid insert/delete before the I/O markNc                 C   sL   z| j |ddr| j   W d S W n	 ty   Y nw t| ||| d S N<r   )delegatecomparerg   TclErrorr   rf   r@   r_   charstagsr)   r)   r*   rf   l  s   
zModifiedUndoDelegator.insertc                 C   sJ   z| j |ddr| j   W d S W n	 ty   Y nw t| || d S r   )r   r   rg   r   r   delete)r@   Zindex1index2r)   r)   r*   r   u  s   
zModifiedUndoDelegator.deletec                    s>   | j j  fdd| j _zt | W  | j _d S  | j _w )Nc                    s    | |dS Nstdinr)   )r_   r   Zorig_insertr)   r*   <lambda>      z2ModifiedUndoDelegator.undo_event.<locals>.<lambda>)r   rf   super
undo_eventr   	__class__r   r*   r   ~  s   
z ModifiedUndoDelegator.undo_eventr>   )r   r   r   r   rf   r   r   __classcell__r)   r)   r   r*   r   j  s
    

		r   c                   @   s   e Zd ZdZdddZdS )UserInputTaggingDelegatorz.Delegator used to tag user input with "stdin".Nc                 C   s    |d u rd}| j ||| d S r   )r   rf   r   r)   r)   r*   rf     s   z UserInputTaggingDelegator.insertr>   )r   r   r   r   rf   r)   r)   r)   r*   r     s    r   c                   @   s   e Zd Zdd ZdS )MyRPCClientc                 C   s   t )z0Override the base class - just re-raise EOFError)EOFErrorr   r)   r)   r*   
handle_EOF     zMyRPCClient.handle_EOFN)r   r   r   r   r)   r)   r)   r*   r     s    r   c                 C   sZ   d|pd d}| t |kr't| t | d\}}|| d  | |d  S |dd S )zReturn width long restart line formatted with filename.

    Fill line with balanced '='s, with any extras and at least one at
    the beginning.  Do not end with a trailing space.
    z= RESTART: ZShellz =r   rr   N)r   divmod)widthr'   r   Zdivmodr)   r)   r*   restart_line  s
   r   c                   @   s  e Zd Zdd ZdZdZdZdd Zdd Zdd	 Z	d?ddZ
dd Zdd Zdd Zdd Zd@ddZdZdd ZdZdd Zdd Zdd Zd d! Zd"Zd#d$ ZdAd%d&Zd'd( Zd)d* Zd+d, ZdAd-d.Zd/d0 Zd1d2 Zd3d4 Z d5d6 Z!d7d8 Z"d9d: Z#d;d< Z$d=d> Z%dS )BModifiedInterpreterc                 C   sB   || _ tjd j}tj| |d d| _d | _t| _	| j
jj| _d S )Nr   )localsF)	tkconsolesysmodules__dict__r   rD   
restartingsubprocess_arglistPORTportcompilecompilerflagsoriginal_compiler_flags)r@   r   r   r)   r)   r*   rD     s   zModifiedInterpreter.__init__Nc                 C   s&   | j d u r
|  | _ t| j | _d S r>   )r   build_subprocess_arglist
subprocessPopen
rpcsubprocr   r)   r)   r*   spawn_subprocess  s   

z$ModifiedInterpreter.spawn_subprocessc                 C   s\   | j dks	J ddd tjD }tjddddd	d
}d|f }tjg| d|t| j g S )Nr   z/Socket should have been assigned a port number.c                 S   s   g | ]}d | qS )z-Wr)   ).0sr)   r)   r*   
<listcomp>  s    z@ModifiedInterpreter.build_subprocess_arglist.<locals>.<listcomp>mainGeneralzdelete-exitfuncFbool)defaulttypez&__import__('idlelib.run').run.main(%r)-c)r   r   warnoptionsr   	GetOption
executablerz   )r@   rq   Z	del_exitfZcommandr)   r)   r*   r     s   

z,ModifiedInterpreter.build_subprocess_arglistc              	   C   sP  t | jf}tdD ]}t| zt|| _W  n ty!   Y q	w |   d S | jj	
 d | _tdkr@| jj	tjtjd |   | jj	d z| j  W n ty`   |   Y d S w | jd| j | jd| jj | jd| jj | jd| jj | jd	| jj | jd
t | jd|  | jdd |   | jS )N   r   r   
   consoler   stdoutstderrrI   r3   rc   Twith_cwd)HOSTr   r   timesleepr   rpccltr$   display_port_binding_errorlistening_sockgetsocknamer   
setsockoptsocket
SOL_SOCKETSO_REUSEADDRr   
settimeoutacceptTimeoutErrordisplay_no_subprocess_errorregisterr   r   r   r   rI   r3   transfer_pathpoll_subprocess)r@   addrir)   r)   r*   start_subprocess  sD   


z$ModifiedInterpreter.start_subprocessFrW   c                 C   s&  | j r| jS d| _ |  }|rzt| j W n   Y | j  |   | j}|j}d|_| 	  z| j
  W n tyG   |   Y d S w | j|d |  |jdd |d |t|j| |jdd |jdd |s{|  |rt| j |  | j| jj_d| _ | jS )	NTFr   r   end-1crs   restartleft)r   r   getdebuggerr   Zclose_subprocess_debuggercloseterminate_subprocessr   	executingr   r   r   r   r   stop_readlinerE   r   r"   r   r   mark_setmark_gravity
showpromptZrestart_subprocess_debuggerload_breakpointsr   r   r   r   )r@   r   r'   rd   r   Zwas_executingr)   r)   r*   restart_subprocess  sH   

z&ModifiedInterpreter.restart_subprocessc                 C   s   | j dddi  d S )NexecZinterrupt_the_serverr)   )r   Z
remotecallr   r)   r)   r*   Z__request_interrupt     z'ModifiedInterpreter.__request_interruptc                 C   s   t j| jd  d S )N)target)	threadingThread'_ModifiedInterpreter__request_interruptstartr   r)   r)   r*   interrupt_subprocess"  r  z(ModifiedInterpreter.interrupt_subprocessc                 C   sz   | j d ur| jj| j  z| jj  W n	 ty   Y nw z| j  W n	 ty/   Y nw |   d| j_	d | _d S )NF)
_afteridr   rE   Zafter_cancelr   r   r   r#   r   r   r   r)   r)   r*   kill_subprocess%  s   

z#ModifiedInterpreter.kill_subprocessc                 C   sJ   z| j   W n
 ty   Y dS w z| j   W dS  ty$   Y dS w )z"Make sure subprocess is terminatedN)r   killr$   waitr   r)   r)   r*   r   4  s   z(ModifiedInterpreter.terminate_subprocessc                 C   s2   |rdg}| tj ntj}| d|f  d S )NrW   zRif 1:
        import sys as _sys
        _sys.path = %r
        del _sys
        
)extendr   rL   
runcommand)r@   r   rL   r)   r)   r*   r   A  s   
z!ModifiedInterpreter.transfer_pathc              
   C   s2  | j }|d u r	d S z
|j| jdd}W n tttfy,   | jjr$Y d S d }|   Y nw |r| j	  d | _|\}}| jj
}|dkrP|d urOtt||d n$|dkr_| jdr^|   n|dkrtd}t||tjd t|||d z| j  W n	 ty   Y nw | jjs| jj| jj| j| _d S d S )	Ng?)r  ZOKr   Z	EXCEPTION<<toggle-jit-stack-viewer>>ERRORz/pyshell.ModifiedInterpreter: Subprocess ERROR:
)r   Zpollresponse
active_seqr   r$   KeyboardInterruptr   closingr  resetoutputr   printreprgetvarremote_stack_viewerr   
__stderr__endexecutingr#   rE   afterpollintervalr   r  )r@   ZcltresponsehowZwhatr   errmsgr)   r)   r*   r   P  sL   


z#ModifiedInterpreter.poll_subprocessc                 C   s
   || _ d S r>   r   )r@   r   r)   r)   r*   setdebuggerx  s   
zModifiedInterpreter.setdebuggerc                 C      | j S r>   r   r   r)   r)   r*   r   {     zModifiedInterpreter.getdebuggerc                 C   s   | j jd| j dS )a  Initiate the remote stack viewer from a separate thread.

        This method is called from the subprocess, and by returning from this
        method we allow the subprocess to unblock.  After a bit the shell
        requests the subprocess to open the remote stack viewer which returns a
        static object looking at the last exception.  It is queried through
        the RPC mechanism.

        i,  N)r   rE   r  r  r   r)   r)   r*   open_remote_stack_viewer~  s   
z,ModifiedInterpreter.open_remote_stack_viewerc                 C   s   ddl m} | jdddi }|d u r| jj  d S || j|}ddlm	}m
} t| jj}t }t|dd }|||dd	}	|	jjd
dd ||	jd |}
|
  d S )Nr   )
debugobj_rr  Zstackviewer)rI   )ScrolledCanvasTreeNodenormalrY   )bgZhighlightthicknessr   Zboth)expandfill)idlelibr'  r   remotequeuer   r|   rg   ZStubObjectTreeItemZidlelib.treer(  r)  ZToplevelr   r[   r\   framepackZcanvasr,  )r@   r'  Zoiditemr(  r)  r   r]   rY   ZscZnoder)   r)   r*   r    s   z'ModifiedInterpreter.remote_stack_viewerr   c                 C   s   |  |}| || dS )z1Like runsource() but assumes complete exec sourceN)stuffsourceexecfiler@   sourcer'   r)   r)   r*   
execsource  s   
zModifiedInterpreter.execsourcec              	   C   s   |du r-t |}| }trdtj| d| d }W d   n1 s(w   Y  zt||d}W n$ tt	fyY   | j
  td| j
jd t| | | j
  Y dS w | | dS )zExecute an existing fileNz__file__ = r'''z'''
z
del __file__r  zB*** Error in script or command!
Traceback (most recent call last):r   )tokenizerv   readuse_subprocessrK   rL   abspathr   OverflowErrorSyntaxErrorr   r  r  r   r   showsyntaxerrorr  runcode)r@   r'   r6  r~   coder)   r)   r*   r4    s,   
zModifiedInterpreter.execfilec                 C   s&   |  |}t|tsJ t| ||S )zBExtend base class method: Stuff the source in the line cache first)r3  
isinstancerz   r   	runsourcer5  r)   r)   r*   rB    s   
zModifiedInterpreter.runsourcec                 C   s>   d| j  }| j d | _ |d}t|d d||ftj|< |S )z"Stuff source in the filename cachez<pyshell#%d>r   rs   r   )gidsplitr   r3   r4   )r@   r6  r'   r   r)   r)   r*   r3    s
   

zModifiedInterpreter.stuffsourcec                 C   s   |  d|f  dS )z>Prepend sys.path with file's directory if not already includeda(  if 1:
            _filename = %r
            import sys as _sys
            from os.path import dirname as _dirname
            _dir = _dirname(_filename)
            if not _dir in _sys.path:
                _sys.path.insert(0, _dir)
            del _filename, _sys, _dirname, _dir
            
N)r  r@   r'   r)   r)   r*   prepend_syspath  s   
z#ModifiedInterpreter.prepend_syspathc                 C   s   | j }|j}|ddd t \}}}t|ddp|pd}t|ddp%d}t|d	dp-d
}	|	d
kr6|d7 }|dkrAd|	d  }
n
d|d |	d f }
|||
 |  | d|  |	  dS )zOverride Interactive Interpreter method: Use Colorizing

        Color the offending position instead of printing it and pointing at it
        with a caret.

        r  rn   r   msgrW   z<no detail available>r(   r   offsetr   ziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
N)
r   rE   rm   r   exc_infor{   Zcolorize_syntax_errorr  r"   r  )r@   r'   r   rE   r   valuetbrG  r(   rH  posr)   r)   r*   r>    s$   z#ModifiedInterpreter.showsyntaxerrorc                 C   s:   | j   |   t|  | j dr| j   dS dS )z1Extend base class method to reset output properlyr  N)r   r  checklinecacher   showtracebackr  open_stack_viewerr   r)   r)   r*   rN    s   

z!ModifiedInterpreter.showtracebackc                 C   s>   t j}t| D ]}|d d |dd   dkr||= q	d S )Nr   r1   r2   )r3   r4   r5   keys)r@   cr9   r)   r)   r*   rM    s   z"ModifiedInterpreter.checklinecachec                 C   sB   | j jr
|   dS | jr| jdd|fi  dS t|| j dS )z*Run the code without invoking the debuggerr   r  r?  r   )r   r   display_executing_dialogr   r/  r  r   )r@   r@  r)   r)   r*   r    s   zModifiedInterpreter.runcommandc                 C   sd  | j jr|   |   | j}zz*| j   |s)| jdur)| jdd|fi | _n|r3|	|| j
 nt|| j
 W nK tyY   | j jsVtjddd| j jdrQ |   n Y n-   trptd| j jd	 |   | j   n| j jrd
| j _td| j jd	 n|   Y W tsz| j   W dS  ty   Y dS w dS tsz| j   W w  ty   Y w w w )Override base class methodNr  r?  zExit?zDo you want to exit altogether?Zyesr   r   z IDLE internal error in runcode()r   Fr  )r   r   r  rM  r   beginexecutingr   Z
asyncqueuer  runr   r  
SystemExitr  r   ZaskyesnorE   rN  r:  r  r   r  canceledr#   )r@   r@  r   r)   r)   r*   r?    sf   


zModifiedInterpreter.runcodec                 C   s   | j j|S )rS  )r   r   r"   )r@   r   r)   r)   r*   r"   6  s   zModifiedInterpreter.writec                 C      t jdd| jjd d S )NzPort Binding ErroraA  IDLE can't bind to a TCP/IP port, which is necessary to communicate with its Python execution server.  This might be because no networking is installed on this computer.  Run IDLE with the -n command line switch to start without a subprocess and refer to Help/IDLE Help 'Running without a subprocess' for further details.r   r   r}   r   rE   r   r)   r)   r*   r   :  s
   
z.ModifiedInterpreter.display_port_binding_errorc                 C   rY  )NzSubprocess Connection ErrorzIDLE's subprocess didn't make connection.
See the 'Startup failure' section of the IDLE doc, online at
https://docs.python.org/3/library/idle.html#startup-failurer   rZ  r   r)   r)   r*   r   E  s
   
z/ModifiedInterpreter.display_no_subprocess_errorc                 C   rY  )NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.r   rZ  r   r)   r)   r*   rR  M  s
   
z,ModifiedInterpreter.display_executing_dialog)FrW   )Fr>   )&r   r   r   rD   r  r   r   r   r   r   r  r	  r  r  r   r   r  r   r   r#  r   r&  r  rC  r7  r4  rB  r3  rF  r>  rN  rM  r  r?  r"   r   r   rR  r)   r)   r)   r*   r     sH    	
+,
&
	
.r   c                       s&  e Zd ZddlmZ de  ZeZe	Z
g dZejdg Zdeeedd e Zeed	 [d
ZdZddlmZ ddlmZ dfddZ fddZ fddZdd Zdd Zdd ZdfddZ d
Z!d
Z"d
Z#d
Z$d
Z%d
Z&dd Z'dd  Z(dfd!d"Z)d#d$ Z*dfd%d&Z+d'd( Z,d)d* Z-d+d, Z.d-d. Z/d/d0 Z0d1d2 Z1d3d4 Z2d5d6 Z3d7d8 Z4d9Z5d:d; Z6d<d= Z7d>d? Z8d@dA Z9dfdBdCZ:dDdE Z;dFdG Z<dHdI Z=dJdK Z>e?@dLZAdMdN ZBdfdOdPZCdfdQdRZDdfdSdTZEdUdV ZFdWdX ZGdYdZ ZHdgd\d]ZI fd^d_ZJ fd`daZKdfdbdcZLddde ZM  ZNS )hr   r   )SqueezerzIDLE Shell ))r   Z_File)ZeditZ_Edit)rd   Z_Debug)optionsZ_Options)ZwindowZ_Window)helpZ_Help)ZSqueeze<<squeeze-current-text>>r   c                 C   s   | d dkS )Nr   rS   r)   )Z
rmenu_itemr)   r)   r*   r   m  r   zPyShell.<lambda>)zCopy with prompts<<copy-with-prompts>>rT   Fr   )History)ShellSidebarNc                 C   sX  t r| j}|d d dkr|dd t| | _|d u r+t }t| |  t|}d | _	t
| |d d  d| _d| _ttdrDtjnd| _| jd	d
 | _| j| _| j}|jdd |d| j |d| j |d| j |d| j |d| j |d| j |d| j |d| j t r|d| j  |d| j! | "| | _#|d| j$ tj%| _&tj'| _(tj)| _*ddl+m,} t-| d|j.|j/| _)t0| d|j.|j/| _%t0| d|j.d| _'t0| d|j.|j/| _1t s| j%t_%| j't_'| j)t_)z
dd l2}|j3|_4W n   tj5t_' | 6| j| _7d| _8| 9| | _	| j:j;j| j_| j:<t=  d S )Nr   r   shell)rb  ZShe_llF   ps1z>>>
rs   r1   char)wrapz<<newline-and-indent>>z<<plain-newline-and-indent>>z<<interrupt-execution>>z<<end-of-file>>z<<open-stack-viewer>><<toggle-debugger>>r  r_  z<<view-restart>>z<<restart-shell>>r^  )iomenur   r   r   backslashreplacer   2   )>r:  
menu_specsrf   r   rc   Tkr   withdrawr   shell_sidebarr   rD   ZusetabsZindentwidthhasattrr   rd  sys_ps1rD  Zprompt_last_linepromptrE   Z	configurerF   enter_callbacklinefeed_callbackcancel_callbackeof_callbackrO  toggle_debuggertoggle_jit_stack_viewercopy_with_prompts_callbackview_restart_markrestart_shellr[  squeezersqueeze_current_text_eventr   save_stdoutr   save_stderrr   
save_stdinr.  rh  r   encodingerrorsr   r   pydocZ
plainpagerZpagerr  r`  historyr  ra  perr   Zinsertfilterr   )r@   rI   msr|   rE   rh  r  r)   r)   r*   rD   {  s   
zPyShell.__init__c                    s&   t    | jd ur| j  d S d S r>   )r   	ResetFontrn  Zupdate_fontr   r   r)   r*   r    s   

zPyShell.ResetFontc                    s   t    t }d d dt|dt|dt|dd}| D ]\}}| jj|fi | q#| jd ur>| j	  d S d S )N)rY   rX   r   r   r*  )r   r   r   r   )
r   ResetColorizerr   r[   r\   itemsrE   Ztag_configurern  Zupdate_colors)r@   r]   Z
tag_colorsr   Ztag_colors_configr   r)   r*   r    s   




zPyShell.ResetColorizerc                 C   s   t j | jdd dS )Nr   )Zinsert_tagsrV   )r   rE   r   r)   r)   r*   replace_event  s   zPyShell.replace_eventc                 C   s   t jddS )NT)Z
shell_only)r   ZGetExtensionsr   r)   r)   r*   get_standard_extension_names  s   z$PyShell.get_standard_extension_namesc                    s\    j ||}ttt|tt|} fdd|D }ddd t|| D d S )z6Return text between first and last with prompts added.c                    s   g | ]	} j j|qS r)   )rn  Zline_promptsget)r   r(   r   r)   r*   r     s    z+PyShell.get_prompt_text.<locals>.<listcomp>rs   c                 s   s.    | ]\}}|d u r|n| d| V  qd S )N r)   )r   rq  r    r)   r)   r*   	<genexpr>  s
    
z*PyShell.get_prompt_text.<locals>.<genexpr>)rE   r  r   rh   ri   rM   zip
splitlines)r@   firstZlastrE   Zlineno_rangeZpromptsr)   r   r*   get_prompt_text  s   



zPyShell.get_prompt_textc                 C   s^   | j }|d}|du rdS |d}|d dkr|d}|  | ||}|| dS )a  Copy selected lines to the clipboard, with prompts.

        This makes the copied text useful for doc-tests and interactive
        shell code examples.

        This always copies entire lines, even if only part of the first
        and/or last lines is selected.
        zsel.first linestartNsel.lastr1   0zsel.last+1line linestart)rE   r_   Zclipboard_clearr  Zclipboard_append)r@   rj   rE   ZselfirstZsellastZprompt_textr)   r)   r*   rx    s   	


z"PyShell.copy_with_prompts_callbackc                 C   s   |a d S r>   r!   )r@   streamr)   r)   r*   set_warning_stream  s   zPyShell.set_warning_streamc                 C   s   t S r>   r  r   r)   r)   r*   get_warning_stream     zPyShell.get_warning_streamc                 C   sJ   | j rtjdd| jd |   dS | j }|r|   d S |   d S )NzDon't debug nowz*You can only toggle the debugger when idler   rV   )	r   r   r}   rE   set_debugger_indicatorrc   r   close_debuggeropen_debugger)r@   rj   dbr)   r)   r*   rv    s   
zPyShell.toggle_debuggerc                 C   s   | j  }| d|   d S )Nrg  )rc   r   Zsetvarr@   r  r)   r)   r*   r  '  s   
zPyShell.set_debugger_indicatorc                 C   s   d S r>   r)   r   r)   r)   r*   rw  +  r  zPyShell.toggle_jit_stack_viewerc                 C   sh   | j  }|r.| j d  |  | j jrt| j j |   | j	d | j
| _|   |   d S )Nz[DEBUG OFF]
)rc   r   r#  r   r   r   Zclose_remote_debuggerr  r   r"   rp  rq  r  r  r  r)   r)   r*   r  .  s   
zPyShell.close_debuggerc                 C   sX   | j jrt| j j| }nt| }| j | |  d| j | _	| 
  |   d S )Nz[DEBUG ON]
)rc   r   r   Zstart_remote_debuggerr   ZDebuggerr#  r  rp  rq  r  r  )r@   Zdbg_guir)   r)   r*   r  ;  s   

zPyShell.open_debuggerc                 C   s    | j rdnd}| dd| d S )Ndisabledr*  rd   z*tack*iewer)r   Zupdate_menu_state)r@   stater)   r)   r*   debug_menu_postcommandG  s   zPyShell.debug_menu_postcommandc                 C   s   |    d| _dS )Helper for ModifiedInterpreterTN)r  r   r   r)   r)   r*   rU  K  rB   zPyShell.beginexecutingc                 C   s   d| _ d| _|   dS )r  FN)r   rX  r  r   r)   r)   r*   r  P  s   zPyShell.endexecutingc                 C   sD   | j rtjddd| jd}|du rdS |   d| _d| _t| S )zExtend EditorWindow.close()zKill?z7Your program is still running!
 Do you want to kill it?okrT  FcancelT)	r   r   ZaskokcancelrE   r   rX  r  r   r   )r@   r   r)   r)   r*   r   V  s   
zPyShell.closec                 C   sV   |    tr| j  | jt_| jt_| j	t_
d| _d| _d| j_d| _t|  dS )zEExtend EditorWindow._close(), shut down debugger and execution serverN)r  r:  rc   r  r}  r   r   r~  r   r  r   r   rI   rb   r  r   r   r   r)   r)   r*   r   e  s   
zPyShell._closec                 C      dS )z8Override EditorWindow method: never remove the colorizerTr)   rE  r)   r)   r*   ispythonsourceu  r   zPyShell.ispythonsourcec                 C   r$  r>   )shell_titler   r)   r)   r*   short_titley  r%  zPyShell.short_titlezHType "help", "copyright", "credits" or "license()" for more information.c                 C   s   | j dd |   trd}| j }|s|   dS nd}tjt	_| 
dt	jt	j| j|f  | j   |   dd l}d|_d |_dS )	Nr   rf   rW   Fz==== No Subprocess ====

WARNING: Running IDLE without a Subprocess is deprecated
and will be removed in a later version. See Help/IDLE Help
for details.

zPython %s on %s
%s
%sr   T)rE   r   r  r:  rc   r   r   r   displayhookr   r"   versionplatform	COPYRIGHTZfocus_forcer  tkinterZ_support_default_rootZ_default_root)r@   Znosubclientr  r)   r)   r*   r     s(   

zPyShell.beginc                 C   s   | j sd S d| _| j  d S NT)reading_stop_readline_flagr   quitr   r)   r)   r*   r     s   zPyShell.stop_readlinec                 C   s   | j }zd| _ | j  W || _ n|| _ w | jrd| _dS | jdd}t|dkr,d}|   | jr:d| _t	s:t
| jrBd| _d}|S )NTFrW   r   r   r   rs   )r  r   mainloopr  rE   r  r   r  rX  r:  r  	endoffile)r@   r8   r    r)   r)   r*   readline  s(   zPyShell.readlinec                 C   r  r  r)   r   r)   r)   r*   isatty  r  zPyShell.isattyc                 C   s   z| j dddrW d S W n   Y | js(| js(|   | jd |   dS d| _d| _	| jrE| jj
rE| j r@| j  n| j  | jrM| j  dS )N	sel.firstz!=r  zKeyboardInterrupt
rV   FT)rE   r   r   r  r  rc   r"   r  r  rX  r   r   r  r  r   r  r   r)   r)   r*   rt    s(   


zPyShell.cancel_callbackc                 C   sh   | j r| jsd S | jdddr| jdddsd S | j s'|   |   dS d| _d| _| j	  dS )Nr   z==rf   r   FTrV   )
r   r  rE   r   r  r   rX  r  r   r  r   r)   r)   r*   ru    s   
zPyShell.eof_callbackc                 C   s2   | j r| jdd | jd dS | | dS )Nrf   rs   rV   )r  rE   rf   seenewline_and_indent_eventr   r)   r)   r*   rs    s   
zPyShell.linefeed_callbackc           	      C   s   | j r| jsd S z| jdd}|r#| jdddr#| || W dS W n   Y | jdddr| jd	d}|r| jdd|d
 rd| jdvr| jdd}|rj| j|d
 d|d rj|d
 |d
 f}| jdd}|r| j|d d|d
 r|d | j	|d d f}| | j|d |d
 | dS | jd	d}|r| jdd|d r| jdd}|r| j|d d|d
 r|d | j	|d d f}| | j|d |d
 | dS | jdd}|r	| j|d ddr	| | j|d
 d| dS | | jdd| dS | jdddr&| j
dd | jdd}|r<| s<| jdd | jdddrL| | dS | j
dd | jre| jdd | jd n| | | j  | jrz| j  dS |   dS )Nr  r  z<=r   rV   rf   r   iomark linestartr   r   r   z>=r   z+1czinsert lineendrk   r   zend-1c linestartrs   )r   r  rE   r  r   recallZtag_prevrangeZ	tag_namesZtag_nextranger_   r   stripr   r  rf   r  Zupdate_idletasksr   r  runit)	r@   rj   selprevZ	prev_consZ	next_consnextindicesr   r)   r)   r*   rr    sx   



zPyShell.enter_callbackc              	   C   sl  t dd|}t dd|}|d}| j  z| jddd | jdd	 | jd
d}| 	drB| 
| | jd
d}| jd|d  | j t|dkrt d|d d}t d|d}|dd  D ],}||r||t|d   }| jdd|  | j qoW | jd | j  d S W | jd | j  d S | jd | j  w )Nz^\s*\nrW   z\n\s*$rs   r  rn   r   rf   r   rk   :r   r   z	^([ \t]*))resubrD  rE   Zundo_block_startrm   r   r  rstripendswithr  rf   r  user_input_insert_tagsr   searchgrouprx   r  Zundo_block_stop)r@   r   rj   r   prefixZorig_base_indentZnew_base_indentr    r)   r)   r*   r  6  s>   




zPyShell.recallz[ \t]*(\n[ \t]*)?\Zc                 C   sj   | j d}| j dd}| jd|}| j|}|s3| j |dkr,| j | j| | j	
  d S d S )Nend-2cr   r   rW   rs   )rE   r_   r  _last_newline_rer  rc   rB  rm   r  rn  update_sidebar)r@   Zindex_beforer    Zinput_is_completer)   r)   r*   r  S  s   zPyShell.runitc                 C   sZ   | j jr	| j  S ztj W n   tjdd| jd Y d S ddlm	} || j
| j d S )NzNo stack tracez@There is no stack trace yet.
(sys.last_traceback is not defined)r   r   )StackBrowser)rc   r   r  r   last_tracebackr   r}   rE   Zidlelib.stackviewerr  r|   rI   )r@   rj   r  r)   r)   r*   rO  _  s   

zPyShell.open_stack_viewerc                 C   s   | j d | j d d S )Nr   r   )rE   r  r   r)   r)   r*   ry  m  s   zPyShell.view_restart_markc                 C   s   | j jdd dS )z&Callback for Run/Restart Shell Cntl-F6Tr   N)rc   r  r   r)   r)   r*   rz  q  s   zPyShell.restart_shellc                 C   s|   |    | j}| jr|| jr|d t| j  }| jdd | j| | j	
  | jdd |   | j  d S )Nr   z	iomark-1crf   r   )r  rq  rp  r  r   rE   r^   r   r"   rn  r  r   set_line_and_columnrO   Z
reset_undo)r@   rq  r)   r)   r*   r  u  s   
zPyShell.showpromptc                 C   sP   | j jj}t|ddd}d||}|ds|d7 }| jj	d|d d S )N   T)r   tabsizeZexpand_tabsrs   r  r   )
rc   r   r   r   rM   rf  r  r  Zbottomrf   )r@   rG  r   wrapperZwrapped_msgr)   r)   r*   show_warning  s   

zPyShell.show_warningc                 C   sb   | j dd}| jr| j| | j ddkr| j dd | j dd |   | j  d S )Nr   r   r  rs   )	rE   r  r  storerf   r   r  ZctipZremove_calltip_window)r@   r6  r)   r)   r*   r    s   zPyShell.resetoutputr)   c                 C   sR   z| j dd t| ||d}| j dd W n    | jr'd| _ts't|S )Nr   rightr   F)rE   r   r   r"   rX  r:  r  )r@   r   r   countr)   r)   r*   r"     s   zPyShell.writec                    s:   z| j dddrW dS W n
 ty   Y dS w t  S )Nr  r   r   r  )rE   r   r   r   rR   r   r   r)   r*   rR     s   
zPyShell.rmenu_check_cutc                    s   | j dddr
dS t  S )Nrf   r   r   r  )rE   r   r   rU   r   r   r)   r*   rU     s   
zPyShell.rmenu_check_pastec                 C   s   | j   | j  d S r>   )r{  Zsqueeze_current_textrn  r  r   r)   r)   r*   r|    s   
z"PyShell.squeeze_current_text_eventc                 C   s   | j   d S r>   )rn  r  )r@   r_   rE   r   r)   r)   r*   on_squeezed_expand  s   zPyShell.on_squeezed_expandr>   )r)   )Or   r   r   Zidlelib.squeezerr[  r   r  r   r   r   r   rk  r   r   r   r5   	itertools	takewhileZ_idxrf   Zallow_line_numbersr  Zidlelib.historyr`  Zidlelib.sidebarra  rD   r  r  r  r  r  rx  r  r   rX  r  r  r  r  r  rv  r  rw  r  r  r  rU  r  r   r   r  r  r  r   r   r  r  rt  ru  rs  rr  r  r  r   r  r  rO  ry  rz  r  r  r  r"   rR   rU   r|  r  r   r)   r)   r   r*   r   U  s    




N



	O






r   c              
   C   s6   | j dkrdD ]}| |dd| |d  qdS dS )z6Make paste replace selection on x11.  See issue #5124.Zx11)ZTextZEntryZSpinboxz	<<Paste>>z%catch {%W delete sel.first sel.last}
N)Z_windowingsystemZ
bind_class)r|   clsr)   r)   r*   fix_x11_paste  s   

r  a  
USAGE: idle  [-deins] [-t title] [file]*
       idle  [-dns] [-t title] (-c cmd | -r file) [arg]*
       idle  [-dns] [-t title] - [arg]*

  -h         print this help message and exit
  -n         run IDLE without a subprocess (DEPRECATED,
             see Help/IDLE Help for details)

The following options will override the IDLE 'settings' configuration:

  -e         open an edit window
  -i         open a shell window

The following options imply -i and will open a shell:

  -c cmd     run the command in a shell, or
  -r file    run script from file

  -d         enable the debugger
  -s         run $IDLESTARTUP or $PYTHONSTARTUP before anything else
  -t title   set title of shell window

A default edit window will be bypassed when -c, -r, or - are used.

[arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].

Examples:

idle
        Open an edit window or shell depending on IDLE's configuration.

idle foo.py foobar.py
        Edit the files, also open a shell if configured to start with shell.

idle -est "Baz" foo.py
        Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
        window with the title "Baz".

idle -c "import sys; print(sys.argv)" "foo"
        Open a shell window and run the command, passing "-c" in sys.argv[0]
        and "foo" in sys.argv[1].

idle -d -s -r foo.py "Hello World"
        Open a shell window, run a startup script, enable the debugger, and
        run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
        sys.argv[1].

echo "import sys; print(sys.argv)" | idle - "foobar"
        Open a shell window, run the script piped in, passing '' in sys.argv[0]
        and "foobar" in sys.argv[1].
c               
      sJ  dd l } ddlm} ddlm} ddlm} td dad}d}d}d }d }d}	z|  tj	dd  d\}
}W n# | j
yZ } ztd	|tf tjd
 td W Y d }~nd }~ww |
D ]d\}}|dkri|}d}|dkrqd}d}|dkrwd}|dkrtjt t  |dkrd}|dkrtdtjd
 da|dkr|}tj|rn	td| t  d}|dkrd}	d}|dkr|t_d}q]|r|d dkrtj }d}tttjD ]}tjtj| tj|< q|r|d dkrdg|dd   t_	nU|rdg| t_	nK|r|g| t_	nA|r>d}g }|D ]}|tj| q|D ]}tj|}|tjvr;tjd| q&nt }|tjvrOtjd| tj ddddd}|p\|}|pb| }trl|slt!  t"dda#t#$  dd l%m&} |t# tj'tjt(d!| d"krtj'd#}t#j)|d$ n-|* st+d%krd& d'}nd( d)} fd*d+|D }d,d+ |D }t#j,dg|R   t-t# t.t# t/t#a0|1t#t0 |r|s|s|d d  D ]}t02|d u r|3| q|st04  |rt05 }|sd S |* rt0j6r|j78  nt0j9}|r)|:  |	rItj;<d-p8tj;<d.}|rItj|rI|j=>| |sO|rs|j=?d/tj	f  |rc|j=@| n,|rr|j=A| |j=>| n|r|Bt#}|r|C| |D }|r|C| t0jErt#F  t0jEst#G  td d S )0Nr   )system)testing)macosxTFr   zc:deihnr:st:zError: %s
%sr   r   r   z-dz-ez-hz-iz-nz: Warning: running IDLE without a subprocess is deprecated.z-rzNo script file: z-sz-t-rW   r   r   zeditor-on-startupr   )r   ZIdle)Z	classNamer	   ZIconsZWindowszidle.ico)r   g333333!@z.png)       0      z.gif)r  r  r  c                    s"   g | ]}t jd | f qS )z	idle_%d%s)rK   rL   rM   )r   sizeextZicondirr)   r*   r   b  s    zmain.<locals>.<listcomp>c                 S   s   g | ]}t t|d qS ))Zmasterr   )Z
PhotoImager|   )r   iconfiler)   r)   r*   r   d  s    ZIDLESTARTUPZPYTHONSTARTUPzbif 1:
            import sys as _sys
            _sys.argv = %r
            del _sys
            
)Hgetoptr  r  r.  r  r  r0   r:  r   argverrorr  	usage_msgr   exitr   r"   rK   rL   r   r   r  r   r9  r   r   r;  ra   dirnamerf   getcwdr   r   ZNoDefaultRootrl  r|   rm  idlelib.runr
   rM   __file__Zwm_iconbitmapZisAquaTk	TkVersionZwm_iconphotor   r  r   rI   ZsetupApprv   rl   newrJ   dictr   lowerrb   r  environr  rc   r4  r  r7  rF  ZtkVersionWarningr  ZpreferTabsPreferenceWarningZinversedictr  Zdestroy)r  r  r  r  Zenable_shellZenable_editrd   cmdZscriptZstartupZoptsrQ   rG  oar   Zpathxr'   dirZ
edit_startr
   r  ZsizesZ	iconfilesZiconsrb  ZtkversionwarningZprefer_tabs_preference_warningr)   r  r*   r     s6  











r   )NN)Xr   r   r   r  ImportErrorr  r  rW  r  ZctypesZPROCESS_SYSTEM_DPI_AWAREZOleDLLZSetProcessDpiAwarenessr#   r$   r   r  rl  r|   rm  r  r
   r}   r@  r   r  r3   rK   Zos.pathr   r  r   r   textwrapr   r  r   r8  r-   Zidlelib.colorizerr   Zidlelib.configr   Zidlelib.delegatorr   r.  r   r   Zidlelib.editorr   r   Zidlelib.filelistr   Zidlelib.outwinr   r   r   r   r   r   Zidlelib.undor   r:  r   r   eofr  r  	NameErrorr!   r+   r,   r0   
checkcacher:   r;   r   r   r   r   Z	RPCClientr   r   r   r   r  r  r   r)   r)   r)   r*   <module>   s   



 ?"   0    g6 
6