
"Ic           @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Td  d k	 l	 Z	 d  d k
 l Z y d  d k l Z Wn e j
 o d Z n Xy# d  d k Z e i e i d  Wn e e i f j
 o n Xe i   Z d 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(   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 |  |  _ } | 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   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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyt   __init__M   s6    				
c         C   s   |  i  d  d  S(   Ni    (   t   done(   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR   s   s    c         C   s   |  i  d  d  S(   Ni   (   R8   (   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR,   v   s    (   t   __name__t
   __module__t   __doc__R7   R   R,   (    (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR   K   s   	&	c         C   s   |  i  d  d  }  d i |   }  t i |   } | p d S| i d  } 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   iNs   Unknown encoding (	   t   splitt   joint	   coding_ret   searcht   Nonet   groupt   codecst   lookupt   LookupError(   t   strt   matcht   nameRB   (    (    s.   /mit/python/lib/python2.6/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 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("   c         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   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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR7      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	   t   unbindRL   RN   RP   RR   RU   R@   RJ   t   filename_change_hook(   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyt   close   s    		c         C   s   |  i  i   S(   N(   RJ   t	   get_saved(   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRY      s    c         C   s   |  i  i |  d  S(   N(   RJ   t	   set_saved(   R.   t   flag(    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRZ      s    c         C   s   |  i  i   d  S(   N(   RJ   t
   reset_undo(   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR\      s    c         C   s   | |  _  d  S(   N(   RW   (   R.   t   hook(    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyt   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   ost   patht   isdirR@   t   filenamet   dirnameRZ   RW   (   R.   Rb   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyt   set_filename   s    			
c         C   sE  |  i  i o | p |  i   } n | } | o y |  i  i } Wn t j
 o d  } n X|  i o2 |  i   o% | o |  i  i i | |  i	  q |  i  i i |  n |  i
 i   d S|  i   o/ |  i   } | d j o |  i
 i   d Sn | p |  i   } n | } | o |  i	 |  n |  i
 i   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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRK      s4     	s   (\r\n)|\n|\rc         C   s^  y) t  | d  } | i   } | i   Wn5 t j
 o) } t i d t |  d |  i t S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%   (   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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRj      s.    
c         C   s/  | i  t  o? y | d i d  } Wn t j
 o | S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(   t
   startswithR   Rv   t   UnicodeErrorRS   RH   RD   Rt   Ru   R	   R@   Rz   t   encoding(   R.   R   R0   RG   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRv     s>    		
	c         C   s   |  i    o d S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(   (   RY   Rb   Rt   t   Messaget   QUESTIONt   YESNOCANCELR	   t   showRM   R@   Rk   (   R.   R   t   mRo   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRl   >  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   Re   (	   Rb   RO   t	   writefileRZ   RJ   t   store_file_breaksRi   R	   Rk   (   R.   Rm   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRM   Q  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   Re   (
   t   asksavefileR   Rd   RZ   RJ   R   Ri   R	   Rk   R   (   R.   Rm   Rb   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRO   ^  s    c         C   sB   |  i    } | o |  i |  n |  i i   |  i |  d S(   NRe   (   R   R   R	   Rk   R   (   R.   Rm   Rb   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRQ   l  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
 SWn5 t j
 o) } t i d t |  d |  i t SXd  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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR   t  s    



c   
      C   s  t  | t i  o | S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  S|  i o\ y | i |  i  SWqlt j
 o5 t i	 d d |  i d |  i
 t | i d  SXn t i d d	 d
  } | d j o t | i d  St } y0 | i t  } t } | d j o
 t } n Wn, t j
 o  t | i d  } d } n X| p | St |  i i |  } | i   | i d j ov d | } |  i
 i d d  }	 |	 i d  o |  i
 i d |  n |  i
 i d |  |  i |  i
 i 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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR{     sv    




	

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%   (   R.   t   c(    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR     s    c         C   s6  t  i d d d d d t  i d t  i d t  i d |  i  } | i   } | t  i j o |  i i   d	 Sd  } |  i	   } | o |  i
 } n | p | d  j oQ t i d
 d  \ } } | } t i |  |  i |  p t i |  d	 S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(   NR   t   PrintR   s   Print to Default PrinterR   R   R   R/   Re   t   prefixt	   IDLE_tmp_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 statuss-   Printing is not enabled for this platform: %s(   Rt   R   R   t   OKCANCELt   OKR	   R   Rk   R@   RY   Rb   t   tempfilet   mkstempR_   RX   R   t   unlinkRG   R   R   t   popenRr   t   stript   reprRu   t   showinfo(   R.   Rm   R   Ro   t   tempfilenamet   savedRb   t   tfdt   platformt   printPlatformR   t   pipet   outputt   statusR   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRT     s^    							
!
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 |  } t | t  o | i	 t
  } n | S(   NRK   R/   t	   filetypest
   initialdirt   initialfile(   t   defaultfilenamet
   opendialogt   tkFileDialogt   OpenR	   R   R   Ry   Rz   R{   t   filesystemencoding(   R.   t   dirt   baseRb   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRg     s    
RK   c         C   ss   |  i  o t i i |  i   S|  i o |  i d f Sy t i   } Wn t i j
 o d } n X| d f Sd  S(   NR   (   Rb   R_   R`   R<   Rc   t   getcwdt   error(   R.   t   modet   pwd(    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR     s    

c         C   s   |  i  d  \ } } |  i p% t i d |  i d |  i  |  _ n |  i i d | d |  } t | t  o | i	 t
  } n | S(   NRM   R/   R   R   R   (   R   t
   savedialogR   t   SaveAsR	   R   R   Ry   Rz   R{   R   (   R.   R   R   Rb   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR   '  s    
c         C   s   |  i  i |  d S(   s-   Update recent file list on all editor windowsN(   RJ   t   update_recent_files_list(   R.   Rb   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR   1  s    N(   s   Python and text filess   *.py *.pyw *.txtR   (   s   All text filesR    R   (   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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRI      sB   							(			-						J		5		
	
c          C   sb   t    }  d d d     Y} t |   } | i   | i   | |  } t |  } |  i   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  |  _ |  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@   Rf   R   RK   RM   RO   RQ   (   R.   R	   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR7   8  s    		c         S   s   d S(   Ni    (    (   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRY   ?  s    c         S   s   d  S(   N(    (   R.   R[   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRZ   @  s    c         S   s   d  S(   N(    (   R.   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR\   A  s    c         S   s   |  i  i d  d  S(   Ns   <<open-window-from-file>>(   R	   t   event_generate(   R.   Rm   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRK   B  s    c         S   s   |  i  i d  d  S(   Ns   <<save-window>>(   R	   R   (   R.   Rm   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRM   D  s    c         S   s   |  i  i d  d  S(   Ns   <<save-window-as-file>>(   R	   R   (   R.   Rm   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRO   F  s    c         S   s   |  i  i d  d  S(   Ns   <<save-copy-of-window-as-file>>(   R	   R   (   R.   Rm   (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyRQ   H  s    (
   R9   R:   R7   RY   RZ   R\   RK   RM   RO   RQ   (    (    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyR   7  s   							(    (   t   Tkt   TextR!   Rk   RI   t   mainloop(   R   R   R	   RJ   t   io(    (    s.   /mit/python/lib/python2.6/idlelib/IOBinding.pyt   test5  s    	

t   __main__('   R_   R   t   sysRB   R   R   Rt   R   t   TkinterR   t   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.   /mit/python/lib/python2.6/idlelib/IOBinding.pyt   <module>   sb   
	


.	 	