
|Nc           @   s~  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Td  d l	 m	 Z	 d  d l
 m Z y d  d l m Z Wn e k
 r d Z n Xy# d  d l Z e j e j d  Wn e e j f k
 r n Xe j   Z d Z e j d	 k rQy! e j   d
 Z e j e  Wn e k
 rMn Xn yD e j e j  Z e e k p{e d k rd Z n  e j e  Wnv e e e f k
 ryB e j   d
 Z e e k pe d k rd Z n  e j e  Wn e e f k
 r	n Xn Xe j   Z e j  d  Z! d e	 f d     YZ" d   Z# d f  d     YZ$ d   Z% e& d k rze%   n  d S(   iN(   t   *(   t   SimpleDialog(   t   idleConf(   t   BOM_UTF8s   ﻿t    t   asciit   win32i   s   coding[:=]\s*([-\w_.]+)t   EncodingMessagec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s3   Inform user that an encoding declaration is needed.c   
      C   s  t  |  _ t |  |  _ } | j d |  j  | j d |  j  | j d |  j  | j	 d  | j
 d  | |  _ t | d d } | j d t d t  t | d	 d
 } | j d d |  | j d t d t d t  t | d d | } | j d t d t  t |  } | j d t d t  d |  _ |  _ t | d d d d d |  j } | j d t d t d d  t | d d d |  j }	 |	 j d t d t d d  |  j |  d  S(   Ns   <Return>s   <Escape>t   WM_DELETE_WINDOWs   I/O Warningt   texts:   Non-ASCII found, yet no encoding declared. Add a line liket   sidet   anchort   fontt   courieri    s   # -*- coding: %s -*-t   fills`   to your file
Choose OK to save this file as %s
Edit your general options to silence this warningt   Okt   defaultt   activet   commandt   expandi   s   Edit my file(   t   Falset   should_editt   Toplevelt   roott   bindt   return_eventt   do_okt   protocolt   wm_delete_windowt   wm_titlet   wm_iconnamet   topt   Labelt   packt   TOPt   Wt   Entryt   insertt   Xt   FrameR   t   cancelt   Buttont   LEFTt   BOTHt   do_editt   _set_transient(
   t   selft   mastert   encR   t   l1t   l2t   l3t   buttonst   b1t   b2(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   __init__M   s6    				
c         C   s   |  j  d  d  S(   Ni    (   t   done(   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR   s   s    c         C   s   |  j  d  d  S(   Ni   (   R8   (   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR,   v   s    (   t   __name__t
   __module__t   __doc__R7   R   R,   (    (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR   K   s   	&	c         C   s   |  j  d  d  }  d j |   }  t j |   } | s; d S| j d  } d d l } y | j |  Wn t k
 r t d |  n X| S(   sz   Return the encoding declaration according to PEP 263.

    Raise LookupError if the encoding is declared but unknown.
    s   
i   i   iNs   Unknown encoding (	   t   splitt   joint	   coding_ret   searcht   Nonet   groupt   codecst   lookupt   LookupError(   t   strt   matcht   nameRB   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   coding_specy   s    t	   IOBindingc           B   s"  e  Z d    Z d   Z d   Z d   Z d   Z d Z d   Z	 d Z
 d Z d   Z d d d  Z d Z e j e  Z e j Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d Z d Z  d  d! d" g Z! d   Z" d d  Z# d   Z$ d   Z% RS(#   c         C   s   | |  _  | j |  _ |  j j d |  j  |  _ |  j j d |  j  |  _ |  j j d |  j  |  _ |  j j d |  j	  |  _
 d  |  _ |  j j d |  j  |  _ d  S(   Ns   <<open-window-from-file>>s   <<save-window>>s   <<save-window-as-file>>s   <<save-copy-of-window-as-file>>s   <<print-window>>(   t   editwinR	   R   t   opent   _IOBinding__id_opent   savet   _IOBinding__id_savet   save_ast   _IOBinding__id_saveast   save_a_copyt   _IOBinding__id_savecopyR@   t   fileencodingt   print_windowt   _IOBinding__id_print(   R.   RJ   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR7      s    		c         C   s   |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  d  |  _ d  |  _  d  |  _	 d  S(   Ns   <<open-window-from-file>>s   <<save-window>>s   <<save-window-as-file>>s   <<save-copy-of-window-as-file>>s   <<print-window>>(
   R	   t   unbindRL   RN   RP   RR   RU   R@   RJ   t   filename_change_hook(   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   close   s    		c         C   s   |  j  j   S(   N(   RJ   t	   get_saved(   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRY      s    c         C   s   |  j  j |  d  S(   N(   RJ   t	   set_saved(   R.   t   flag(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRZ      s    c         C   s   |  j  j   d  S(   N(   RJ   t
   reset_undo(   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR\      s    c         C   s   | |  _  d  S(   N(   RW   (   R.   t   hook(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   set_filename_change_hook   s    c         C   sf   | r- t  j j |  r- d  |  _ | |  _ n5 | |  _ d  |  _ |  j d  |  j rb |  j   n  d  S(   Ni   (   t   ost   patht   isdirR@   t   filenamet   dirnameRZ   RW   (   R.   Rb   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   set_filename   s    				c         C   s1  |  j  j r | s! |  j   } n | } | r y |  j  j } Wn t k
 rV d  } n X|  j r |  j   r | r |  j  j j | |  j	  q |  j  j j |  n |  j
 j   d S|  j   r |  j   } | d k r |  j
 j   d Sn  | s|  j   } n | } | r |  j	 |  n |  j
 j   d S(   Nt   breakR(   (   RJ   t   flistt   askopenfilet   interpt   AttributeErrorR@   Rb   RY   RK   t   loadfileR	   t	   focus_sett	   maybesave(   R.   t   eventt   editFileRb   Rh   t   reply(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRK      s4    
s   (\r\n)|\n|\rc         C   sX  y) t  | d  } | j   } | j   Wn3 t k
 r^ } t j d t |  d |  j t SX|  j	 |  } |  j
 j |  } | r | j d  |  _ t |  j t  r |  j j d  |  _ n  |  j
 j d |  } n  |  j j d d  |  j d   |  j j d |  |  j   |  j |  |  j j d	 d  |  j j d	  |  j |  t S(
   Nt   rbs	   I/O ErrorR/   i    R   s   \ns   1.0t   endR%   (   RK   t   readRX   t   IOErrort   tkMessageBoxt	   showerrorRE   R	   R   t   decodet   eol_reR?   RA   t   eol_conventiont
   isinstancet   unicodet   encodet   subt   deleteRd   R@   R%   R\   t   mark_sett   seet   updaterecentfileslistt   True(   R.   Rb   t   ft   charst   msgt   firsteol(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRj      s.    
c         C   s!  | j  t  rK y | d j d  } Wn t k
 r: | SXt |  _ | Sn  y t |  } Wn< t k
 r } t j d d d d | d |  j	  d	 } n X| r y t | |  SWq t k
 r q Xn  y t | d  SWn t k
 r n Xy t | t  } t |  _ Wn t k
 rn X| S(
   sM   Create a Unicode string

        If that fails, let Tcl try its best
        i   s   utf-8t   titles   Error loading the filet   messages^   The encoding '%s' is not known to this Python installation. The file may not display correctlyR/   R   N(   t
   startswithR   Rv   t   UnicodeErrorRS   RH   RD   Rt   Ru   R	   R@   Rz   t   encoding(   R.   R   R0   RG   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRv     s>    		

c      
   C   s   |  j    r d Sd |  j p d } t j d d d | d t j d |  j  } | r~ d } |  j d   |  j    s d	 } q n | d  k r d	 } n d
 } |  j j   | S(   Nt   yess&   Do you want to save %s before closing?s   this untitled documentR   s   Save On CloseR   R   R/   R(   t   no(	   RY   Rb   Rt   t   askyesnocancelt   YESR	   RM   R@   Rk   (   R.   R   t   confirmRo   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRl   >  s&    			c         C   sq   |  j  s |  j |  nG |  j |  j   r` |  j t  y |  j j   Wq` t k
 r\ q` Xn  |  j j	   d S(   NRe   (
   Rb   RO   t	   writefileRZ   R   RJ   t   store_file_breaksRi   R	   Rk   (   R.   Rm   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRM   T  s    	c         C   s   |  j    } | rf |  j |  rf |  j |  |  j d  y |  j j   Wqc t k
 r_ qc Xqf n  |  j j   |  j	 |  d S(   Ni   Re   (
   t   asksavefileR   Rd   RZ   RJ   R   Ri   R	   Rk   R   (   R.   Rm   Rb   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRO   a  s    
c         C   s@   |  j    } | r" |  j |  n  |  j j   |  j |  d S(   NRe   (   R   R   R	   Rk   R   (   R.   Rm   Rb   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRQ   o  s    c         C   s   |  j    |  j |  j j d d   } |  j d k rO | j d |  j  } n  y8 t | d  } | j |  | j   | j	   t
 SWn3 t k
 r } t j d t |  d |  j t SXd  S(   Ns   1.0s   end-1cs   
t   wbs	   I/O ErrorR/   (   t   fixlastlineR{   R	   t   getRx   t   replaceRK   t   writet   flushRX   R   Rs   Rt   Ru   RE   R   (   R.   Rb   R   R   R   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR   w  s    



c   
      C   s  t  | t j  r | Sy | j d  SWn t k
 r: n Xy t |  } d  } Wn t k
 rr } | } d  } n X| r y | j |  SWq t k
 r d | } q Xn  | r t j	 d d | d |  j
 n  |  j t k s | r t | j d  S|  j rYy | j |  j  SWqYt k
 rUt j	 d d |  j d |  j
 t | j d  SXn  t j d d	 d
  } | d k rt | j d  St } y. | j t  } t } | d k rt } n  Wn* t k
 rt | j d  } d } n X| s| St |  j j |  } | j   | j d k rd | } |  j
 j d d  }	 |	 j d  rh|  j
 j d |  n |  j
 j d |  |  j |  j
 j d d   S| S(   NR   s   Invalid encoding '%s's	   I/O Errors   %s. Saving as UTF-8R/   s   utf-8s1   Cannot save this as '%s' anymore. Saving as UTF-8t   maint   EditorWindowR   t   localei   s   # -*- coding: %s -*-
s   1.0s   2.0s   #!s   end-1c(   Ry   t   typest
   StringTypeR{   R   RH   R@   RD   Rt   Ru   R	   RS   R   R   t	   GetOptionR   R   R   R   RJ   R   t   got   numR   R   R%   (
   R.   R   R0   t   failedR   t   config_encodingt   ask_usert   dialogt   enclinet	   firstline(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR{     sv    


	

	


c         C   s8   |  j  j d  } | d k r4 |  j  j d d  n  d  S(   Ns   end-2cs   
s   end-1c(   R	   R   R%   (   R.   t   c(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR     s    c      	   C   s  t  j d d d d d t  j d |  j  } | sA |  j j   d Sd  } |  j   } | re |  j } n  | sx | d  k r t j	 d d	  \ } } | } t
 j |  |  j |  s t
 j |  d Sn  t
 j } t } | d
 k rt j d d d  }	 |	 d }	 n* | d k r't j d d d  }	 n t } | r|	 | }	 t
 j |	 d  }
 |
 j   j   } |
 j   } | rd | | } n  | rd t |	  | } t  j d | d |  j qn# d | } t  j d | d |  j | rt
 j |  n  d S(   NR   t   PrintR   s   Print to Default PrinterR   R/   Re   t   prefixt	   IDLE_tmp_t   posixR   t   Generals   print-command-posixs    2>&1t   nts   print-command-wint   rs#   Printing failed (exit status 0x%x)
s   Printing command: %s
s   Print statuss-   Printing is not enabled for this platform: %s(   Rt   t   askokcancelt   OKR	   Rk   R@   RY   Rb   t   tempfilet   mkstempR_   RX   R   t   unlinkRG   R   R   R   R   t   popenRr   t   stript   reprRu   t   showinfo(   R.   Rm   R   t   tempfilenamet   savedRb   t   tfdt   platformt   printPlatformR   t   pipet   outputt   statusR   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRT     sX    				

s   Python filess
   *.py *.pywt   TEXTs
   Text filess   *.txts	   All filesR    c         C   s   |  j  d  \ } } |  j sB t j d |  j d |  j  |  _ n  |  j j d | d |  } t | t  r~ | j	 t
  } n  | S(   NRK   R/   t	   filetypest
   initialdirt   initialfile(   t   defaultfilenamet
   opendialogt   tkFileDialogt   OpenR	   R   t   showRy   Rz   R{   t   filesystemencoding(   R.   t   dirt   baseRb   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRg     s    	RK   c         C   sm   |  j  r t j j |  j   S|  j r2 |  j d f Sy t j   } Wn t j k
 r^ d } n X| d f Sd  S(   NR   (   Rb   R_   R`   R<   Rc   t   getcwdt   error(   R.   t   modet   pwd(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR     s    		
c         C   s   |  j  d  \ } } |  j sB t j d |  j d |  j  |  _ n  |  j j d | d |  } t | t  r~ | j	 t
  } n  | S(   NRM   R/   R   R   R   (   R   t
   savedialogR   t   SaveAsR	   R   R   Ry   Rz   R{   R   (   R.   R   R   Rb   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR   '  s    	c         C   s   |  j  j |  d S(   s-   Update recent file list on all editor windowsN(   RJ   t   update_recent_files_list(   R.   Rb   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR   1  s    N(   s   Python filess
   *.py *.pyws   TEXT(   s
   Text filess   *.txts   TEXT(   s	   All filesR    (&   R9   R:   R7   RX   RY   RZ   R\   R@   RW   R^   Rb   Rc   Rd   RK   t   eolt   ret   compileRw   R_   t   linesepRx   Rj   Rv   Rl   RM   RO   RQ   R   R{   R   RT   R   R   R   Rg   R   R   R   (    (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRI      sB   							(			-						J		2		
	
c          C   sb   t    }  d d d     Y} t |   } | j   | j   | |  } t |  } |  j   d  S(   Nt	   MyEditWinc           B   sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         S   sn   | |  _  d  |  _ |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  d  S(   Ns   <Control-o>s   <Control-s>s   <Alt-s>s   <Alt-z>(   R	   R@   Rf   R   RK   RM   RO   RQ   (   R.   R	   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR7   8  s    		c         S   s   d S(   Ni    (    (   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRY   ?  s    c         S   s   d  S(   N(    (   R.   R[   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRZ   @  s    c         S   s   d  S(   N(    (   R.   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR\   A  s    c         S   s   |  j  j d  d  S(   Ns   <<open-window-from-file>>(   R	   t   event_generate(   R.   Rm   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRK   B  s    c         S   s   |  j  j d  d  S(   Ns   <<save-window>>(   R	   R   (   R.   Rm   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRM   D  s    c         S   s   |  j  j d  d  S(   Ns   <<save-window-as-file>>(   R	   R   (   R.   Rm   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRO   F  s    c         S   s   |  j  j d  d  S(   Ns   <<save-copy-of-window-as-file>>(   R	   R   (   R.   Rm   (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyRQ   H  s    (
   R9   R:   R7   RY   RZ   R\   RK   RM   RO   RQ   (    (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyR   7  s   							(    (   t   Tkt   TextR!   Rk   RI   t   mainloop(   R   R   R	   RJ   t   io(    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   test5  s    	

t   __main__('   R_   R   t   sysRB   R   R   Rt   R   t   TkinterR   t   idlelib.configHandlerR   R   t   ImportErrorR   t	   setlocalet   LC_CTYPEt   Errort   getfilesystemencodingR   R   R   t   getdefaultlocaleRC   RD   t   nl_langinfot   CODESETR@   t	   NameErrorRi   t
   ValueErrort   lowerR   R>   R   RH   RI   R   R9   (    (    (    s&   C:\RCS\Python\lib\idlelib\IOBinding.pyt   <module>   sb   

		.	 	