Current File : //proc/thread-self/root/opt/alt/python34/lib64/python3.4/idlelib/__pycache__/PyShell.cpython-34.pyo
�
e fR��@sVddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlm
Z
ddlmZmZyddlTWn2ek
r�eddej�ejd�YnXddljZddlmZmZdd lmZdd
lmZddl m!Z!ddl"m#Z#dd
l$m%Z%ddl&m'Z'ddl&m(Z(ddl&m)Z)ddl&m*Z*dZ+dZ,eja-ddl.Z.ddd�Z/dddd�Z0da1dd�Z2e2d�dej3dd�Z4e4e_3Gdd�de�Z5Gdd�de�Z6Gd d!�d!e�Z7Gd"d#�d#e!�Z8Gd$d%�d%e'j9�Z:Gd&d'�d'e
�Z;Gd(d)�d)e#�Z<Gd*d+�d+e
j=�Z>Gd,d-�d-e>�Z?Gd.d/�d/e>�Z@d0ZAd1d2�ZBeCd3krHejDd3ejDd)<eB�ne2d4�dS)5�N)�InteractiveInterpreter)�python_version�system)�*zJ** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **�file�)�EditorWindow�
fixwordbreaks)�FileList)�ColorDelegator)�
UndoDelegator)�OutputWindow)�idleConf)�rpc)�Debugger)�RemoteDebugger)�
macosxSupportz 127.0.0.1cCsyd}|d||f7}|dkr;tj||�}n|j�}|r^|d|7}n|d|j|f7}|S)zFormat warnings the IDLE way.z!
Warning (from warnings module):
z File "%s", line %s
Nz %s
z%s: %s
)� linecache�getline�strip�__name__)�message�category�filename�lineno�line�s�r�4/opt/alt/python34/lib64/python3.4/idlelib/PyShell.py�idle_formatwarning0srcCsg|dkrt}ny3|jt||||d|��|jd�Wnttfk
rbYnXdS)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.
Nrz>>> )�warning_stream�writer�AttributeError�OSError)rrrrrrrrr�idle_showwarning=s r$cCsL|r*tdkrHtjatt_qHntdk rHtt_dandS)z>Replace warning.showwarning with idle_showwarning, or reverse.N)�_warnings_showwarning�warnings�showwarningr$)Zcapturerrr�capture_warningsPs r(TcCs{tj}i}xNt|�D]@}|dd�|dd�dkr|j|�||<qqW||�|j|�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.
Nrz<>���)r�cache�list�pop�update)rZorig_checkcacher*�save�keyrrr�extended_linecache_checkcache_s $
r0c@s�eZdZdZdd�Zd'd(d)d*d+d,gZddd�Zdd�Zd
dd�Zd
dd�Z dd�Z
dd�Zdd �Zd!d"�Z
d#d$�Zd%d&�Zd
S)-�PyShellEditorWindowz6Regular text edit window in IDLE, supports breakpointscGs�g|_tj||�|jjd|j�|jjd|j�|jjd|jj�t j
jtj
�d�|_|jj|dd�}|jj|�|jjr�|j�n|j�dS)Nz<<set-breakpoint-here>>z<<clear-breakpoint-here>>z<<open-python-shell>>zbreakpoints.lstcSs|j�|�dS)N)�restore_file_breaks)Zold_hook�selfrrr�filename_changed_hook�s
z;PyShellEditorWindow.__init__.<locals>.filename_changed_hook)�breakpointsr�__init__�text�bind�set_breakpoint_here�clear_breakpoint_here�flist�
open_shell�os�path�joinrZ
GetUserCfgDir�breakpointPath�ioZfilename_change_hookZset_filename_change_hookrr2�color_breakpoint_text)r3�argsr4rrrr6ys
zPyShellEditorWindow.__init__�Cut�<<cut>>�rmenu_check_cut�Copy�<<copy>>�rmenu_check_copy�Paste� <<paste>>�rmenu_check_pasteN�Set Breakpoint�<<set-breakpoint-here>>�Clear Breakpoint�<<clear-breakpoint-here>>TcCse|jdkrdS|r:tj�}tj|d�}nidd6dd6}|jjd|�dS)z,Turn colorizing of breakpoint text on or offN�break��
foreground�
background�BREAK)rAr�CurrentTheme�GetHighlightr7Z
tag_config)r3Zcolor�themeZcfgrrrrB�sz)PyShellEditorWindow.color_breakpoint_textcCs�|j}|jj}|jdd|d|d�y|jj|�Wn"tk
rl|jj|�YnXy&|jj j
j}|j||�WnYnXdS)NrUz%d.0r)
r7rAr�tag_addr5�index�
ValueError�appendr;�pyshell�interp�debuggerr9)r3rr7r�debugrrr�set_breakpoint�s
z"PyShellEditorWindow.set_breakpointcCsU|j}|jj}|s)|j�dStt|jd���}|j|�dS)N�insert)r7rAr�bell�int�floatrZra)r3�eventr7rrrrrr9�s
z'PyShellEditorWindow.set_breakpoint_herecCs�|j}|jj}|s)|j�dStt|jd���}y|jj|�WnYnX|j ddd�y&|j
jjj
}|j||�WnYnXdS)NrbrUzinsert linestartzinsert lineend +1char)r7rArrcrdrerZr5�remove�
tag_remover;r]r^r_r:)r3rfr7rrr`rrrr:�s"
z)PyShellEditorWindow.clear_breakpoint_herec Cs�|jr|j}|jj}|s2|j�dSg|_|jddt�y#|jjj j
}|j|�WqYqXndS)NrUz1.0)r5r7rArrcrhZENDr;r]r^r_�clear_file_breaks)r3r7rr`rrrri�s
z%PyShellEditorWindow.clear_file_breakscCsb|j}|jj}y+t|jd��}|j�}WdQXWntk
rZg}YnXy�t|jd��v}x1|D])}|j|d�sz|j|�qzqzW|j �|j}|r�|j|dt
|�d�nWdQXWnrtk
r]}zRt|jdd�sKd|j_
tjd d
ddt
|�d
|j�nWYdd}~XnXdS)z#Save breakpoints when file is saved�rN�w�=�
�breakpoint_error_displayedFT�titlez
IDLE Errorrz$Unable to update breakpoint list:
%s�parent)r5rAr�openr@� readlinesr#�
startswithr!�update_breakpoints�str�getattr�rootrn�tkMessageBox� showerrorr7)r3Zbreaksr�fp�linesZnew_filer�errrrr�store_file_breaks�s.
,
z%PyShellEditorWindow.store_file_breakscCs�|jj�|jdkr dS|jj}|dkr<dStjj|j�r�t|jd��}|j �}WdQXxe|D]Z}|j
|d�rt|t|�dd��}x|D]}|j
|�q�WqqWndS)Nrjrlr)r7r-rArr=r>�isfiler@rqrrrs�eval�lenra)r3rrzr{rZbreakpoint_linenumbersZbreakpoint_linenumberrrrr2s
z'PyShellEditorWindow.restore_file_breakscCs4|j}|jd�}|j|�}||_dS)z3Retrieves all the breakpoints in the current windowrUN)r7Z
tag_ranges�ranges_to_linenumbersr5)r3r7�rangesZlinenumber_listrrrrts z&PyShellEditorWindow.update_breakpointscCs�g}x�tdt|�d�D]f}tt||j��}tt||dj��}x'||kr�|j|�|d7}q^WqW|S)Nr�r)�ranger�rdre�stringr\)r3r�r{rZr�endrrrr�s
z)PyShellEditorWindow.ranges_to_linenumberscCs|j�tj|�dS)z7Extend base method - clear breaks when module is closedN)rir�_close)r3rrrr�-s
zPyShellEditorWindow._close)rDrEzrmenu_check_cut)rGrHrI)rJrKzrmenu_check_paste)NNN)rMrNN)rOrPN)r�
__module__�__qualname__�__doc__r6Zrmenu_specsrBrar9r:rir}r2rtr�r�rrrrr1vs$ *r1c@s1eZdZdZeZdZddd�ZdS)�PyShellFileListz8Extend base class: IDLE supports a shell and breakpointsNcCsQ|jr|jjj�n.t|�|_|jrJ|jj�sJdSn|jS)N)r]�top�wakeup�PyShell�begin)r3rfrrrr<<s zPyShellFileList.open_shell)rr�r�r�r1rr]r<rrrrr�3sr�c@sFeZdZdZdd�Zdd�Zdd�Zdd �Zd
S)�ModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfcCstj|�|j�dS)N)rr6�LoadTagDefs)r3rrrr6Js
zModifiedColorDelegator.__init__cCs7|jddd�|jddd�tj|�dS)NZTODOz1.0�iomarkZSYNC)rhrYr�recolorize_main)r3rrrr�Nsz&ModifiedColorDelegator.recolorize_maincCs{tj|�tj�}|jjiidd6dd6d6tj|d�d6tj|d�d6tj|d�d6�dS)NrTrS�stdin�stdout�stderr�console)rr�rrV�tagdefsr-rW)r3rXrrrr�Ss
z"ModifiedColorDelegator.LoadTagDefscCs+x$|jD]}|j|dd�q
WdS)Nr�r�)r�rh)r3�tagrrr�removecolors]sz#ModifiedColorDelegator.removecolorsN)rr�r�r�r6r�r�r�rrrrr�Gs
r�c@s4eZdZdZddd�Zddd�ZdS)�ModifiedUndoDelegatorz;Extend base class: forbid insert/delete before the I/O markNc
Cs\y-|jj|dd�r,|jj�dSWntk
rAYnXtj||||�dS)N�<r�)�delegate�comparerc�TclErrorrrb)r3rZ�chars�tagsrrrrbes
zModifiedUndoDelegator.insertcCsYy-|jj|dd�r,|jj�dSWntk
rAYnXtj|||�dS)Nr�r�)r�r�rcr�r�delete)r3Zindex1Zindex2rrrr�ns
zModifiedUndoDelegator.delete)rr�r�r�rbr�rrrrr�bs r�c@seZdZdd�ZdS)�MyRPCClientcCs
t�dS)z0Override the base class - just re-raise EOFErrorN)�EOFError)r3rrr�
handle_EOFzszMyRPCClient.handle_EOFN)rr�r�r�rrrrr�xsr�c@s�eZdZdd�ZdZdZdZdd�Zdd�Zdd �Z d
ddd
�Z
dd�Zdd�Zdd�Z
dd�Zd
dd�ZdZdd�ZdZdd�Zdd�Zdd�Zd d!�Zd"Zd#d$�Zdd%d&�Zd'd(�Zd)d*�Zd+d,�Zdd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$d=d>�Z%dS)?�ModifiedInterpretercCsf||_tjdj}tj|d|�d|_d|_d|_t |_
|jjj
|_dS)N�__main__�localsF)� tkconsole�sys�modules�__dict__rr6�save_warnings_filters�
restarting�subprocess_arglist�PORT�port�compile�compiler�flags�original_compiler_flags)r3r�r�rrrr6�s zModifiedInterpreter.__init__NcCs:|jdkr!|j�|_ntj|j�|_dS)N)r��build_subprocess_arglist�
subprocess�Popen�
rpcsubproc)r3rrr�spawn_subprocess�sz$ModifiedInterpreter.spawn_subprocesscCs�dd�tjD�}tjddddddd �}td
krSd|f}n
d|f}tjg|d
|t|j�gS)NcSsg|]}d|�qS)z-Wr)�.0rrrr�
<listcomp>�s z@ModifiedInterpreter.build_subprocess_arglist.<locals>.<listcomp>�main�Generalzdelete-exitfunc�defaultF�type�boolzidlelib.PyShellz&__import__('idlelib.run').run.main(%r)z__import__('run').main(%r)z-c)r��warnoptionsr� GetOptionr�
executablerur�)r3rkZ del_exitfZcommandrrrr��s
z,ModifiedInterpreter.build_subprocess_arglistcCs�t|jf}xXtd�D]<}tj|�yt|�|_PWqtk
rWYqXqW|j�dS|jj j
�d|_tdkr�|jj jt
jt
jd�n|j�|jj jd�y|jj�Wn#t
jk
r|j�dSYnX|jjd|j�|jjd|jj�|jjd|jj�|jjd|jj�|jjd |jj�|jjd
t�|jjd|�|jdd
�|j�|jS)N�rr�
r�r�r�r�r;rr^�with_cwdT)�HOSTr�r��timeZsleepr��rpccltr#�display_port_binding_error�listening_sockZgetsocknamer�Z
setsockopt�socketZ
SOL_SOCKETZSO_REUSEADDRr�Z
settimeout�accept�timeout�display_no_subprocess_error�registerr�r�r�r�r;r�
transfer_path�poll_subprocess)r3Zaddr�irrr�start_subprocess�s>
z$ModifiedInterpreter.start_subprocessFrRcCs�|jr|jSd|_|j�}|rMytj|j�WqMYqMXn|jj�|j�|j}|j}d|_|j �y|jj
�Wn#tjk
r�|j
�dSYnX|jd|�|j�|jjdd�d|r�|nd}t|j�t|�dd d
}|jdj||��|jjdd�|jjdd
�|sz|j�n|r�tj|j�|j�n|j|jj_d|_|jS)NTFr�r�zend-1cz RESTART: ZShell�r�rlz
{0} {1} {0}�restart�left) r�r��getdebuggerrZclose_subprocess_debugger�close�terminate_subprocessr�� executingr�r�r�r�r�r��
stop_readliner7r�rd�widthr�r!�format�mark_set�mark_gravity�
showpromptZrestart_subprocess_debugger�load_breakpointsr�r�r�r�)r3r�rr`r�Z
was_executingr�Zhalfbarrrr�restart_subprocess�sH
%
z&ModifiedInterpreter.restart_subprocesscCs|jjddfi�dS)N�execZinterrupt_the_server)r�Z
remotecall)r3rrrZ__request_interrupt�sz'ModifiedInterpreter.__request_interruptcCstjd|j�j�dS)N�target)� threadingZThread�'_ModifiedInterpreter__request_interrupt�start)r3rrr�interrupt_subprocess�sz(ModifiedInterpreter.interrupt_subprocesscCs�|jdk r(|jjj|j�ny|jjj�Wntk
rPYnXy|jj�Wntk
rvYnX|j�d|j_ d|_dS)NF)
�_afteridr�r7Zafter_cancelr�r�r�r"r�r�)r3rrr�kill_subprocesss
z#ModifiedInterpreter.kill_subprocesscCsXy|jj�Wntk
r)dSYn+Xy|jj�Wntk
rSdSYnXdS)z"Make sure subprocess is terminatedN)r��killr#�wait)r3rrrr�s
z(ModifiedInterpreter.terminate_subprocesscCsC|r"dg}|jtj�n tj}|jd|f�dS)NrRzRif 1:
import sys as _sys
_sys.path = %r
del _sys
)�extendr�r>�
runcommand)r3r�r>rrrr�s z!ModifiedInterpreter.transfer_pathcCs�|j}|dkrdSy|j|jdd�}Wn;tttfk
rr|jjr^dSd}|j�YnX|rp|jj �d|_|\}}|jj
}|dkr�|dk rGtt|�d|�qGnl|dkr |jj
d�rG|j�qGn>|dkrGd}t||dtj�t||d|�ny|jj�Wqptk
rlYqpXn|jjs�|jjj|jj|j�|_ndS) Nr�g�������?ZOKrZ EXCEPTIONz<<toggle-jit-stack-viewer>>�ERRORz/PyShell.ModifiedInterpreter: Subprocess ERROR:
)r�Zpollresponse�
active_seqr�r#�KeyboardInterruptr��closingr��resetoutputr��print�repr�getvar�remote_stack_viewerr��
__stderr__�endexecutingr"r7�after�pollintervalr�r�)r3Zclt�responseZhowZwhatr��errmsgrrrr�,s@
z#ModifiedInterpreter.poll_subprocesscCs
||_dS)N)r_)r3r_rrr�setdebuggerTszModifiedInterpreter.setdebuggercCs|jS)N)r_)r3rrrr�WszModifiedInterpreter.getdebuggercCs|jjjd|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�r7r�r�)r3rrr�open_remote_stack_viewerZs
z,ModifiedInterpreter.open_remote_stack_viewercCs�ddlm}|jjdddi�}|dkrK|jjj�dS|j|j|�}ddlm }m
}t|jj�}tj
�}tj|d�d}||d |d
d�} | jjddd
d�|| jd|�}
|
j�dS)Nr)�RemoteObjectBrowserr�Zstackviewerr;)�ScrolledCanvas�TreeNodeZnormalrTZbgZhighlightthickness�expandrZfillZboth)zflist)�idlelibrr��remotequeuer�rwrcZStubObjectTreeItemZidlelib.TreeWidgetrrZToplevelrrVrWZframeZpackZcanvasr)r3rZoid�itemrrr�rXrTZscZnoderrrr�gsz'ModifiedInterpreter.remote_stack_viewerrcCs#|j|�}|j||�dS)z1Like runsource() but assumes complete exec sourceN)�stuffsource�execfile)r3�sourcerrrr�
execsourcezszModifiedInterpreter.execsourcecCs�|dkr3tj|��}|j�}WdQXnyt||d�}WnXttfk
r�|jj�tdd|jj �t
j||�|jj�YnX|j
|�dS)zExecute an existing fileNr�zB*** Error in script or command!
Traceback (most recent call last):r)�tokenizerq�readr��
OverflowError�SyntaxErrorr�r�r�r�r�showsyntaxerrorr��runcode)r3rrrz�coderrrr
s
zModifiedInterpreter.execfilec
Cs�|j|�}d|_tjdd�|_tjdddt�ztj|||�SWd|jdk r�|jtjdd�<d|_nXdS)zBExtend base class method: Stuff the source in the line cache firstrN�action�errorr) r Zmorer&�filtersr��filterwarnings�
SyntaxWarningr� runsource)r3rrrrrr�s zModifiedInterpreter.runsourcecCsSd|j}|jd|_|jd�}t|�dd||ftj|<|S)z"Stuff source in the filename cachez<pyshell#%d>rrmr)�gid�splitr�rr*)r3rrr{rrrr �s
#zModifiedInterpreter.stuffsourcecCs|jd|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�)r3rrrr�prepend_syspath�sz#ModifiedInterpreter.prepend_syspathcCs|j}|j}|jddd�tj�\}}}t|dd�pU|pUd}t|dd�pmd}t|d d�p�d
} | d
kr�|d7}n|dkr�d| d}
nd|d| df}
|j||
�|j�|jd
|�|j �dS)z�Override Interactive Interpreter method: Use Colorizing
Color the offending position instead of printing it and pointing at it
with a caret.
r�z1.0r��msgrRz<no detail available>rr�offsetrziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
N)
r�r7rhr��exc_inforvZcolorize_syntax_errorr�r!r�)r3rr�r7r��value�tbrrr�posrrrr�s"
z#ModifiedInterpreter.showsyntaxerrorcCsJ|jj�|j�tj|�|jjd�rF|jj�ndS)z1Extend base class method to reset output properlyz<<toggle-jit-stack-viewer>>N)r�r��checklinecacher�
showtracebackr��open_stack_viewer)r3rrrr$�s
z!ModifiedInterpreter.showtracebackcCsXtj}xHt|j��D]4}|dd�|dd�dkr||=qqWdS)Nrz<>r))rr*r+�keys)r3�cr/rrrr#�s $z"ModifiedInterpreter.checklinecachecCsV|jjr|j�dS|jrB|jjdd|fi�nt||j�dS)z*Run the code without invoking the debuggerrr�rr)r�r��display_executing_dialogr�rr�r�)r3rrrrr��s
zModifiedInterpreter.runcommandcCs�|jjr|jj�n|j�|jdk rW|jtjdd�<d|_n|j}zNyw|jj �|r�|j
dk r�|j
jdd|fi�|_n,|r�|j
||j�nt||j�Wn�tk
r4|jjs-tjddddd|jj�r �q0|j�n�Ynytrmtd d
|jj�|j�|jj�n;|jjr�d|j_tdd
|jj�n
|j�YnXWdts�y|jj�Wq�tk
r�Yq�XnXdS)
zOverride base class methodNr�rzExit?zDo you want to exit altogether?r��yesrpz IDLE internal error in runcode()rFr�)r�r�r^r�r#r�r&rr_�beginexecutingr�Z
asyncqueuer�Zrunr�r��
SystemExitr�rxZaskyesnor7r$�use_subprocessr�r�r��canceledr")r3rr_rrrr�sP
zModifiedInterpreter.runcodecCs|jjj|�S)zOverride base class method)r�r�r!)r3rrrrr!"szModifiedInterpreter.writecCs tjddd|jj�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.rp)rxryr�r7)r3rrrr�&sz.ModifiedInterpreter.display_port_binding_errorcCs tjddd|jj�dS)NzSubprocess Startup Errorz�IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.rp)rxryr�r7)r3rrrr�1sz/ModifiedInterpreter.display_no_subprocess_errorcCs tjddd|jj�dS)NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.rp)rxryr�r7)r3rrrr(9sz,ModifiedInterpreter.display_executing_dialog)&rr�r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r_rr�rr�rrr
rr rrr$r#r�rr!r�r�r(rrrrr�sF
+-
&
1r�cs/eZdZde�dZeZeZdVdWdXdYdZd[gZ ddl
mZddd�Zdd�Z
dZdZdZdZdZdZdd�Zdd�Zddd�Zdd�Zddd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1Z!d2d3�Z"d4d5�Z#d6d7�Z$d8d9�Z%dd:d;�Z&d<d=�Z'd>d?�Z(d@dA�Z)dBdC�Z*dDdE�Z+ddFdG�Z,ddHdI�Z-ddJdK�Z.dLdM�Z/dNdO�Z0fdPdQ�Z1�fdRdS�Z2�fdTdU�Z3�S)\r�zPython z Shellr�_File�edit�_Editr`�_Debug�options�_Options�windows�_Window�help�_Helpr)�HistoryNc Cs�tr9|j}|dddkr9|jdd�q9nt|�|_|dkr�t�}t|�|j�t|�}nt j
||dd�d|_d|_d|_
|j}|jdd�|jd |j�|jd
|j�|jd|j�|jd|j�|jd
|j�|jd|j�|jd|j�tr~|jd|j�|jd|j�ntj|_tj|_tj|_ ddl!m"}t#|d|j$�|_t%|d|j$�|_t%|d|j$�|_t%|d|j$�|_&ts?|jt_|jt_|jt_nyddl'}|j(|_)Wntj*t_�YnX|j+|j�|_,d|_-dS)Nr�r�shell�She_llT�Zwrap�charz<<newline-and-indent>>z<<plain-newline-and-indent>>z<<interrupt-execution>>z<<end-of-file>>z<<open-stack-viewer>>z<<toggle-debugger>>z<<toggle-jit-stack-viewer>>z<<view-restart>>z<<restart-shell>>)� IOBindingr�r�r�r��2)zshellr:).r,�
menu_specsrbr�r^�Tkr �withdrawr�r
r6ZusetabsZindentwidthZcontext_use_ps1r7Z configurer8�enter_callback�linefeed_callback�cancel_callback�eof_callbackr%�toggle_debugger�toggle_jit_stack_viewer�view_restart_mark�
restart_shellr�r��save_stdoutr��save_stderrr��
save_stdinrr=�PseudoInputFile�encoding�PseudoOutputFiler��pydocZ
plainpagerZpagerr�r8�historyr�)r3r;Zmsrwr7r=rPrrrr6Ws\
zPyShell.__init__cCstjdd�S)NZ
shell_onlyT)rZ
GetExtensions)r3rrr�get_standard_extension_names�sz$PyShell.get_standard_extension_namesFcCs
|adS)N)r )r3�streamrrr�set_warning_stream�szPyShell.set_warning_streamcCstS)N)r )r3rrr�get_warning_stream�szPyShell.get_warning_streamcCs`|jr0tjddd|j�|j�dS|jj�}|rR|j�n
|j�dS)NzDon't debug nowz*You can only toggle the debugger when idlerprQ) r�rxryr7�set_debugger_indicatorr^r��close_debugger�
open_debugger)r3rf�dbrrrrF�s
zPyShell.toggle_debuggercCs%|jj�}|jd|�dS)Nz<<toggle-debugger>>)r^r�Zsetvar)r3rYrrrrV�szPyShell.set_debugger_indicatorcCsdS)Nr)r3rfrrrrG�szPyShell.toggle_jit_stack_viewercCs�|jj�}|r�|jjd�|j�|jjrQtj|jj�n|j�|jj d�dt
_|j�n|j
�dS)Nz[DEBUG OFF]
z>>> )r^r�rr�r�rZclose_remote_debuggerr�r�r!r��ps1r�rV)r3rYrrrrW�s
zPyShell.close_debuggercCsq|jjr'tj|jj|�}ntj|�}|jj|�|j�dt_|j �|j
�dS)Nz[DEBUG ON]
>>> )r^r�rZstart_remote_debuggerrrr�r�rZr�rV)r3Zdbg_guirrrrX�s
zPyShell.open_debuggercCs|j�d|_dS)zHelper for ModifiedInterpreterrN)r�r�)r3rrrr*�s
zPyShell.beginexecutingcCs d|_d|_|j�dS)zHelper for ModifiedInterpreterrN)r�r-r�)r3rrrr��s zPyShell.endexecutingcCsf|jr=tjddddd|j�}|dkr=dSn|j�d|_d|_tj|�S) zExtend EditorWindow.close()zKill?z7Your program is still running!
Do you want to kill it?r��okrpFZcancelT) r�rxZaskokcancelr7r�r-r�rr�)r3r�rrrr��s
z
PyShell.closecCs||j�tr |jj�n|jt_|jt_|j t_
d|_d|_d|j_
d|_tj|�dS)zEExtend EditorWindow._close(), shut down debugger and execution serverN)rWr,r^r�rJr�r�rKr�rLr�r�r;r]rQrr�)r3rrrr��s
zPyShell._closecCsdS)z8Override EditorWindow method: never remove the colorizerTr)r3rrrr�ispythonsource�szPyShell.ispythonsourcecCs|jS)N)�shell_title)r3rrr�short_title�szPyShell.short_titlez@Type "copyright", "credits" or "license()" for more information.cCs�|jjdd�|j�trOd}|jj�}|sm|j�dSndddd}tjt _|j
d t jt j|j
|f�|jj�|j�d
dl}d|_dS)Nr�rbrRFz==== No Subprocess ====
z9WARNING: Running IDLE without a Subprocess is deprecated
z;and will be removed in a later version. See Help/IDLE Help
zfor details.
zPython %s on %s
%s
%srT)r7r�r�r,r^r�r�r�displayhookr�r!�version�platform� COPYRIGHTZfocus_forcer��tkinterZ
_default_root)r3ZnosubZclientrcrrrr�s$
z
PyShell.begincCs'|js
dSd|_|jj�dS)NT)�reading�_stop_readline_flagr��quit)r3rrrr�s zPyShell.stop_readlinecCs�|j}zd|_|jj�Wd||_X|jrFd|_dS|jjdd�}t|�dkrvd}n|j�|jr�d|_t s�t
�q�n|jr�d|_d}n|S)NrFrRr�zend-1crrm)rdr��mainlooprer7�getr�r�r-r,r�� endoffile)r3r.rrrr�readline"s(
zPyShell.readlinecCsdS)NTr)r3rrr�isatty9szPyShell.isattyc
Cs�y |jjddd�rdSWnYnX|jp:|jse|j�|jjd�|j�dSd|_d|_ |jr�|jj
r�|jj�r�|jj�q�|jj
�n|jr�|jj�ndS)Nz sel.firstz!=zsel.lastzKeyboardInterrupt
rQrr)r7r�r�rdr�r^r!r�rir-r�r�r�r�r�rf)r3rfrrrrD<s&
zPyShell.cancel_callbackcCs�|jr|jrdS|jjddd�oD|jjddd�sKdS|jsk|j�|j�nd|_d|_|jj �dS)Nr�z==rbzend-1crrrQ)
r�rdr7r�r�r�r-rir�rf)r3rfrrrrERs
zPyShell.eof_callbackcCs@|jr/|jjdd�|jjd�n
|j|�dS)NrbrmrQ)rdr7rb�see�newline_and_indent_event)r3rfrrrrCas
zPyShell.linefeed_callbackcCs�|jr|jrdSyN|jjdd�}|rd|jjddd�rd|j||�dSnWnYnX|jjddd�r�|jjd d�}|r�|jjdd|d
�r�|j|jj|d|d
�|�dS|jjd d�}|rL|jjdd
|d�rL|j|jj|d|d
�|�dS|jjdd�}|r�|jj|ddd�r�|j|jj|d
d�|�n|j|jjdd�|�dS|jjddd�r�|jjdd�n|jjdd�}|r8|j �r8|jj
dd�n|jjddd�ra|j|�dS|jjdd�|jr�|jjdd�|jj
d�n
|j|�|jjd dd�|jj�|jr�|jj�n
|j�dS)Nz sel.firstzsel.lastz<=r�rQrbr�ziomark linestartr�rrzinsert lineendz>=r�zinsert linestartzend-1czend-1c linestartrm)r�rdr7rhr��recallZ
tag_prevrangeZ
tag_nextranger�rr�rmrbrlrYZupdate_idletasksr�rf�runit)r3rf�sel�prev�next�indicesrrrrrBjsX"'"'&
zPyShell.enter_callbackcCs�tjdd|�}tjdd|�}|jd�}|jj�zL|jjddd�|jjdd �|jjd
d�}|j�j d�r�|j
|�|jjd
d�}n|jjd|dj��t
|�d
kr�tjd|d�jd�}tjd|�jd�}xd|d
d�D]O}|j|�rm||t
|�d�}n|jjdd|j��q;WnWd|jjd�|jj�XdS)Nz^\s*\nrRz\n\s*$rmrpz1.0r�rbzend-1czinsert linestart�:rrz ^([ \t]*))�re�subrr7Zundo_block_startrhr�rh�rstrip�endswithrmrbrr��search�grouprsrlZundo_block_stop)r3rrfr{�prefixZorig_base_indentZnew_base_indentrrrrrn�s*
(zPyShell.recallcCs�|jjdd�}t|�}x.|dkrQ||ddkrQ|d}q$W|dkr||ddkr|d}nx.|dkr�||ddkr�|d}q�W|d|�}|jj|�dS)Nr�zend-1crrz rm)r7rhr�r^r)r3rr�rrrro�s#
#z
PyShell.runitcCss|jjr|jj�SytjWn%tjddd|j�dSYnXddlm }||j
|j�dS)NzNo stack tracez@There is no stack trace yet.
(sys.last_traceback is not defined)rpr)�StackBrowser)r^r�r�r��last_tracebackrxryr7Zidlelib.StackViewerr|rwr;)r3rfr|rrrr%�s
zPyShell.open_stack_viewercCs$|jjd�|jjd�dS)Nr�r�)r7rl)r3rfrrrrH�szPyShell.view_restart_markcCs|jjdd�dS)z&Callback for Run/Restart Shell Cntl-F6r�TN)r^r�)r3rfrrrrI�szPyShell.restart_shellc Csl|j�yttj�}Wnd}YnX|jj|�|jjdd�|j�|j j
�dS)NrRrbzend-1c)r�rur�rZr�r!r7r��set_line_and_columnrAZ
reset_undo)r3rrrrr��s
zPyShell.showpromptcCs�|jjdd�}|jr1|jj|�n|jjd�dkr_|jjdd�n|jjdd�|j�dS)Nr�zend-1czend-2crm)r7rhrQZstorerbr�r~)r3rrrrr��s zPyShell.resetoutputcCs�t|t�ryt|�ryt|�dkryx*t|�D]\}}|dkr:Pq:q:Wtd|||dd��nyB|jjdd�tj |||d�}|jjdd�Wn�YnX|j
r�d|_
ts�t�q�n|S) NuzUCS-2rz%Non-BMP character not supported in Tkr��rightr�r)
�
isinstancerur��max� enumerate�UnicodeEncodeErrorr7r�r
r!r-r,r�)r3rr�r�r<�countrrrr!�s"- z
PyShell.writecsFy |jjddd�rdSWntk
r8dSYnXt�j�S)Nz sel.firstr�r��disabled)r7r�r��superrF)r3)� __class__rrrFs
zPyShell.rmenu_check_cutcs)|jjddd�rdSt�j�S)Nrbr�r�r�)r7r�r�rL)r3)r�rrrLszPyShell.rmenu_check_paste)zfiler.)r/r0)zdebugr1)r2r3)r4r5)zhelpr7)4rr�r�rr]r�rr�rr?Zidlelib.IdleHistoryr8r6rRrdr�r-rir�rerTrUrFrVrGrWrXr*r�r�r�r\r^rbr�r�rjrkrDrErCrBrnror%rHrIr�r�r!rFrLrr)r�rr�Asd :
? r�c@sOeZdZddd�Zedd��Zedd��Zdd �ZdS)
�
PseudoFileNcCs||_||_||_dS)N)r9r�� _encoding)r3r9r�rNrrrr6"s zPseudoFile.__init__cCs|jS)N)r�)r3rrrrN'szPseudoFile.encodingcCsd|jS)Nz<%s>)r�)r3rrr�name+szPseudoFile.namecCsdS)NTr)r3rrrrk/szPseudoFile.isatty)rr�r�r6�propertyrNr�rkrrrrr� sr�c@s(eZdZdd�Zdd�ZdS)rOcCsdS)NTr)r3rrr�writable5szPseudoOutputFile.writablecCs}|jrtd��nt|�tk rgt|t�sUtdt|�j��ntj|�}n|jj ||j
�S)Nzwrite to closed filezmust be str, not )�closedr[r�rur�� TypeErrorr�__str__r9r!r�)r3rrrrr!8s zPseudoOutputFile.writeN)rr�r�r�r!rrrrrO3srOc@sUeZdZddd�Zdd�Zd
dd�Zdd d
�Zdd�ZdS)rMNcCs#tj||||�d|_dS)NrR)r�r6�_line_buffer)r3r9r�rNrrrr6EszPseudoInputFile.__init__cCsdS)NTr)r3rrr�readableIszPseudoInputFile.readablercCs|jrtd��n|dkr-d}n+t|t�sXtdt|�j��n|j}d|_|dkr�x�|jj �}|s�Pn||7}qyWn_x9t
|�|kr�|jj �}|s�Pn||7}q�W||d�|_|d|�}|S)Nzread from closed filerzmust be int, not rRrr))r�r[r�rdr�r�rr�r9rjr�)r3�size�resultrrrrrLs, zPseudoInputFile.readcCs�|jrtd��n|dkr-d}n+t|t�sXtdt|�j��n|jpm|jj �}|dkr�t
|�}n|jdd|�}|dkr�|d}n||d�|_|d|�S)Nzread from closed filerzmust be int, not rrmr))r�r[r�rdr�r�rr�r9rjr��find)r3r�rZeolrrrrjcs
zPseudoInputFile.readlinecCs|jj�dS)N)r9r�)r3rrrr�sszPseudoInputFile.closer)r))rr�r�r6r�rrjr�rrrrrMCs
rMa�
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].
cs�td�dad}d}d}d}d}d}y)tjtjdd�d�\}}WnRtjk
r�}z/td|tfdtj�tj d�WYdd}~XnXxE|D]=\} }
| dkr�|
}d}n| d kr�d}d}n| d
krd}n| dkr9tj
jt�tj �n| dkrNd}n| d
krvtddtj�dan| dkr�|
}tj
j|�r�ntd|�tj �d}n| dkr�d}d}n| dkr�|
t_d}q�q�W|r(|ddkr(tjj�}d}nx=tttj
��D]&}tj
jtj
|�tj
|<q>W|r�|ddkr�dg|dd�t_n�|r�dg|t_n�|r�|g|t_n�|rTd}g}x'|D]}
|jtj
j|
��q�Wxy|D]=}tj
j|�}|tj
krtj
jd|�qqWn1tj�}|tj
kr�tj
jd|�ntjddddd�}|p�|}|p�|}tdd�atj
jtj
jt�d��t �dkr tj
j�d�}tj!d |�nft"d!kr�t"d"kr>d#nd$���fd%d&�d3D�}d*d&�|D�}tj#d|�nt$t�tj%�t&t�a't(j)tt'�t(j*�r�tj+d+d,�tj+d+d-�tj+d+d.�n|r`|p|s`x=|dd�D]+}
t'j,|
�dkr|j-|
�qqW|s]t'j.�q]q`n|r�t'j/�}|s|dSt(j*�r�t'j0r�|j1j2�q�n t'j3}|r�|j4�n|rtj5j6d/�p�tj5j6d0�}
|
rtj
j|
�r|j7j8|
�qn|s$|r�|j7j9d1tjf�|rW|j7j:|�q�|r�|j7j;|�|j7j8|�q�n5|r�t(j<t�}|r�|j7j9d2|�q�nxt'j=r�tj>�q�Wtj?�td�dS)4NTFrzc:deihnr:st:zError: %s
%srr�z-cz-dz-ez-hz-iz-nz: Warning: running IDLE without a subprocess is deprecated.z-rzNo script file: z-sz-tr�-rRr�r�zeditor-on-startupr�r�Z classNameZIdleZIconsZWindowszidle.icor�g!@g333333!@z.pngz.gifcs/g|]%}tjj�d|�f��qS)z idle_%d%s)r=r>r?)r�r�)�ext�icondirrrr�s zmain.<locals>.<listcomp>�� �0cSsg|]}td|��qS)r)Z
PhotoImage)r��iconfilerrrr�s ZTextz<B2>z<B2-Motion>z<<PasteSelection>>ZIDLESTARTUPZ
PYTHONSTARTUPzbif 1:
import sys as _sys
_sys.argv = %r
del _sys
zprint('%s'))r�r�r�)@r(r,�getoptr��argvrr�� usage_msgr��exitr�r!r=r>r~r�r]r�rr�r��abspathr\�dirnamerb�getcwdrr�r@rwr?�__file__rZ
wm_iconbitmapZ TkVersionZwm_iconphotor rAr�r;rZsetupAppZisAquaTkZunbind_classrqrg�newr<�dictr��lowerr]rX�environrhr^r
r�rrZtkVersionWarningZinversedictrgZdestroy)Zenable_shellZenable_editr`�cmdZscriptZstartupZoptsrCr�o�ar�Zpathxr�dirZ
edit_startr�Z iconfilesZiconsr9Ztkversionwarningr)r�r�rr��s�
)
$
!
r�r�F)Er�r=Zos.pathrur�r�r�r�r�r
rArrrrarrrc�ImportErrorr�r�r�Ztkinter.messageboxZ
messageboxrxZidlelib.EditorWindowrr Zidlelib.FileListr
Zidlelib.ColorDelegatorrZidlelib.UndoDelegatorrZidlelib.OutputWindowr
Zidlelib.configHandlerrrrrrrr�r�r r&rr$r%r(�
checkcacher0r1r�r�r�Z RPCClientr�r�r��
TextIOBaser�rOrMr�r�rr�rrrr�<module>sx
�����h�