m
fIc           @   s_  d  k  Z  d  k Z d  k Z d  k Z d  k Z d  k Z d  k Z d  k Z d k Td k	 l	 Z	 d k
 l Z y d k l Z Wn e j
 o d Z n Xy  d  k Z e i e i d  Wn e e i f j
 o n Xd Z e i d j o; y! e i   d	 Z e i e  Wn e j
 o n Xn yG e i e i  Z e e j p
 e d j o
 d Z n e i e  Wn} e e e f j
 oh yE e i   d	 Z e e j p
 e d j o
 d Z n e i e  Wn e e f j
 o n Xn Xe i   Z e i d
  Z d e	 f d     YZ  d   Z! d f  d     YZ" d   Z# e$ d j o e#   n d  S(   N(   t   *(   s   SimpleDialog(   s   idleConf(   s   BOM_UTF8s   ﻿t    t   asciit   win32i   s   coding[:=]\s*([-\w_.]+)t   EncodingMessagec           B   s)   t  Z d  Z d   Z d   Z d   Z RS(   s3   Inform user that an encoding declaration is needed.c   
      C   s  t  |  _ t |  |  _ } | i d |  i  | i d |  i	  | i
 d |  i  | i d  | i d  | |  _ t | d d } | i d t d t  t | d	 d
 } | i d d |  | i d t d t d t  t | d d | } | i d t d t  t |  } | i d t d t  d |  _ |  _ t | d d d d d |  i	 }	 |	 i d t d t  d d  t | d d d |  i! } | i d t d t  d d  |  i# |  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   selft   should_editt   Toplevelt   mastert   roott   topt   bindt   return_eventt   do_okt   protocolt   wm_delete_windowt   wm_titlet   wm_iconnamet   Labelt   l1t   packt   TOPt   Wt   Entryt   l2t   insertt   enct   Xt   l3t   Framet   buttonsR   t   cancelt   Buttont   b1t   LEFTt   BOTHt   do_editt   b2t   _set_transient(
   R   R   R'   R+   R2   R)   R    R%   R   R.   (    (    t.   /mit/python/lib/python2.4/idlelib/IOBinding.pyt   __init__J   s4    		c         C   s   |  i d  d  S(   Ni    (   R   t   done(   R   (    (    R4   R   p   s    c         C   s   |  i d  d  S(   Ni   (   R   R6   (   R   (    (    R4   R1   s   s    (   t   __name__t
   __module__t   __doc__R5   R   R1   (    (    (    R4   R   H   s    	&	c         C   s   |  i d  d  }  d i |   }  t i |   } | p d Sn | i d  } d k	 } y | i
 |  Wn  t j
 o 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   Ns   Unknown encoding (   t   strt   splitt   joint	   coding_ret   searcht   matcht   Nonet   groupt   namet   codecst   lookupt   LookupError(   R:   RB   RC   R?   (    (    R4   t   coding_specv   s     	t	   IOBindingc           B   s"  t  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 i e  Z e i 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("   Nc         C   s   | |  _  | i |  _ |  i i d |  i  |  _ |  i i d |  i  |  _ |  i i d |  i  |  _	 |  i i d |  i
  |  _ d  |  _ |  i i d |  i  |  _ 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   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   RH   (    (    R4   R5      s    		c         C   s   |  i i d |  i  |  i i d |  i  |  i i d |  i  |  i i d |  i  |  i i d |  i  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   R   t   unbindRJ   RL   RN   RP   RS   R@   RH   t   filename_change_hook(   R   (    (    R4   t   close   s    		c         C   s   |  i i   S(   N(   R   RH   t	   get_saved(   R   (    (    R4   RW      s    c         C   s   |  i i |  d  S(   N(   R   RH   t	   set_savedt   flag(   R   RY   (    (    R4   RX      s    c         C   s   |  i i   d  S(   N(   R   RH   t
   reset_undo(   R   (    (    R4   RZ      s    c         C   s   | |  _ d  S(   N(   t   hookR   RU   (   R   R[   (    (    R4   t   set_filename_change_hook   s    c         C   sk   | o) t i i |  o d  |  _  | |  _ n8 | |  _  d  |  _ |  i d  |  i o |  i   n d  S(   Ni   (	   t   filenamet   ost   patht   isdirR@   R   t   dirnameRX   RU   (   R   R]   (    (    R4   t   set_filename   s    			
c         C   s?  |  i i o | p |  i   } n | } | ot y |  i i } Wn d  } n X|  i o2 |  i   o% | o |  i i i	 | |  i
  q |  i i i	 |  n |  i i   d Sn |  i   o2 |  i   } | d j o |  i i   d Sq n | p |  i   } n | } | o |  i
 |  n |  i i   d S(   Nt   breakR,   (   R   RH   t   flistt   editFilet   askopenfileR]   t   interpR@   RW   RI   t   loadfileR   t	   focus_sett	   maybesavet   reply(   R   t   eventRe   Rg   R]   Rk   (    (    R4   RI      s4    
 s   (\r\n)|\n|\rc         C   sa  y) t  | d  } | i   } | i   Wn8 t j
 o, } t i	 d t
 |  d |  i t Sn X|  i |  } |  i i |  } | oW | i d  |  _ t |  i t  o |  i i d  |  _ n |  i i d |  } n |  i i d d  |  i d   |  i i d |  |  i   |  i |  |  i i d	 d  |  i i d	  |  i |  t  S(
   Nt   rbs	   I/O ErrorR   i    R   s   \ns   1.0t   endR&   (!   RI   R]   t   ft   readt   charsRV   t   IOErrort   msgt   tkMessageBoxt	   showerrorR:   R   R   R   t   decodet   eol_reR>   t   firsteolRA   t   eol_conventiont
   isinstancet   unicodet   encodet   subt   deleteRb   R@   R&   RZ   t   mark_sett   seet   updaterecentfileslistt   True(   R   R]   Ro   Rx   Rs   Rq   (    (    R4   Rh      s.    	
c         C   s2  | i t  oB y | d i d  } Wn t j
 o | SqR Xt |  _ | Sn y t |  } Wn> t	 j
 o2 } t i d d d d | d |  i  d	 } n X| o+ y t | |  SWq t j
 o q Xn y t | d  SWn t j
 o n Xy t | t  } t |  _ Wn t j
 o 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(   Rq   t
   startswitht   BOM_UTF8Rv   t   UnicodeErrorR   RQ   RF   R'   RE   RB   Rt   Ru   R   R@   R{   t   encoding(   R   Rq   R'   RB   (    (    R4   Rv     s<     		
	c         C   s   |  i   o d Sn d |  i p d } t i d d d | d t i d t i d	 |  i  } | i
   } | d j o( |  i d   |  i   p
 d
 } q n |  i i   | S(   Nt   yess&   Do you want to save %s before closing?s   this untitled documentR   s   Save On CloseR   t   icont   typeR   R,   (   R   RW   R]   R   Rt   t   Messaget   QUESTIONt   YESNOCANCELR   t   mt   showRk   RK   R@   Ri   (   R   R   Rk   R   (    (    R4   Rj   ;  s    		c         C   sw   |  i p |  i |  nL |  i |  i  o8 |  i d  y |  i i   Wqf t j
 o qf Xn |  i	 i
   d S(   Ni   Rc   (   R   R]   RM   Rl   t	   writefileRX   RH   t   store_file_breakst   AttributeErrorR   Ri   (   R   Rl   (    (    R4   RK   N  s    
	c         C   s   |  i   } | oY |  i |  oE |  i |  |  i d  y |  i i   Wqh t j
 o qh Xql n |  i	 i
   |  i |  d S(   Ni   Rc   (   R   t   asksavefileR]   R   Rb   RX   RH   R   R   R   Ri   R   (   R   Rl   R]   (    (    R4   RM   [  s    c         C   sB   |  i   } | o |  i |  n |  i i   |  i |  d S(   NRc   (   R   R   R]   R   R   Ri   R   (   R   Rl   R]   (    (    R4   RO   i  s    c         C   s   |  i   |  i |  i i d d   } |  i d j o | i d |  i  } n y8 t | d  } | i |  | i   | i   t SWn8 t j
 o, } t i d t |  d |  i t Sn Xd  S(   Ns   1.0s   end-1cs   
t   wbs	   I/O ErrorR   (   R   t   fixlastlineR|   R   t   getRq   Ry   t   replaceRI   R]   Ro   t   writet   flushRV   R   Rr   Rs   Rt   Ru   R:   R   (   R   R]   Ro   Rs   Rq   (    (    R4   R   q  s    


c   
      C   s  t  | t i  o | Sn y | i d  SWn t j
 o n Xy t |  } d  } Wn! t
 j
 o } | } d  } n X| o5 y | i |  SWq t j
 o d | } q Xn | o! t i d d | d |  i n |  i t j p | o t | i d  Sn |  i o_ y | i |  i  SWqut j
 o8 t i d d |  i d |  i t | i d  SquXn t i d d	 d
  } | d j o t | i d  Sn t } y0 | i t  } t } | d j o
 t } n Wn, t j
 o  t | i d  } d } n X| p | Sn t |  i i |  } | i   | i d j oy d | }	 |  i i  d d  } | i" d  o |  i i# d |	  n |  i i# d |	  |  i |  i i  d d   Sn | 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($   Rz   Rq   t   typest
   StringTypeR|   R   RF   R'   R@   t   failedRE   Rs   Rt   Ru   R   R   RQ   R   t   idleConft	   GetOptiont   config_encodingR   t   ask_userR   R   R   RH   R   t   dialogt   got   numt   enclineR   t	   firstlineR   R&   (
   R   Rq   R   R'   R   Rs   R   R   R   R   (    (    R4   R|     sp    
	
	
	

 c         C   s:   |  i i d  } | d j o |  i i d d  n d  S(   Ns   end-2cs   
s   end-1c(   R   R   R   t   cR&   (   R   R   (    (    R4   R     s    c         C   s  d  } |  i   } | o |  i } n | p | d  j oT t i d d  \ } } | } t	 i
 |  |  i |  p t	 i |  d Sq n t	 i } d }	 | d j o# t i d d d  } | d	 } n- | d
 j o t i d d d  } n d }	 |	 o | | } t	 i | d  } | i   i   }
 | i
   } | o d | |
 }
 n |
 o1 d t |  |
 }
 t i d |
 d |  i qn$ d | } t i d | d |  i | o t	 i |  n d S(   Nt   prefixt	   IDLE_tmp_Rc   i   t   posixR   t   Generals   print-command-posixs    2>&1t   nts   print-command-wini    t   rs#   Printing failed (exit status 0x%x)
s   Printing command: %s
s   Print statusR   s-   Printing is not enabled for this platform: %s(   R@   t   tempfilenameR   RW   t   savedR]   t   tempfilet   mkstempt   tfdR^   RV   R   t   unlinkRB   t   platformt   printPlatformR   R   R   t   popent   pipeRp   t   stript   outputt   statust   reprRt   Ru   R   R   t   showinfo(   R   Rl   R   R   R   R   R]   R   R   R   R   R   R   (    (    R4   RR     sF    		
!
s   Python and text filess   *.py *.pyw *.txtt   TEXTs   All text filesR    s	   All filesc         C   s]   |  i d  \ } } |  i p% t i d |  i d |  i  |  _ n |  i i	 d | d |  S(   NRI   R   t	   filetypest
   initialdirt   initialfile(
   R   t   defaultfilenamet   dirt   baset
   opendialogt   tkFileDialogt   OpenR   R   R   (   R   R   R   (    (    R4   Rf     s
    
RI   c         C   sy   |  i o t i i |  i  SnU |  i o |  i d f Sn: y t i   } Wn t i j
 o d } n X| d f Sd  S(   NR   (	   R   R]   R^   R_   R;   Ra   t   getcwdt   pwdt   error(   R   t   modeR   (    (    R4   R     s    

c         C   s]   |  i d  \ } } |  i p% t i d |  i d |  i  |  _ n |  i i	 d | d |  S(   NRK   R   R   R   R   (
   R   R   R   R   t
   savedialogR   t   SaveAsR   R   R   (   R   R   R   (    (    R4   R     s
    
c         C   s   |  i i |  d S(   s-   Update recent file list on all editor windowsN(   R   RH   t   update_recent_files_listR]   (   R   R]   (    (    R4   R     s     (   s   Python and text filess   *.py *.pyw *.txtR   (   s   All text filesR    R   (   s	   All filesR    (&   R7   R8   R5   RV   RW   RX   RZ   R@   RU   R\   R]   Ra   Rb   RI   t   eolt   ret   compileRw   R^   t   linesepRy   Rh   Rv   Rj   RK   RM   RO   R   R|   R   RR   R   R   R   Rf   R   R   R   (    (    (    R4   RG      s>   							(			-						J		+		c          C   sb   t    } d f  d     Y} t |  }  |  i   |  i   | |   } t |  } | i
   d  S(   Nt	   MyEditWinc           B   sP   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(	   Nc         C   sn   | |  _  d  |  _ |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  d  S(   Ns   <Control-o>s   <Control-s>s   <Alt-s>s   <Alt-z>(	   R   R   R@   Rd   R   RI   RK   RM   RO   (   R   R   (    (    R4   R5   %  s    		c         C   s   d S(   Ni    (    (   R   (    (    R4   RW   ,  s    c         C   s   d  S(   N(    (   R   RY   (    (    R4   RX   -  s    c         C   s   d  S(   N(    (   R   (    (    R4   RZ   .  s    c         C   s   |  i i d  d  S(   Ns   <<open-window-from-file>>(   R   R   t   event_generate(   R   Rl   (    (    R4   RI   /  s    c         C   s   |  i i d  d  S(   Ns   <<save-window>>(   R   R   R   (   R   Rl   (    (    R4   RK   1  s    c         C   s   |  i i d  d  S(   Ns   <<save-window-as-file>>(   R   R   R   (   R   Rl   (    (    R4   RM   3  s    c         C   s   |  i i d  d  S(   Ns   <<save-copy-of-window-as-file>>(   R   R   R   (   R   Rl   (    (    R4   RO   5  s    (
   R7   R8   R5   RW   RX   RZ   RI   RK   RM   RO   (    (    (    R4   R   $  s   							(   t   TkR   R   t   TextR   R!   Ri   RH   RG   t   iot   mainloop(   R   R   RH   R   R   (    (    R4   t   test"  s    	

t   __main__(%   R^   R   t   sysRC   R   R   Rt   R   t   Tkintert   SimpleDialogt   configHandlerR   R   t   ImportErrorR   t	   setlocalet   LC_CTYPEt   ErrorR   R   t   getdefaultlocaleRD   RE   t   nl_langinfot   CODESETR@   t	   NameErrorR   t
   ValueErrort   lowerR   R=   R   RF   RG   R   R7   (   R   R   R   R   RF   R   R   R   R   R   RC   R   R   R^   R   Rt   RG   R=   (    (    R4   t   ?   s`   										


.	 	