Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/idlelib/__pycache__/pyshell.cpython-310.pyc

o

0�i��
@s,ddlZedkrejdejd<zddlTWney(edejd�ed��wejdkrKzddl	Z	dZ
e	�d	��e
�Wnee
efyJYnwdd
lmZedkrte�at��ddlmZet�ejd
detd�ed��ddlmZddlZddlZddlZddlZddlmZddlZddlZddl Z ddl!m"Z"ddl#Z#ddl$Z$ddl%Z%ddl&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl-m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl-m7Z7ddl-m8Z8ddlm9Z9m:Z:m;Z;ddl<m=Z=da>d Z?dZ@z
d!ZAeAeB_AeAeC_AWn
eD�yYnwejaE	d@d"d#�ZFdaGd$d%�ZHeHd&�dejIfd'd(�ZJeJe_IGd)d*�d*e1�ZKGd+d,�d,e4�ZLGd-d.�d.e(�ZMGd/d0�d0e=�ZNGd1d2�d2e,�ZOGd3d4�d4e8jP�ZQd5d6�ZRGd7d8�d8e�ZSGd9d:�d:e6�ZTd;d<�ZUd=ZVd>d?�ZWedk�r�eW�eHd�dS)A�N�__main__zidlelib.pyshell)�*zJ** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **��file�Zwin32Zshcore)�
messageboxg!@��fix_scalingzIdle 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.1zCtrl-D (end-of-file)c	CsN|durt}z|�t|||||d��|�d�WdSttfy&YdSw)aShow 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�linenorr�r(�6/opt/alt/python310/lib64/python3.10/idlelib/pyshell.py�idle_showwarningRs
��r*cCs:|rtdurtjatt_dSdStdurtt_dadSdS)z>Replace warning.showwarning with idle_showwarning, or reverse.N)�_warnings_showwarning�warnings�showwarningr*)Zcapturer(r(r)�capture_warningses
��r.TcCsXtj}i}t|�D]}|dd�|dd�dkr |�|�||<q	||�|�|�dS)aoExtend 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&Zorig_checkcacher2�save�keyr(r(r)�extended_linecache_checkcachets�r8c@sveZdZdZdd�Zgd�Zddd�Zdd	�Zddd�Zdd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd
S)�PyShellEditorWindowz6Regular text edit window in IDLE, supports breakpointscGs�g|_tj|g|�R�|j�d|j�|j�d|j�|j�d|jj�t	j
�tj
d�|_|jj|fdd�}|j�|�|jjrE|��|��dS)N�<<set-breakpoint-here>>�<<clear-breakpoint-here>>z<<open-python-shell>>zbreakpoints.lstcSs|��|�dS�N)�restore_file_breaks)Zold_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�joinrZuserdir�breakpointPath�ioZfilename_change_hookZset_filename_change_hookr&r=�color_breakpoint_text)r>�argsr?r(r(r)rB�s�
�zPyShellEditorWindow.__init__))ZCutz<<cut>>�rmenu_check_cut)�Copyz<<copy>>�rmenu_check_copy)ZPastez	<<paste>>�rmenu_check_paste)NNN)zSet Breakpointr:N)zClear Breakpointr;NTcCsD|jdurdS|rt��}t�|d�}nddd�}|j�d|�dS)z,Turn colorizing of breakpoint text on or offN�break�)�
foreground�
background�BREAK)rMr�CurrentTheme�GetHighlightrCZ
tag_config)r>Zcolor�themeZcfgr(r(r)rN�s

z)PyShellEditorWindow.color_breakpoint_textcCs�|j}|jj}|�dd|d|d�z|j�|�Wnty+|j�|�Ynwz|jj	j
j}|�||�WdSYdS)NrXz%d.0r)
rCrMr&�tag_addrA�index�
ValueError�appendrG�pyshell�interprrE)r>r'rCr&�debugr(r(r)�set_breakpoint�s�z"PyShellEditorWindow.set_breakpointNcCs>|j}|jj}|s|��dStt|�d���}|�|�dS)N�insert)rCrMr&�bell�int�floatr]rc)r>�eventrCr&r'r(r(r)rE�sz'PyShellEditorWindow.set_breakpoint_herecCs�|j}|jj}|s|��dStt|�d���}z|j�|�WnY|�	ddd�z|j
jjj
}|�||�WdSYdS)NrdrX�insert linestartzinsert lineend +1char)rCrMr&rerfrgr]rA�remove�
tag_removerGr`rarrF)r>rhrCr&r'rbr(r(r)rF�s$�z)PyShellEditorWindow.clear_breakpoint_herecCsf|jr1|j}|jj}|s|��dSg|_|�ddt�z|jjj	j
}|�|�WdSYdSdS)NrX�1.0)rArCrMr&rerkZENDrGr`rar�clear_file_breaks)r>rCr&rbr(r(r)rm�s�z%PyShellEditorWindow.clear_file_breaksc
CsZ|j}|jj}zt|jd��}|��}Wd�n1swYWnty.g}YnwzKt|jd��:}|D]}|�|d�sG|�|�q9|�	�|j}|rg|�|dt
|�d�Wd�WdSWd�WdS1sswYWdSty�}z&t|jdd�s�d|j_
tjd	d
t
|�|jd�WYd}~dSWYd}~dSd}~ww)z#Save breakpoints when file is saved�rN�w�=�
�breakpoint_error_displayedFTz
IDLE Errorz$Unable to update breakpoint list:
%s)�titler$r)rArMr&�openrL�	readlinesr#�
startswithr!�update_breakpoints�str�getattr�rootrrr�	showerrorrC)r>Zbreaksr&�fp�linesZnew_filer�errr(r(r)�store_file_breaks�sF
���
��&������z%PyShellEditorWindow.store_file_breakscCs�|j��|jdurdS|jj}|durdStj�|j�rYt|jd��}|�	�}Wd�n1s2wY|D]!}|�
|d�rXt|t|�dd��}|D]}|�
|�qPq9dSdS)Nrnrpr)rCr5rMr&rIrJ�isfilerLrtrurv�eval�lenrc)r>r&r|r}rZbreakpoint_linenumbersZbreakpoint_linenumberr(r(r)r=s$


���z'PyShellEditorWindow.restore_file_breakscCs$|j}|�d�}|�|�}||_dS)z3Retrieves all the breakpoints in the current windowrXN)rCZ
tag_ranges�ranges_to_linenumbersrA)r>rC�rangesZlinenumber_listr(r(r)rw+s


z&PyShellEditorWindow.update_breakpointscCshg}tdt|�d�D]'}tt||j��}tt||dj��}||kr1|�|�|d7}||ks$q
|S)Nr�r)�ranger�rfrg�stringr_)r>r�r}r]r'�endr(r(r)r�2s
��z)PyShellEditorWindow.ranges_to_linenumberscCs|��t�|�dS)z7Extend base method - clear breaks when module is closedN)rmr�_close�r>r(r(r)r�CszPyShellEditorWindow._close)Tr<)�__name__�
__module__�__qualname__�__doc__rB�rmenu_specsrNrcrErFrmrr=rwr�r�r(r(r(r)r9�s
	

	*r9c@s"eZdZdZeZdZddd�ZdS)�PyShellFileListz8Extend base class: IDLE supports a shell and breakpointsNcCs<|jr|jj��|jSt|�|_|jr|j��sdS|jSr<)r`�top�wakeup�PyShell�begin�r>rhr(r(r)rHRs
�
zPyShellFileList.open_shellr<)r�r�r�r�r9rr`rHr(r(r(r)r�Is
r�c@s eZdZdZdd�Zdd�ZdS)�ModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfcCs*|�ddd�|�ddd�t�|�dS)NZTODOrl�iomarkZSYNC)rkr\r�recolorize_mainr�r(r(r)r�_sz&ModifiedColorDelegator.recolorize_maincCs|jD]	}|�|dd�qdS)Nr�r�)Ztagdefsrk)r>�tagr(r(r)�removecolorsds
�z#ModifiedColorDelegator.removecolorsN)r�r�r�r�r�r�r(r(r(r)r�]sr�cs4eZdZdZd	dd�Zd	dd�Z�fdd�Z�ZS)
�ModifiedUndoDelegatorz;Extend base class: forbid insert/delete before the I/O markNcCsLz|j�|dd�r|j��WdSWn	tyYnwt�||||�dS�N�<r�)�delegate�comparere�TclErrorrrd�r>r]�chars�tagsr(r(r)rdls
��zModifiedUndoDelegator.insertcCsJz|j�|dd�r|j��WdSWn	tyYnwt�|||�dSr�)r�r�rer�r�delete)r>Zindex1Zindex2r(r(r)r�us
��zModifiedUndoDelegator.deletecs>|jj��fdd�|j_z
t��|�W�|j_dS�|j_w)Ncs�||d�S�N�stdinr()r]r��Zorig_insertr(r)�<lambda>��z2ModifiedUndoDelegator.undo_event.<locals>.<lambda>)r�rd�super�
undo_eventr���	__class__r�r)r�~s
�z ModifiedUndoDelegator.undo_eventr<)r�r�r�r�rdr�r��
__classcell__r(r(r�r)r�js


		r�c@seZdZdZddd�ZdS)�UserInputTaggingDelegatorz.Delegator used to tag user input with "stdin".NcCs |durd}|j�|||�dSr�)r�rdr�r(r(r)rd�sz UserInputTaggingDelegator.insertr<)r�r�r�r�rdr(r(r(r)r��sr�c@seZdZdd�ZdS)�MyRPCClientcCst�)z0Override the base class - just re-raise EOFError)�EOFErrorr�r(r(r)�
handle_EOF��zMyRPCClient.handle_EOFN)r�r�r�r�r(r(r(r)r��sr�cCsZd|pd�d�}|t|�kr't|t|�d�\}}||d�|�|d��S|dd�S)z�Return 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: ZShellz =r�rpN���)r��divmod)�widthr&r�Zdiv�modr(r(r)�restart_line�s
r�c@seZdZdd�ZdZdZdZdd�Zdd�Zdd	�Z	d?dd
�Z
dd�Zdd�Zdd�Z
dd�Zd@dd�ZdZdd�ZdZdd�Zdd�Zdd�Zd d!�Zd"Zd#d$�ZdAd%d&�Zd'd(�Zd)d*�Zd+d,�ZdAd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$d=d>�Z%dS)B�ModifiedInterpretercCsB||_tjdj}tj||d�d|_d|_t|_	|j
jj|_
dS)Nr)�localsF)�	tkconsole�sys�modules�__dict__rrB�
restarting�subprocess_arglist�PORT�port�compile�compiler�flags�original_compiler_flags)r>r�r�r(r(r)rB�szModifiedInterpreter.__init__NcCs&|jdur
|��|_t�|j�|_dSr<)r��build_subprocess_arglist�
subprocess�Popen�
rpcsubprocr�r(r(r)�spawn_subprocess�s

z$ModifiedInterpreter.spawn_subprocesscCs\|jdks	Jd��dd�tjD�}tjddddd	d
�}d|f}tjg|d|t|j�gS)
Nrz/Socket should have been assigned a port number.cSsg|]}d|�qS)z-Wr()�.0�sr(r(r)�
<listcomp>�sz@ModifiedInterpreter.build_subprocess_arglist.<locals>.<listcomp>�main�Generalzdelete-exitfuncF�bool)�default�typez&__import__('idlelib.run').run.main(%r)�-c)r�r��warnoptionsr�	GetOption�
executablerx)r>roZ	del_exitfZcommandr(r(r)r��s�
�
z,ModifiedInterpreter.build_subprocess_arglistc	CsPt|jf}td�D]}t�|�zt|�|_Wnty!Yq	w|��dS|jj	�
�d|_tdkr@|jj	�t
jt
jd�|��|jj	�d�z|j��Wnty`|��YdSw|j�d|j�|j�d|jj�|j�d|jj�|j�d|jj�|j�d	|jj�|j�d
t�|j�d|�|jdd
�|��|jS)N�rr�
�consoler��stdout�stderrrGr1raT��with_cwd)�HOSTr�r��time�sleepr��rpccltr#�display_port_binding_error�listening_sockZgetsocknamer�Z
setsockopt�socketZ
SOL_SOCKETZSO_REUSEADDRr�Z
settimeout�accept�TimeoutError�display_no_subprocess_error�registerr�r�r�r�rGr1�
transfer_path�poll_subprocess)r>Zaddr�ir(r(r)�start_subprocess�sD


���z$ModifiedInterpreter.start_subprocessFrUcCs&|jr|jSd|_|��}|rzt�|j�WnY|j��|��|j}|j}d|_|�	�z|j�
�WntyG|��YdSw|j
|d�|��|j�dd�|�d�|�t|j|��|j�dd�|j�dd�|s{|��|r�t�|j�|��|j|jj_d|_|jS)	NTFr�r��end-1crq�restart�left)r�r��getdebuggerrZclose_subprocess_debugger�close�terminate_subprocessr��	executingr�r�r�r�r��
stop_readlinerCr�r!r�r��mark_set�mark_gravity�
showpromptZrestart_subprocess_debugger�load_breakpointsr�r�r�r�)r>r�r&rbr�Z
was_executingr(r(r)�restart_subprocess�sH
�
z&ModifiedInterpreter.restart_subprocesscCs|j�dddi�dS)N�execZinterrupt_the_serverr()r�Z
remotecallr�r(r(r)Z__request_interrupt�z'ModifiedInterpreter.__request_interruptcCstj|jd���dS)N)�target)�	threadingZThread�'_ModifiedInterpreter__request_interrupt�startr�r(r(r)�interrupt_subprocess"r�z(ModifiedInterpreter.interrupt_subprocesscCsz|jdur
|jj�|j�z|jj��Wn	tyYnwz|j��Wn	ty/Ynw|��d|j_	d|_dS)NF)
�_afteridr�rCZafter_cancelr�r�r�r"r�r�r�r(r(r)�kill_subprocess%s
��
z#ModifiedInterpreter.kill_subprocesscCsJz|j��Wn
tyYdSwz|j��WdSty$YdSw)z"Make sure subprocess is terminatedN)r��killr#�waitr�r(r(r)r�4s��z(ModifiedInterpreter.terminate_subprocesscCs2|rdg}|�tj�ntj}|�d|f�dS)NrUzRif 1:
        import sys as _sys
        _sys.path = %r
        del _sys
        
)�extendr�rJ�
runcommand)r>r�rJr(r(r)r�As
�z!ModifiedInterpreter.transfer_pathc
Cs2|j}|dur	dSz
|j|jdd�}Wntttfy,|jjr$YdSd}|��Ynw|r�|j�	�d|_|\}}|jj
}|dkrP|durOtt|�|d�n$|dkr_|j�
d�r^|��n|dkrtd}t||tjd�t|||d�z|j��Wn	ty�Ynw|jjs�|jj�|jj|j�|_dSdS)	Ng�������?)rZOKrZ	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"rC�after�pollintervalr�r)r>Zclt�responseZhowZwhatr��errmsgr(r(r)r�PsL�
���

��z#ModifiedInterpreter.poll_subprocesscCs
||_dSr<r)r>rr(r(r)�setdebuggerxs
zModifiedInterpreter.setdebuggercC�|jSr<rr�r(r(r)r�{�zModifiedInterpreter.getdebuggercCs|jj�d|j�dS)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�rCrrr�r(r(r)�open_remote_stack_viewer~s
z,ModifiedInterpreter.open_remote_stack_viewercCs�ddlm}|j�dddi�}|dur|jj��dS|�|j|�}ddlm	}m
}t|jj�}t�
�}t�|d�d}|||dd	�}	|	jjd
dd�||	jd|�}
|
��dS)
Nr)�
debugobj_rr�Zstackviewer)rG)�ScrolledCanvas�TreeNode�normalrW)ZbgZhighlightthicknessrZboth)�expandZfill)�idlelibrr��remotequeuer�rzreZStubObjectTreeItemZidlelib.treerrZToplevelrrYrZ�frameZpackZcanvasr )r>rZoid�itemrrr�r[rWZscZnoder(r(r)r�sz'ModifiedInterpreter.remote_stack_viewerrcCs|�|�}|�||�dS)z1Like runsource() but assumes complete exec sourceN)�stuffsource�execfile�r>�sourcer&r(r(r)�
execsource�s
zModifiedInterpreter.execsourcec	Cs�|dur-t�|��}|��}trdtj�|��d�|d}Wd�n1s(wYzt||d�}Wn$tt	fyY|j
��td|j
j
d�t�||�|j
��YdSw|�|�dS)zExecute an existing fileNz__file__ = r'''z'''
z
del __file__r�zB*** Error in script or command!
Traceback (most recent call last):r)�tokenizert�read�use_subprocessrIrJ�abspathr��
OverflowError�SyntaxErrorr�r
rr�r�showsyntaxerrorr��runcode)r>r&r(r|�coder(r(r)r&�s,����
��zModifiedInterpreter.execfilecCs&|�|�}t|t�sJ�t�|||�S)zBExtend base class method: Stuff the source in the line cache first)r%�
isinstancerxr�	runsourcer'r(r(r)r4�s
zModifiedInterpreter.runsourcecCs>d|j}|jd|_|�d�}t|�dd||ftj|<|S)z"Stuff source in the filename cachez<pyshell#%d>rrqr)�gid�splitr�r1r2)r>r(r&r}r(r(r)r%�s


zModifiedInterpreter.stuffsourcecCs|�d|f�dS)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_syspathcCs�|j}|j}|�ddd�t��\}}}t|dd�p|pd}t|dd�p%d}t|d	d�p-d
}	|	d
kr6|d7}|dkrAd|	d}
n
d|d|	df}
|�||
�|��|�d
|�|�	�dS)z�Override Interactive Interpreter method: Use Colorizing

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

        r	rlr��msgrUz<no detail available>r'r�offsetrziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
N)
r�rCrkr��exc_inforyZcolorize_syntax_errorr
r!r�)r>r&r�rCr��value�tbr9r'r:�posr(r(r)r0�s$�z#ModifiedInterpreter.showsyntaxerrorcCs:|j��|��t�|�|j�d�r|j��dSdS)z1Extend base class method to reset output properlyrN)r�r
�checklinecacher�
showtracebackr�open_stack_viewerr�r(r(r)r@�s

�z!ModifiedInterpreter.showtracebackcCs>tj}t|���D]}|dd�|dd�dkr||=q	dS)Nrr/r0)r1r2r3�keys)r>�cr7r(r(r)r?�s��z"ModifiedInterpreter.checklinecachecCsB|jjr
|��dS|jr|j�dd|fi�dSt||j�dS)z*Run the code without invoking the debuggerrr�r1r)r�r��display_executing_dialogr�r"r�r�)r>r2r(r(r)r�s�zModifiedInterpreter.runcommandcCsd|jjr|��|��|j}z�z*|j��|s)|jdur)|j�dd|fi�|_n|r3|�	||j
�nt||j
�WnKtyY|jj
sVtjddd|jjd�rQ�|��n�Yn-trptd|jjd	�|��|j��n|jjr�d
|j_td|jjd	�n|��YWts�z|j��WdSty�YdSwdSts�z|j��Wwty�Ywww)�Override base class methodNr�r1zExit?zDo you want to exit altogether?Zyes�r�rz IDLE internal error in runcode()rFr)r�r�r�r?r�beginexecutingr�Z
asyncqueuer
�runr�r��
SystemExitrrZaskyesnorCr@r,rr�r�canceledr")r>r2rr(r(r)r1sf

���
�������zModifiedInterpreter.runcodecCs|jj�|�S)rE)r�r�r!)r>r�r(r(r)r!6szModifiedInterpreter.writecC�tjdd|jjd�dS)NzPort Binding ErroraAIDLE 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
�rr{r�rCr�r(r(r)r�:s

�z.ModifiedInterpreter.display_port_binding_errorcCrK)NzSubprocess Connection Errorz�IDLE'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
rLr�r(r(r)r�Es

�z/ModifiedInterpreter.display_no_subprocess_errorcCrK)NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.r
rLr�r(r(r)rDMs

�z,ModifiedInterpreter.display_executing_dialog)FrU)Fr<)&r�r�r�rBrr�r�r�r�r�r�r�rrr�r�r
r�rrr�rrr5r)r&r4r%r8r0r@r?rr1r!r�r�rDr(r(r(r)r��sH	
+,


&

	
.r�cs&eZdZddlmZde�ZeZe	Z
gd�Zej
dgZ
deee�dd�e
���Ze
�ed	�[d
ZdZddlmZdd
lmZdfdd�Z�fdd�Z�fdd�Zdd�Zdd�Zdd�Zdfdd�Z d
Z!d
Z"d
Z#d
Z$d
Z%d
Z&dd�Z'dd �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�fd^d_�ZJ�fd`da�ZKdfdbdc�ZLddde�ZM�ZNS)hr�r)�SqueezerzIDLE Shell ))rZ_File)ZeditZ_Edit)rbZ_Debug)ZoptionsZ_Options)ZwindowZ_Window)�helpZ_Help)ZSqueeze�<<squeeze-current-text>>rcCs|ddkS)NrrQr()Z
rmenu_itemr(r(r)r�mr�zPyShell.<lambda>)zCopy with prompts�<<copy-with-prompts>>rRFr�)�History)�ShellSidebarNcCsXtr|j}|dddkr|�dd�t|�|_|dur+t�}t|�|��t|�}d|_	t
�||dd�d|_d|_
ttd�rDtjnd|_|j�d	�d
|_|j|_|j}|jdd�|�d
|j�|�d|j�|�d|j�|�d|j�|�d|j�|�d|j�|�d|j�|�d|j�tr�|�d|j �|�d|j!�|�"|�|_#|�d|j$�tj%|_&tj'|_(tj)|_*ddl+m,}t-|d|j.|j/�|_)t0|d|j.|j/�|_%t0|d|j.d�|_'t0|d|j.|j/�|_1ts�|j%t_%|j't_'|j)t_)z
ddl2}|j3|_4Wntj5t_'�|�6|j�|_7d|_8|�9|�|_	|j:j;j|j_|j:�<t=��dS)Nr�r�shell)rSZShe_llF��ps1z>>>
rqr/�char)�wrapz<<newline-and-indent>>z<<plain-newline-and-indent>>z<<interrupt-execution>>z<<end-of-file>>z<<open-stack-viewer>>�<<toggle-debugger>>rrPz<<view-restart>>z<<restart-shell>>rO)�iomenur�r�r��backslashreplacer��2)>r,�
menu_specsrdr�ra�Tkr�withdrawr��
shell_sidebarrrBZusetabsZindentwidth�hasattrr�rU�sys_ps1r6Zprompt_last_line�promptrCZ	configurerD�enter_callback�linefeed_callback�cancel_callback�eof_callbackrA�toggle_debugger�toggle_jit_stack_viewer�copy_with_prompts_callback�view_restart_mark�
restart_shellrM�squeezer�squeeze_current_text_eventr��save_stdoutr��save_stderrr��
save_stdinr!rYr�encoding�errorsrr��pydocZ
plainpagerZpagerrrQ�historyrrR�perr�Zinsertfilterr�)r>rGZmsrzrCrYrsr(r(r)rB{s�
�����zPyShell.__init__cs&t���|jdur|j��dSdSr<)r��	ResetFontr_Zupdate_fontr�r�r(r)rv�s

�zPyShell.ResetFontcs�t���t��}ddd�t�|d�t�|d�t�|d�d�}|��D]\}}|jj|fi|��q#|jdur>|j�	�dSdS)N)rWrVr�r�r)r�r�r�r�)
r��ResetColorizerrrYrZ�itemsrCZ
tag_configurer_Z
update_colors)r>r[Z
tag_colorsr�Ztag_colors_configr�r(r)rw�s



�
�zPyShell.ResetColorizercCstj|jdd�dS)Nr�)Zinsert_tagsrT)rrCr�r(r(r)�
replace_event�szPyShell.replace_eventcCstjdd�S)NT)Z
shell_only)rZ
GetExtensionsr�r(r(r)�get_standard_extension_names�sz$PyShell.get_standard_extension_namescs\�j�||�}ttt|��tt|���}�fdd�|D�}d�dd�t||���D��dS)z6Return text between first and last with prompts added.csg|]	}�jj�|��qSr()r_Zline_prompts�get)r�r'r�r(r)r��s��z+PyShell.get_prompt_text.<locals>.<listcomp>rqcss.�|]\}}|dur|n|�d|��VqdS)N� r()r�rbrr(r(r)�	<genexpr>�s
��
�z*PyShell.get_prompt_text.<locals>.<genexpr>)rCr{r�rfrgrK�zip�
splitlines)r>�firstZlastrCZlineno_rangeZpromptsr(r�r)�get_prompt_text�s

�
�
��zPyShell.get_prompt_textcCs^|j}|�d�}|durdS|�d�}|ddkr|�d�}|��|�||�}|�|�dS)aCopy 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.
        zsel.first linestartN�sel.lastr/�0zsel.last+1line linestart)rCr]Zclipboard_clearr�Zclipboard_append)r>rhrCZselfirstZsellastZprompt_textr(r(r)ri�s	


z"PyShell.copy_with_prompts_callbackcCs|adSr<�r )r>�streamr(r(r)�set_warning_streamszPyShell.set_warning_streamcCstSr<r�r�r(r(r)�get_warning_stream�zPyShell.get_warning_streamcCsJ|jrtjdd|jd�|��dS|j��}|r|��dS|��dS)NzDon't debug nowz*You can only toggle the debugger when idler
rT)	r�rr{rC�set_debugger_indicatorrar��close_debugger�
open_debugger)r>rh�dbr(r(r)rgs�
zPyShell.toggle_debuggercCs|j��}|�d|�dS)NrX)rar�Zsetvar�r>r�r(r(r)r�'s
zPyShell.set_debugger_indicatorcCsdSr<r(r�r(r(r)rh+r�zPyShell.toggle_jit_stack_viewercCsh|j��}|r.|j�d�|��|jjrt�|jj�|��|j�	d�|j
|_|��|�
�dS)Nz[DEBUG OFF]
)rar�rr�r�rZclose_remote_debuggerr
r�r!rarbr�r�r�r(r(r)r�.s
zPyShell.close_debuggercCsX|jjr
t�|jj|�}nt�|�}|j�|�|��d|j|_	|�
�|��dS)Nz[DEBUG ON]
)rar�rZstart_remote_debuggerrZDebuggerrr�rarbr�r�)r>Zdbg_guir(r(r)r�;s
�
zPyShell.open_debuggercCs |jrdnd}|�dd|�dS)N�disabledrrbz*tack*iewer)r�Zupdate_menu_state)r>�stater(r(r)�debug_menu_postcommandGszPyShell.debug_menu_postcommandcCs|��d|_dS)�Helper for ModifiedInterpreterTN)r
r�r�r(r(r)rGKr@zPyShell.beginexecutingcCsd|_d|_|��dS)r�FN)r�rJr�r�r(r(r)rPszPyShell.endexecutingcCsD|jrtjddd|jd�}|durdS|��d|_d|_t�|�S)zExtend EditorWindow.close()zKill?z7Your program is still running!
 Do you want to kill it?�okrFFZcancelT)	r�rZaskokcancelrCr�rJrrr�)r>rr(r(r)r�Vs�
z
PyShell.closecCsV|��tr|j��|jt_|jt_|j	t_
d|_d|_d|j_
d|_t�|�dS)zEExtend EditorWindow._close(), shut down debugger and execution serverN)r�r,rarrnr�r�ror�rpr�r�rGr`rtrr�r�r(r(r)r�es
zPyShell._closecC�dS)z8Override EditorWindow method: never remove the colorizerTr(r7r(r(r)�ispythonsourceur�zPyShell.ispythonsourcecCrr<)�shell_titler�r(r(r)�short_titleyrzPyShell.short_titlezHType "help", "copyright", "credits" or "license()" for more information.cCs�|j�dd�|��trd}|j��}|s|��dSnd}tjt	_|�
dt	jt	j|j
|f�|j��|��ddl}d|_d|_dS)	Nr�rdrUFz�==== No Subprocess ====

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

zPython %s on %s
%s
%srT)rCr�r
r,rar�r�r�displayhookr�r!�version�platform�	COPYRIGHTZfocus_forcer��tkinterZ_support_default_rootZ
_default_root)r>ZnosubZclientr�r(r(r)r�s(
��
z
PyShell.begincCs|jsdSd|_|j��dS�NT)�reading�_stop_readline_flagr��quitr�r(r(r)r��szPyShell.stop_readlinecCs�|j}z
d|_|j��W||_n||_w|jrd|_dS|j�dd�}t|�dkr,d}|��|jr:d|_t	s:t
�|jrBd|_d}|S)NTFrUr�r�rrq)r�r��mainloopr�rCr{r�r
rJr,r�	endoffile)r>r6rr(r(r)�readline�s(zPyShell.readlinecCr�r�r(r�r(r(r)�isatty�r�zPyShell.isattycCs�z
|j�ddd�rWdSWnY|js(|js(|��|j�d�|��dSd|_d|_	|jrE|jj
rE|j��r@|j��n|j�
�|jrM|j��dS)N�	sel.firstz!=r�zKeyboardInterrupt
rTFT)rCr�r�r�r
rar!r�r�rJr�r�r�rr�r�r�r(r(r)re�s(�


zPyShell.cancel_callbackcCsh|jr|jsdS|j�ddd�r|j�ddd�sdS|js'|��|��dSd|_d|_|j�	�dS)Nr�z==rdr�FTrT)
r�r�rCr�r
r�rJr�r�r�r�r(r(r)rf�s��
zPyShell.eof_callbackcCs2|jr|j�dd�|j�d�dS|�|�dS)NrdrqrT)r�rCrd�see�newline_and_indent_eventr�r(r(r)rd�s
�zPyShell.linefeed_callbackc	Cs|jr|jsdSz|j�dd�}|r#|j�ddd�r#|�||�WdSWnY|j�ddd��r|j�d	d�}|r�|j�dd|d
�r�d|j�d�vr�|j�dd�}|rj|j�|d
d|d
�rj|d
|d
f}|j�dd�}|r�|j�|d
d|d
�r�|d
|j�	|d
d�f}|�|j�|d
|d
�|�dS|j�d	d�}|r�|j�dd|d
�r�|j�dd�}|r�|j�|d
d|d
�r�|d
|j�	|d
d�f}|�|j�|d
|d
�|�dS|j�dd�}|�r	|j�|d
dd��r	|�|j�|d
d�|�dS|�|j�dd�|�dS|j�ddd��r&|j�
dd�|j�dd�}|�r<|���s<|j�dd�|j�ddd��rL|�
|�dS|j�
dd�|j�re|j�dd�|j�d�n|�
|�|j��|j�rz|j��dS|��dS)Nr�r�z<=r�rTrdr��iomark linestartr�rr�z>=rz+1czinsert lineendrir�zend-1c linestartrq)r�r�rCr{r��recallZ
tag_prevrangeZ	tag_namesZ
tag_nextranger]r��stripr�r�rdr�Zupdate_idletasksr�r��runit)	r>rh�sel�prevZ	prev_consZ	next_cons�next�indicesr�r(r(r)rc�sx�����



�zPyShell.enter_callbackc	Cslt�dd|�}t�dd|�}|�d�}|j��z�|j�ddd�|j�dd	�|j�d
d�}|���	d�rB|�
|�|j�d
d�}|j�d|d��|j
�t|�d
kr�t�d|d��d�}t�d|��d�}|d
d�D],}|�|�r�||t|�d�}|j�dd|��|j
�qoW|j�d�|j��dSW|j�d�|j��dS|j�d�|j��w)Nz^\s*\nrUz\n\s*$rqr�rlr�rdr�ri�:rrz	^([ \t]*))�re�subr6rCZundo_block_startrkr�r{�rstrip�endswithr�rdr��user_input_insert_tagsr��search�grouprvr�Zundo_block_stop)r>r�rhr}�prefixZorig_base_indentZnew_base_indentrr(r(r)r�6s>


�
��
��zPyShell.recallz[ \t]*(\n[ \t]*)?\ZcCsj|j�d�}|j�dd�}|j�d|�}|j�|�}|s3|j�|�dkr,|j�|j|�|j	�
�dSdS)N�end-2cr�r�rUrq)rCr]r{�_last_newline_rer�rar4rkr�r_�update_sidebar)r>Zindex_beforerZinput_is_completer(r(r)r�Ss�z
PyShell.runitcCsZ|jjr	|j��SztjWntjdd|jd�YdSddlm	}||j
|j�dS)NzNo stack tracez@There is no stack trace yet.
(sys.last_traceback is not defined)r
r)�StackBrowser)rar�rr��last_tracebackrr{rCZidlelib.stackviewerr�rzrG)r>rhr�r(r(r)rA_s

�zPyShell.open_stack_viewercCs|j�d�|j�d�dS)Nr�r�)rCr�r�r(r(r)rjmszPyShell.view_restart_markcCs|jjdd�dS)z&Callback for Run/Restart Shell Cntl-F6Tr�N)rar�r�r(r(r)rkqszPyShell.restart_shellcCs||��|j}|jr|�|j�r|dt|j��}|j�dd�|j�|�|j	�
�|j�dd�|��|j
��dS)Nr�z	iomark-1crdr�)r
rbrar�r�rCr\r�r!r_r�r��set_line_and_columnrMZ
reset_undo)r>rbr(r(r)r�us
zPyShell.showpromptcCsP|jjj}t|ddd�}d�|�|��}|�d�s|d7}|jj�	d|d�dS)N�T)r��tabsizeZexpand_tabsrqr�r�)
rar�r�rrKrWr�ruZbottomrd)r>r9r��wrapperZwrapped_msgr(r(r)�show_warning�s

zPyShell.show_warningcCsb|j�dd�}|jr|j�|�|j�d�dkr|j�dd�|j�dd�|��|j��dS)Nr�r�r�rq)	rCr{rtZstorerdr�r�ZctipZremove_calltip_window)r>r(r(r(r)r
�szPyShell.resetoutputr(cCsRz|j�dd�t�|||d�}|j�dd�Wn�|jr'd|_ts't�|S)Nr��rightr�F)rCr�rr!rJr,r)r>r�r��countr(r(r)r!�sz
PyShell.writecs:z
|j�ddd�rWdSWn
tyYdSwt���S)Nr�r�r�r�)rCr�r�r�rPr�r�r(r)rP�s��
zPyShell.rmenu_check_cutcs|j�ddd�r
dSt���S)Nrdr�r�r�)rCr�r�rSr�r�r(r)rS�s
zPyShell.rmenu_check_pastecCs|j��|j��dSr<)rlZsqueeze_current_textr_r�r�r(r(r)rm�s
z"PyShell.squeeze_current_text_eventcCs|j��dSr<)r_r�)r>r]rCr�r(r(r)�on_squeezed_expand�szPyShell.on_squeezed_expandr<)r()Or�r�r�Zidlelib.squeezerrMr
r�r�rr�rr\rr�r�r3�	itertools�	takewhileZ_idxrdZallow_line_numbersr�Zidlelib.historyrQZidlelib.sidebarrRrBrvrwryrzr�rir�r�rJr�rr�r�r�rgr�rhr�r�r�rGrr�r�r�r�r�r�r�r�r�rerfrdrcr�r�r�r�r�rArjrkr�r�r
r!rPrSrmr�r�r(r(r�r)r�Us�

�

�
N



�
	O






r�c
Cs6|jdkrdD]}|�|dd|�|d��qdSdS)z6Make paste replace selection on x11.  See issue #5124.Zx11)ZTextZEntryZSpinboxz	<<Paste>>z%catch {%W delete sel.first sel.last}
N)Z_windowingsystemZ
bind_class)rz�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
sJddl}ddlm}ddlm}ddlm}td�dad}d}d}d}d}d}	z|�tj	dd�d�\}
}Wn#|j
yZ}ztd	|tftj
d
�t�d�WYd}~nd}~ww|
D]d\}
}|
dkri|}d}|
d
krqd}d}|
dkrwd}|
dkr�tj�t�t��|
dkr�d}|
dkr�tdtj
d
�da|
dkr�|}tj�|�r�n	td|�t��d}|
dkr�d}	d}|
dkr�|t_d}q]|r�|ddkr�tj��}d}tttj��D]}tj�tj|�tj|<q�|r�|ddkr�dg|dd�t_	nU|�rdg|t_	nK|�r|g|t_	nA|�r>d}g}|D]}|�tj�|���q|D]}tj�|�}|tjv�r;tj�d|��q&nt��}|tjv�rOtj�d|�tj ddddd�}|�p\|}|�pb|}t�rl|�slt!�t"dd�a#t#�$�dd l%m&}|t#�tj�'tj�t(�d!��|�d"k�r�tj�'�d#�}t#j)|d$�n-|�*��s�t+d%k�r�d&�d'}nd(�d)}��fd*d+�|D�}d,d+�|D�}t#j,dg|�R�t-t#�t.t#�t/t#�a0|�1t#t0�|�r|�s|�s|dd�D]}t0�2|�du�r�|�3|��q�|�st0�4�|�rt0�5�}|�sdS|�*��rt0j6�r|j7�8�nt0j9}|�r)|�:�|	�rItj;�<d-��p8tj;�<d.�}|�rItj�|��rI|j=�>|�|�sO|�rs|j=�?d/tj	f�|�rc|j=�@|�n,|�rr|j=�A|�|j=�>|�n|�r�|�Bt#�}|�r�|�C|�|�D�}|�r�|�C|�t0jE�r�t#�F�t0jE�s�t#�G�td�dS)0Nr)�system)�testing)�macosxTFrzc:deihnr:st:zError: %s
%srr�r�z-dz-ez-hz-iz-nz: Warning: running IDLE without a subprocess is deprecated.z-rzNo script file: z-sz-t�-rUr�r�zeditor-on-startupr�)r�ZIdle)Z	classNamerZIconsZWindowszidle.ico)r�g333333!@z.png)�� �0�z.gif)r�r�r�cs"g|]
}tj��d|�f��qS)z	idle_%d%s)rIrJrK)r��size�ZextZicondirr(r)r�bs�zmain.<locals>.<listcomp>cSsg|]}tt|d��qS))Zmasterr)Z
PhotoImagerz)r��iconfiler(r(r)r�ds�ZIDLESTARTUPZ
PYTHONSTARTUPzbif 1:
            import sys as _sys
            _sys.argv = %r
            del _sys
            
)H�getoptr�r�r!r�r�r.r,r��argv�errorr�	usage_msgr��exitr�r!rIrJr�r�r�r�r+r�r�r-r_�dirnamerd�getcwdrr�Z
NoDefaultRootr]rzr^�idlelib.runr	rK�__file__Z
wm_iconbitmapZisAquaTk�	TkVersionZwm_iconphotorr�r�rGZsetupApprtrj�newrH�dictr��lowerr`r��environr{rar&rr)r8ZtkVersionWarningr�ZpreferTabsPreferenceWarningZinversedictr�Zdestroy)r�r�r�r�Zenable_shellZenable_editrb�cmdZscriptZstartupZoptsrOr9�o�ar�Zpathxr&�dirZ
edit_startr	r�ZsizesZ	iconfilesZiconsrSZtkversionwarningZprefer_tabs_preference_warningr(r�r)r��s6���
�
���



��
�
�
���


�r�)NN)Xr�r�r�r��ImportErrorrrrIr�ZctypesZPROCESS_SYSTEM_DPI_AWAREZOleDLLZSetProcessDpiAwarenessr"r#rr�r]rzr^r�r	r{r2rr�r1rIZos.pathr
r�r�r��textwraprr�r�r*r,Zidlelib.colorizerrZidlelib.configrZidlelib.delegatorrr!rrZidlelib.editorrrZidlelib.filelistrZidlelib.outwinrrrrrrZidlelib.undorr,r�r��eofr�r��	NameErrorr r*r+r.�
checkcacher8r9r�r�r�r�Z	RPCClientr�r�r�r�r�r�r�r(r(r(r)�<module>s���
��
�
�

�?
"0g6
6