� e fR�� @sVddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZyddlTWn2ek r�eddej�ejd�YnXddljZddlmZmZdd lmZdd lmZdd l m!Z!dd l"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�de j3dd�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_formatwarning0s  rcCsg|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�Z dd �Z d!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 j t j �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�s z)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 j j j }|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 |j dd�sKd|j _ tjd d d d t |�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_breaksc Cs�|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__r6Z rmenu_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�3s r�c@sFeZdZdZdd�Zdd�Zdd�Zdd �Zd S) �ModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfcCstj|�|j�dS)N)r r6� 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)r r�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�TclErrorr rb)r3rZ�chars�tagsrrrrbes  zModifiedUndoDelegator.insertc CsYy-|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�xs r�c@s�eZdZdd�ZdZdZdZdd�Zdd�Zdd �Z d d d d �Z dd�Z dd�Z dd�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 |_ |j j j |_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�|jdkstd��dd�tjD�}tjddddd d d �}td krnd |f}n d|f}tjg|d|t|j�gS)Nrz/Socket should have been assigned a port number.cSsg|]}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��AssertionErrorr�� warnoptionsr� GetOptionr� executableru)r3rkZ del_exitfZcommandrrrr��s   z,ModifiedInterpreter.build_subprocess_arglistc Cs�t|jf}xXtd�D]<}tj|�yt|�|_PWqtk rWYqXqW|j�dS|jj j �d|_t dkr�|jj j t 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 |�|jd d �|j�|jS)N�rr� r�r�r�r�r;rr^�with_cwdT)�HOSTr�r��timeZsleepr��rpccltr#�display_port_binding_error�listening_sockZ getsocknamer�Z setsockopt�socketZ SOL_SOCKETZ SO_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#t j k r�|j �dSYnX|jd|�|j�|jjdd�d|r�|nd}t|j�t|�dd d }|jd j||��|jjd d�|jjd d �|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�r7Z after_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 rGt t |�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�Z pollresponse� 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_viewerc Cs�ddlm}|jjdddi�}|dkrK|jjj�dS|j|j|�}ddlm }m }t |jj�}t j �}t j|d�d}||d |d d�} | jjd d d d�|| jd|�} | j�dS)Nr)�RemoteObjectBrowserr�Z stackviewerr;)�ScrolledCanvas�TreeNodeZnormalrTZbgZhighlightthickness�expandrZfillZboth)zflist)�idlelibrr�� remotequeuer�rwrcZStubObjectTreeItemZidlelib.TreeWidgetrrZToplevelrrVrWZframeZpackZcanvasr) r3rZoid�itemrrr�rXrTZscZnoderrrr�gs  z'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)r3rr rz�coderrrr s    zModifiedInterpreter.execfilec Cs�|j|�}d|_tjdd�|_tjdddt�t|t�sYt �zt j |||�SWd|jdk r�|jtjdd�<d|_nXdS)zBExtend base class method: Stuff the source in the line cache firstrN�action�errorr) r Zmorer&�filtersr��filterwarnings� SyntaxWarning� isinstancerur�r� runsource)r3r rrrrr�s  zModifiedInterpreter.runsourcecCsSd|j}|jd|_|jd�}t|�dd||ftj|<|S)z"Stuff source in the filename cachez <pyshell#%d>rrmr)�gid�splitr�rr*)r3r rr{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_syspathc Cs|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 j dd|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_td d |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�rr r rr rrr&r%r�rr!r�r�r*rrrrr�sF     +-      &          1  r�cs/eZdZde�dZeZeZdVdWdXdYdZd[gZ ddl m Z ddd�Z dd�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 r6ZusetabsZ indentwidthZcontext_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�r:�historyr�)r3r;Zmsrwr7r?rRrrrr6Ws\                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�dbrrrrH�s     zPyShell.toggle_debuggercCs%|jj�}|jd| �dS)Nz<<toggle-debugger>>)r^r�Zsetvar)r3r[rrrrX�szPyShell.set_debugger_indicatorcCsdS)Nr)r3rfrrrrI�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�rX)r3r[rrrrY�s     zPyShell.close_debuggercCsq|jjr'tj|jj|�}ntj|�}|jj|�|j�dt_|j �|j �dS)Nz[DEBUG ON] >>> ) r^r�rZstart_remote_debuggerrrr�r�r\r�rX)r3Zdbg_guirrrrZ�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�rxZ askokcancelr7r�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)rYr.r^r�rLr�r�rMr�rNr�r�r;r]rSrr�)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 j t j |j |f�|jj�|j�d dl}d|_d S) 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� COPYRIGHTZ focus_forcer��tkinterZ _default_root)r3ZnosubZclientrerrrr�s$         z PyShell.begincCs'|js dSd|_|jj�dS)NT)�reading�_stop_readline_flagr��quit)r3rrrr�s  zPyShell.stop_readlinec Cs�|j}zd|_|jj�Wd||_X|jrFd|_dS|jjdd�}t|�dkrvd}n|j�|jr�d|_t s�t �q�n|j r�d|_ d}n|S)NrFrRr�zend-1crrm) rfr��mainlooprgr7�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�rfr�r^r!r�rkr/r�r�r�r�r�rh)r3rfrrrrF<s&     zPyShell.cancel_callbackcCs�|jr|j rdS|jjddd�oD|jjddd�sKdS|jsk|j�|j�nd|_d|_|jj �dS)Nr�z==rbzend-1crrrQ) r�rfr7r�r�r�r/rkr�rh)r3rfrrrrGRs      zPyShell.eof_callbackcCs@|jr/|jjdd�|jjd�n |j|�dS)NrbrmrQ)rfr7rb�see�newline_and_indent_event)r3rfrrrrEas   zPyShell.linefeed_callbackc Cs�|jr|j rdSyN|jjdd�}|rd|jjddd�rd|j||�dSnWnYnX|jjddd�r�|jjd d�}|r�|jjdd|d �r�|j|jj|d |d �|�dS|jjd d�}|rL|jjd d |d �rL|j|jj|d |d �|�dS|jjdd�}|r�|jj|d dd�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�|jj dd�|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�rfr7rjr��recallZ tag_prevrangeZ tag_nextranger�rr�rorbrnrYZupdate_idletasksr�rh�runit)r3rf�sel�prev�next�indicesrrrrrDjsX "'"'&      zPyShell.enter_callbackc Cs�tjdd|�}tjdd|�}|jd�}|jj�zL|jjddd�|jjdd �|jjd d�}|j�j d �r�|j |�|jjd d�}n|jj d|d j ��t |�d kr�tjd|d �jd �}tjd|�jd �}xd|d d�D]O}|j|�rm||t |�d�}n|jj dd|j��q;WnWd|jjd�|jj�XdS)Nz^\s*\nrRz\n\s*$rmrrz1.0r�rbzend-1czinsert linestart�:rrz ^([ \t]*))�re�subrr7Zundo_block_startrhr�rj�rstrip�endswithrorbrr��search�grouprsrnZundo_block_stop)r3rrfr{�prefixZorig_base_indentZnew_base_indentrrrrrp�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)r7rjr�r^r)r3rr�rrrrq�s #  #z PyShell.runitc Css|jjr|jj�Sy tjWn%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�)r7rn)r3rfrrrrJ�szPyShell.view_restart_markcCs|jjdd�dS)z&Callback for Run/Restart Shell Cntl-F6r�TN)r^r�)r3rfrrrrK�szPyShell.restart_shellc Csl|j�yttj�}Wnd}YnX|jj|�|jjdd�|j�|j j �dS)NrRrbzend-1c) r�rur�r\r�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)r7rjrSZstorerbr�r�)r3r rrrr��s zPyShell.resetoutputc Cs�t|t�ryt|�ryt|�dkryx*t|�D]\}}|dkr:Pq:q:Wtd|||dd��nyB|jjdd�tj |||d�}|jjdd�Wn �YnX|j r�d|_ t s�t �q�n|S) Nu￿zUCS-2rz%Non-BMP character not supported in Tkr��rightr�r) rrur��max� enumerate�UnicodeEncodeErrorr7r�r r!r/r.r�)r3rr�r�r>�countrrrr!�s"-     z PyShell.writec sFy |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)zfiler0)r1r2)zdebugr3)r4r5)r6r7)zhelpr9)4rr�r�rr_r�r r�r rAZidlelib.IdleHistoryr:r6rTrfr�r/rkr�rgrVrWrHrXrIrYrZr,r�r�r�r^r`rdr�r�rlrmrFrGrErDrprqr'rJrKr�r�r!rFrLrr)r�rr�Asd  :                ?   r�c@sOeZdZddd�Zedd��Zedd��Zdd �ZdS) � PseudoFileNcCs||_||_||_dS)N)r;r�� _encoding)r3r;r�rPrrrr6"s  zPseudoFile.__init__cCs|jS)N)r�)r3rrrrP'szPseudoFile.encodingcCs d|jS)Nz<%s>)r�)r3rrr�name+szPseudoFile.namecCsdS)NTr)r3rrrrm/szPseudoFile.isatty)rr�r�r6�propertyrPr�rmrrrrr� s r�c@s(eZdZdd�Zdd�ZdS)rQcCsdS)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__r;r!r�)r3rrrrr!8s zPseudoOutputFile.writeN)rr�r�r�r!rrrrrQ3s  rQc@sUeZdZddd�Zdd�Zd dd�Zdd d �Zd d �ZdS)rONcCs#tj||||�d|_dS)NrR)r�r6� _line_buffer)r3r;r�rPrrrr6EszPseudoInputFile.__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[rrdr�r�rr�r;rlr�)r3�size�resultrrrrrLs,      zPseudoInputFile.readcCs�|jrtd��n|dkr-d}n+t|t�sXtdt|�j��n|jpm|jj �}|dkr�t |�}n|j dd|�}|dkr�|d}n||d�|_|d|�S)Nzread from closed filerzmust be int, not rrmr)) r�r[rrdr�r�rr�r;rlr��find)r3r�rZeolrrrrlcs      zPseudoInputFile.readlinecCs|jj�dS)N)r;r�)r3rrrr�sszPseudoInputFile.closer)r))rr�r�r6r�rrlr�rrrrrOCs  rOa� 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| d kr9tj j t�tj �n| d krNd}n| d krvtddtj�dan| dkr�| }t j j|�r�ntd|�tj �d}n| dkr�d}d}n| dkr�| t_d}q�q�W|r(|ddkr(tjj�}d}nx=tttj ��D]&} t j jtj | �tj | <q>W|r�|ddkr�dg|dd�t_n�|r�dg|t_n�|r�|g|t_n�|rTd}g} x'|D]} | jt j j| ��q�Wxy| D]=}t j j|�}|tj krtj jd|�qqWn1t j�}|tj kr�tj jd|�ntjddddd�}|p�|}|p�| }tdd�at j jt j jt�d��t �dkr t j 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|rt j5j6d/�p�t j5j6d0�} | rt j 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)4NTFrz c:deihnr:st:z Error: %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>>Z IDLESTARTUPZ PYTHONSTARTUPzbif 1: import sys as _sys _sys.argv = %r del _sys z print('%s'))r�r�r�)@r(r.�getoptr��argvrr�� usage_msgr��exitr�r!r=r>r~r�r_r�rr�r��abspathr\�dirnamerb�getcwdrr�rBrwr?�__file__rZ wm_iconbitmapZ TkVersionZ wm_iconphotor rCr�r;rZsetupAppZisAquaTkZ unbind_classrqrg�newr<�dictr��lowerr]rZ�environrjr^r r�r rZtkVersionWarningZ inversedictriZdestroy)Z enable_shellZ enable_editr`�cmdZscriptZstartupZoptsrCr�o�ar�Zpathxr�dirZ edit_startr�Z iconfilesZiconsr;Ztkversionwarningr)r�r�rr��s� )                         $      !              r�r�F)Er�r=Zos.pathrwr�r�r�r�r�rrArrrrcrrre� ImportErrorr�r�r�Ztkinter.messageboxZ messageboxrxZidlelib.EditorWindowrr Zidlelib.FileListr Zidlelib.ColorDelegatorr Zidlelib.UndoDelegatorr Zidlelib.OutputWindowr Zidlelib.configHandlerrrrrrrr�r�r r&rr$r%r(� checkcacher0r1r�r�r�Z RPCClientr�r�r�� TextIOBaser�rQrOr�r�rr�rrrr�<module>sx                   �����h �