B � f�P� @s�ddlZddlmZddlZddlZddlZddlZddlZddlmZ ddl m Z ddl mZddlZddlmZejr�dZdZn�yddlZe�ejd�Wneejfk r�YnXejdkr�dZdZn�ye�ej�Zer�e�e�WnXee e!fk �rDy e�"�d Ze�r"e�e�Wne#e!fk �r>YnXYnXe�rZe�$�Zd Znd ZdZe�%d ej&�Z'e�%d ej&�Z(dd�Z)Gdd�d�Z*dd�Z+e,dk�r�ddl-m.Z.e.dddd�ddl/m0Z0e0e+�dS)�N)�BOM_UTF8)� askstring)�idleConfzutf-8�surrogateescape�Zwin32��strict�asciiz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)z^[ \t\f]*(?:[#\r\n]|$)cCs�t|t�r|�d�}n|}d|kr8|�dd�dd�}n$d|krV|�dd�dd�}n|g}x2|D]&}t�|�}|dk rzPt�|�sbdSqbWdS|�d�}yt� |�Wn t k r�t d|��YnX|S)aVReturn the encoding declaration according to PEP 263. When checking encoded data, only the first two lines should be passed in to avoid a UnicodeDecodeError if the rest of the data is not unicode. The first two lines would contain the encoding specification. Raise a LookupError if the encoding is declared but unknown. z iso-8859-1� �N� rzUnknown encoding: ) � isinstance�bytes�decode�split� coding_re�match�blank_re�group�codecs�lookup� LookupError)�data�linesZlst�liner�name�r�3/opt/alt/python37/lib64/python3.7/idlelib/iomenu.py� coding_specBs*      rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd Zd d �Z d Z d Z dd�Z d4dd�Z dZe�e�ZejZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd Zd Z d'Z!e"j#d(kr�d)nd*Z$d+d,�Z%d5d.d/�Z&d0d1�Z'd2d3�Z(d S)6� IOBindingcCsr||_|j|_|j�d|j�|_|j�d|j�|_|j�d|j�|_|j�d|j �|_ d|_ |j�d|j �|_ dS)Nz<>z<>z<>z<>z<>)�editwin�text�bind�open�_IOBinding__id_open�save�_IOBinding__id_save�save_as�_IOBinding__id_saveas� save_a_copy�_IOBinding__id_savecopy� fileencoding� print_window�_IOBinding__id_print)�selfr rrr�__init__ps  zIOBinding.__init__cCsf|j�d|j�|j�d|j�|j�d|j�|j�d|j�|j�d|j�d|_d|_d|_dS)Nz<>z<>z<>z<>z<>) r!Zunbindr$r&r(r*r-r �filename_change_hook)r.rrr�close|szIOBinding.closecCs |j��S)N)r � get_saved)r.rrrr2�szIOBinding.get_savedcCs|j�|�dS)N)r � set_saved)r.�flagrrrr3�szIOBinding.set_savedcCs|j��dS)N)r � reset_undo)r.rrrr5�szIOBinding.reset_undoNcCs ||_dS)N)r0)r.�hookrrr�set_filename_change_hook�sz"IOBinding.set_filename_change_hookcCsF|rtj�|�rd|_||_n$||_d|_|�d�|jrB|��dS)Nr)�os�path�isdir�filename�dirnamer3r0)r.r;rrr� set_filename�s zIOBinding.set_filenamecCs�|jj}|rt|s|��}n|}|r`|jrTt|jdd�sT|jsT|��rT|�||j�qp|�|�n|jrp|j� �dS|��r�|� �}|dkr�|j� �dS|s�|��}n|}|r�|�|�n |j� �dS)N�interp�break�cancel) r �flist� askopenfile�getattrr;r2r#�loadfiler!� focus_set� maybesave)r.�eventZeditFilerAr;�replyrrrr#�s6       zIOBinding.openz (\r\n)|\n|\rc CsBy|j j � �t d d t|j j d �}|�rnt ||�}d|_|dfSttfk �r�YnXdS)zCreate a Unicode string.N�zutf-8)NF�BOMFzError loading the filez^The encoding '%s' is not known to this Python installation. The file may not display correctly)�title�messagerJr zSpecify file encodingzwThe file's encoding is invalid for Python 3.x. IDLE will convert it to UTF-8. What is the current encoding of the file?)Z initialvaluerJT)� startswithrr�UnicodeDecodeErrorr+rrrQrRr!rSr �updater�encoding)r.r\rr^�encrrrrrT�sh         zIOBinding._decodecCsp|��r dSd|jpd}tjd|tj|jd�}|rPd}|�d�|��sbd}n|dkr^d}nd}|j��|S)NZyesz&Do you want to save %s before closing?zthis untitled documentz Save On Close)rarb�defaultrJr@Zno)r2r;rQZaskyesnocancelZYESr!r%rE)r.rb�confirmrHrrrrF<s&    zIOBinding.maybesavecCsZ|js|�|�n:|�|j�rL|�d�y|j��Wntk rJYnX|j��dS)NTr?) r;r'� writefiler3r �store_file_breaks�AttributeErrorr!rE)r.rGrrrr%Rs    zIOBinding.savecCsf|��}|rN|�|�rN|�|�|�d�y|j��Wntk rLYnX|j��|� |�dS)Nrr?) � asksavefilerjr=r3r rkrlr!rErZ)r.rGr;rrrr'_s     zIOBinding.save_ascCs.|��}|r|�|�|j��|�|�dS)Nr?)rmrjr!rErZ)r.rGr;rrrr)ms    zIOBinding.save_a_copyc Cs�|��}|�|�}y:t|d��&}|�|�|��t�|���WdQRXdStk r�}zt j dt |�|j d�dSd}~XYnXdS)N�wbTz I/O Error)rJF) � fixnewlines�encoder#�write�flushr8�fsync�filenorPrQrRrSr!)r.r;r!r^r[r]rrrrjus     zIOBinding.writefilecCsT|j�d�dkr*t|jd�s*|j�dd�|j�dd�}|jdkrP|�d|j�}|S)z/Return text with final if needed and os eols.zend-2cr r>zend-1cz1.0)r!�get�hasattrr rLrW�replace)r.r!rrrro�s  zIOBinding.fixnewlinesc Cs�t|t�r|S|jdkr&t|�d�Sy |�d�Stk rDYnXyt|�}d}Wn*tk r�}z |}d}Wdd}~XYn X|s�d}|r�y |�|�Stk r�d|}YnXtj dd||j d�t|�d�S)Nr`zutf-8r zInvalid encoding '%s'z I/O Errorz%s. Saving as UTF-8)rJ) r rr+rrp� UnicodeErrorrrrQrRr!)r.r^rgZfailedr]rrrrp�s4     zIOBinding.encodecCsdtjddtj|jd�}|s(|j��dSd}|��}|r>|j}|rJ|dkr�tjdd�\}}|}t � |�|� |�s�t � |�dSt j }d}|dkr�t�d d d �} | d } n|d kr�t�d d d�} nd}|�r6| t�|�} t �| d�} | ����} | � �} | �r d| | } | �rPdt| �| } tjd| |jd�nd|} tjd| |jd�|�r`t � |�dS)NZPrintzPrint to Default Printer)rarbrhrJr?Z IDLE_tmp_)�prefixT�posix�mainZGeneralzprint-command-posixz 2>&1�ntzprint-command-winF�rz#Printing failed (exit status 0x%x) zPrinting command: %s z Print status)rJz-Printing is not enabled for this platform: %s)rQZ askokcancelZOKr!rEr2r;�tempfileZmkstempr8r1rj�unlinkrrZ GetOption�shlexZquote�popenrO�strip�reprrRZshowinfo)r.rGriZ tempfilenameZsavedr;Ztfd�platformZ printPlatformZcommand�pipe�outputZstatusrbrrrr,�sX           zIOBinding.print_window))z Python filesz *.py *.pyw�TEXT)z Text filesz*.txtr�)z All files�*�darwinz.pyrcCs<|�d�\}}|js(tj|j|jd�|_|jj||d�}|S)Nr#)rJ� filetypes)� initialdir� initialfile)�defaultfilename� opendialog� tkFileDialogZOpenr!r��show)r.�dir�baser;rrrrB�s  zIOBinding.askopenfiler#cCsV|jrtj�|j�S|jr$|jdfSy t��}Wntk rHd}YnX|dfSdS)Nr)r;r8r9rr<�getcwdrP)r.�mode�pwdrrrr��s   zIOBinding.defaultfilenamecCs@|�d�\}}|js,tj|j|j|jd�|_|jj||d�}|S)Nr%)rJr��defaultextension)r�r�)r�� savedialogr�ZSaveAsr!r�r�r�)r.r�r�r;rrrrms zIOBinding.asksavefilecCs|jjr|j�|�dS)z-Update recent file list on all editor windowsN)r rAZupdate_recent_files_list)r.r;rrrrZszIOBinding.updaterecentfileslist)NN)r#))�__name__� __module__� __qualname__r/r1r2r3r5r0r7r;r<r=r#Zeol�re�compilerUr8�lineseprWrDrTrFr%r'r)rjrorpr,r�r�r��sysr�r�rBr�rmrZrrrrrks@   , $D  '2  rc Cs�ddlm}m}||�}|�d�tt|���d�dd��\}}|�d||df�Gdd �d �}||�}|��|� �||�}t |�dS) Nr)�Toplevel�TextzTest IOBinding�+rz+%d+%d�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dS)z_io_binding..MyEditWincSs`||_d|_|j�d|j�|j�d|j�|j�d|j�|j�d|j�|j�d|j�dS)Nz z z zz )r!rAr"r#�printr%�saveas�savecopy)r.r!rrrr/sz'_io_binding..MyEditWin.__init__cSsdS)Nrr)r.rrrr2$�z(_io_binding..MyEditWin.get_savedcSsdS)Nr)r.r4rrrr3%r�z(_io_binding..MyEditWin.set_savedcSsdS)Nr)r.rrrr5&r�z)_io_binding..MyEditWin.reset_undocSs|j�d�dS)Nz<>)r!�event_generate)r.rGrrrr#'sz#_io_binding..MyEditWin.opencSs|j�d�dS)Nz<>)r!r�)r.rGrrrr�)sz$_io_binding..MyEditWin.printcSs|j�d�dS)Nz<>)r!r�)r.rGrrrr%+sz#_io_binding..MyEditWin.savecSs|j�d�dS)Nz<>)r!r�)r.rGrrrr�-sz%_io_binding..MyEditWin.saveascSs|j�d�dS)Nz<>)r!r�)r.rGrrrr�/sz'_io_binding..MyEditWin.savecopyN) r�r�r�r/r2r3r5r#r�r%r�r�rrrr� MyEditWinsr�) Ztkinterr�r�ra�map�intZgeometryrZpackrEr) rJr�r��root�x�yr�r!r rrr� _io_bindings  r��__main__)r{zidlelib.idle_test.test_iomenur F)� verbosity�exit)�run)1rrr8r�r�r�r~Ztkinter.filedialogZ filedialogr�Ztkinter.messageboxZ messageboxrQZtkinter.simpledialogrZidlelibZidlelib.configrZtestingrf�errorsZlocale� setlocale�LC_CTYPE� ImportError�Errorr�� nl_langinfo�CODESETZlocale_encodingr� NameErrorrlrZgetdefaultlocale� ValueError�lowerr��ASCIIrrrrr�r�Zunittestr{Zidlelib.idle_test.htestr�rrrr�sf         ),$