Your IP : 3.145.72.55


Current Path : /opt/alt/python34/lib64/python3.4/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/idlelib/__pycache__/IOBinding.cpython-34.pyo

�
e f=M�@stddlZddlmZddlZddlZddlZddlZddlZddljZ	ddl
jZddl
mZy#ddlZejejd�Wneejfk
r�YnXej�ZdZejdkr!y!ej�dZeje�Wnek
rYnXn�yDejej�ZedkpKedkrWdZneje�Wnxeeefk
r�yBej�dZedkp�edkr�dZneje�Wneefk
r�YnXYnXej �ZeZ!ej"dej#�Z$ej"d	ej#�Z%d
d�Z&Gdd
�d
�Z'dd�Z(e)dkrpddl*m+Z+e+e(�ndS)�N)�BOM_UTF8)�	askstring��ascii�win32�z%^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)z^[ \t\f]*(?:[#\r\n]|$)cCst|t�r!|jd�}n|}d|krR|jdd�dd�}n4d|kr}|jdd�dd�}n	|g}xD|D]8}tj|�}|dk	r�Pntj|�s�dSq�WdS|jd�}ytj	|�Wn"t
k
rt
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�6/opt/alt/python34/lib64/python3.4/idlelib/IOBinding.py�coding_specCs*		

rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdZdd
�Z	dZ
dZdd�Zdddd�Z
dZeje�ZejZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZdZdZ d:d;d<gZ!e"j#d.krJd/nd0Z$d1d2�Z%d3d4d5�Z&d6d7�Z'd8d9�Z(dS)=�	IOBindingcCs�||_|j|_|jjd|j�|_|jjd|j�|_|jjd|j�|_|jjd|j	�|_
d|_|jjd|j�|_
dS)Nz<<open-window-from-file>>z<<save-window>>z<<save-window-as-file>>z<<save-copy-of-window-as-file>>z<<print-window>>)�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)�selfrrrr�__init__ns		zIOBinding.__init__cCs�|jjd|j�|jjd|j�|jjd|j�|jjd|j�|jjd|j�d|_d|_d|_dS)Nz<<open-window-from-file>>z<<save-window>>z<<save-window-as-file>>z<<save-copy-of-window-as-file>>z<<print-window>>)	rZunbindr"r$r&r(r+r�filename_change_hook)r,rrr�closezs		zIOBinding.closecCs
|jj�S)N)r�	get_saved)r,rrrr0�szIOBinding.get_savedcCs|jj|�dS)N)r�	set_saved)r,�flagrrrr1�szIOBinding.set_savedcCs|jj�dS)N)r�
reset_undo)r,rrrr3�szIOBinding.reset_undoNcCs
||_dS)N)r.)r,�hookrrr�set_filename_change_hook�sz"IOBinding.set_filename_change_hookcCsf|r-tjj|�r-d|_||_n5||_d|_|jd�|jrb|j�ndS)Nr)�os�path�isdir�filename�dirnamer1r.)r,r9rrr�set_filename�s			
	zIOBinding.set_filenamecCs%|jj}|r�|s'|j�}n|}|r�|jr~t|jdd�r~|jr~|j�r~|j||j�q�|j|�n|jr�|jj	�ndS|j�r�|j
�}|dkr�|jj	�dSn|s�|j�}n|}|r|j|�n
|jj	�dS)NZinterp�break�cancel)r�flist�askopenfile�getattrr9r0r!�loadfiler�	focus_set�	maybesave)r,�eventZeditFiler>r9�replyrrrr!�s6	
	

zIOBinding.openz(\r\n)|\n|\rc	Cs�yKt|d��6}|j�|j�}|jd�|j�}WdQXWnHtk
r�}z(tjdt|�d|j�dSWYdd}~XnX|j	||�\}}|dkr�tjdd|d|j�dS|j
j|�}|r|jd�|_
|j
jd|�}n|jjd	d
�|jd�|jjd	|�|j�|j|�|r}|jd�n|jjdd	�|jjd�|j|�dS)
N�rbrz	I/O Error�parentFzDecoding ErrorzFile %s
Failed to Decodez\nz1.0�end�insertT)r!�readline�seek�read�OSError�tkMessageBox�	showerror�strr�_decode�eol_re�searchr�eol_convention�subZdeleter;rIr3r1Zmark_setZyview�updaterecentfileslist)	r,r9�f�	two_linesr�msg�charsZ	convertedZfirsteolrrrrA�s:
	





zIOBinding.loadfilec;Csd}|jt�ray|dd�jd�}Wntk
rJdSYqaXd|_|dfSnyt|�}Wnctk
r�}z.tjdddd	|d
|j	�d}WYdd}~Xntk
r�dSYnX|ry&t
||�}||_|dfSWqtk
rYqXny&t
|d�}d|_|dfSWntk
rUYnXy&t
|d�}d|_|dfSWntk
r�YnXy`|jj	j�t
dd
dtd
|jj	�}|r�t
||�}d|_n|dfSWnttfk
rYnXdS)zCreate a Unicode string.N�zutf-8F�BOM�titlezError loading the file�messagez^The encoding '%s' is not known to this Python installation. The file may not display correctlyrGrzSpecify 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initialvalueT)NF)NF)NF)�
startswithrr
�UnicodeDecodeErrorr)rrrNrOrrPr�updater�locale_encoding)r,rXrrZ�encrrrrrQ�sh
		
	

		
	
	
zIOBinding._decodec	Cs�|j�rdSd|jpd}tjddd|dtjd|j�}|r~d}|jd�|j�s�d	}q�n|dkr�d	}nd
}|jj�|S)N�yesz&Do you want to save %s before closing?zthis untitled documentr]z
Save On Closer^�defaultrGr=�no)r0r9rNZaskyesnocancelZYESrr#rB)r,r^�confirmrErrrrC:s&		
	
zIOBinding.maybesavecCsr|js|j|�nH|j|j�ra|jd�y|jj�Wqatk
r]YqaXn|jj�dS)NTr<)	r9r%�	writefiler1r�store_file_breaks�AttributeErrorrrB)r,rDrrrr#Ps	


zIOBinding.savecCs�|j�}|rg|j|�rg|j|�|jd�y|jj�Wqdtk
r`YqdXqgn|jj�|j	|�dS)Nrr<)
�asksavefilerhr;r1rrirjrrBrV)r,rDr9rrrr%]s




zIOBinding.save_ascCs@|j�}|r"|j|�n|jj�|j|�dS)Nr<)rkrhrrBrV)r,rDr9rrrr'ks

zIOBinding.save_a_copycCs�|j�|jjdd�}|jdkrF|jd|j�}n|j|�}y-t|d��}|j|�WdQXdSWnHtk
r�}z(t	j
dt|�d|j�dSWYdd}~XnXdS)	Nz1.0zend-1cr�wbTz	I/O ErrorrGF)�fixlastliner�getrT�replace�encoder!�writerMrNrOrP)r,r9rrZrWrYrrrrhss

zIOBinding.writefilec#Cst|t�r|S|jdkr3t|jd�Sy|jd�SWntk
rXYnXyt|�}d}Wn1tk
r�}z|}d}WYdd}~XnX|s�d}n|r�y|j|�SWq�tk
r�d|}Yq�Xntj	dd|d|j
�t|jd�S)Nr\zutf-8rzInvalid encoding '%s'z	I/O Errorz%s.
Saving as UTF-8rG)rrr)rrp�UnicodeErrorrrrNrOr)r,rZrcZfailedrYrrrrp�s4

	


zIOBinding.encodecCs8|jjd�}|dkr4|jjdd�ndS)Nzend-2crzend-1c)rrnrI)r,�crrrrm�szIOBinding.fixlastlinec	Cstjdddddtjd|j�}|sA|jj�dSd}|j�}|re|j}n|sx|dkr�tjdd	�\}}|}t	j
|�|j|�s�t	j|�dSnt	j
}d
}|dkrtjdd
d�}	|	d}	n*|dkr'tjdd
d�}	nd}|r�|	tj|�}	t	j|	d�}
|
j�j�}|
j
�}|r�d||}n|r�dt|	�|}tjd|d|j�q�n#d|}
tjd|
d|j�|r�t	j|�ndS)Nr]ZPrintr^zPrint to Default PrinterrerGr<�prefixZ	IDLE_tmp_T�posix�mainZGeneralzprint-command-posixz 2>&1�ntzprint-command-winF�rz#Printing failed (exit status 0x%x)
zPrinting command: %s
zPrint statusz-Printing is not enabled for this platform: %s)rNZaskokcancelZOKrrBr0r9�tempfileZmkstempr6r/rh�unlinkr�idleConfZ	GetOption�shlexZquote�popenrL�strip�reprrOZshowinfo)r,rDrgZtempfilenameZsavedr9Ztfd�platformZ
printPlatformZcommand�pipe�outputZstatusr^rrrr*�sX		


		

zIOBinding.print_window�Python files�
*.py *.pyw�TEXT�
Text files�*.txt�	All files�*�darwinz.pyrcCsa|jd�\}}|jsBtjd|jd|j�|_n|jjd|d|�}|S)Nr!rG�	filetypes�
initialdir�initialfile)�defaultfilename�
opendialog�tkFileDialogZOpenrr��show)r,�dir�baser9rrrr?�s	zIOBinding.askopenfiler!cCsk|jrtjj|j�S|jr2|jdfSytj�}Wntk
r\d}YnX|dfSdS)Nr)r9r6r7rr:�getcwdrM)r,�mode�pwdrrrr��s		

zIOBinding.defaultfilenamecCsj|jd�\}}|jsKtjd|jd|jd|j�|_n|jjd|d|�}|S)Nr#rGr��defaultextensionr�r�)r��
savedialogr�ZSaveAsrr�r�r�)r,r�r�r9rrrrk�s				zIOBinding.asksavefilecCs#|jjr|jj|�ndS)z-Update recent file list on all editor windowsN)rr>Zupdate_recent_files_list)r,r9rrrrV	szIOBinding.updaterecentfileslist)r�r�r�)r�r�r�)r�r�))�__name__�
__module__�__qualname__r-r/r0r1r3r.r5r9r:r;r!Zeol�re�compilerRr6�lineseprTrArQrCr#r%r'rhrprmr*r�r�r��sysr�r�r?r�rkrVrrrrrlsD,	$D
'2	
rcCs�ddlm}m}ddlm}||�}|jd�tttt	j
d|j����\}}}}|jd||df�Gdd	�d	�}	||�}
|
j�|
j
�|	|
�}t|�dS)
Nr)�Toplevel�Text)r{zTest IOBindingz[x+]z+%d+%d�c@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)z_io_binding.<locals>.MyEditWincSsB||_d|_|jjd|j�|jjd|j�dS)Nz<Control-o>z<Control-s>)rr>r r!r#)r,rrrrr-s		z'_io_binding.<locals>.MyEditWin.__init__cSsdS)Nrr)r,rrrr0sz(_io_binding.<locals>.MyEditWin.get_savedcSsdS)Nr)r,r2rrrr1sz(_io_binding.<locals>.MyEditWin.set_savedcSsdS)Nr)r,rrrr3sz)_io_binding.<locals>.MyEditWin.reset_undocSs|jjd�dS)Nz<<open-window-from-file>>)r�event_generate)r,rDrrrr!sz#_io_binding.<locals>.MyEditWin.opencSs|jjd�dS)Nz<<save-window>>)rr�)r,rDrrrr#!sz#_io_binding.<locals>.MyEditWin.saveN)	r�r�r�r-r0r1r3r!r#rrrr�	MyEditWinsr�)Ztkinterr�r�Zidlelib.configHandlerr{r]�list�map�intr�rZgeometryZpackrBr)rGr�r�r{�root�widthZheight�x�yr�rrrrr�_io_bindings
3

r��__main__)�run),rrr6r�r|r�ryZtkinter.filedialogZ
filedialogr�Ztkinter.messageboxZ
messageboxrNZtkinter.simpledialogrZlocale�	setlocale�LC_CTYPE�ImportError�Error�getfilesystemencodingZfilesystemencodingrbr�Zgetdefaultlocalerr�nl_langinfo�CODESET�	NameErrorrj�
ValueError�lower�encodingr��ASCIIrrrrr�r�Zidlelib.idle_test.htestr�rrrr�<module>s\
		
)��

?>