
9a^c           @   s  d  d l  Z  d  d l  m 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 Z d  d l	 Z	 d  d l
 m
 Z
 d  d l m Z y# 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 r3y! e j   d	 Z e  j e  Wn e k
 r/n Xn yD e j e j  Z e e k p]e d k ri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! e j  d  Z" d e
 f d     YZ# d   Z$ d f  d     YZ% d   Z& e' d k r~d  d l( m) Z) e) e&  n  d S(   iN(   t   BOM_UTF8(   t   *(   t   SimpleDialog(   t   idleConft    t   asciit   win32i   s&   ^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)s   ^[ \t\f]*(?:[#\r\n]|$)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
See Language Reference, 2.1.4 Encoding declarations.
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"   lib/python2.7/idlelib/IOBinding.pyt   __init__J   s6    				
c         C   s   |  j  d  d  S(   Ni    (   t   done(   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   q   s    c         C   s   |  j  d  d  S(   Ni   (   R8   (   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR,   t   s    (   t   __name__t
   __module__t   __doc__R7   R   R,   (    (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   H   s   	'	c         C   s   |  j  d d  d  } xD | D]8 } t j |  } | d k	 rB Pn  t j |  s d Sq Wd 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	   coding_ret   matcht   Nonet   blank_ret   groupt   codecst   lookupt   LookupError(   t   strt   lstt   lineR>   t   nameRB   (    (    s"   lib/python2.7/idlelib/IOBinding.pyt   coding_specw   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! e" j# d k rd n d 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.   RK   (    (    s"   lib/python2.7/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   unbindRM   RO   RQ   RS   RV   R?   RK   t   filename_change_hook(   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyt   close   s    		c         C   s   |  j  j   S(   N(   RK   t	   get_saved(   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRZ      s    c         C   s   |  j  j |  d  S(   N(   RK   t	   set_saved(   R.   t   flag(    (    s"   lib/python2.7/idlelib/IOBinding.pyR[      s    c         C   s   |  j  j   d  S(   N(   RK   t
   reset_undo(   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR]      s    c         C   s   | |  _  d  S(   N(   RX   (   R.   t   hook(    (    s"   lib/python2.7/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   dirnameR[   RX   (   R.   Rc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyt   set_filename   s    				c         C   s%  |  j  j } | r | s' |  j   } n | } | r |  j  r~ t |  j  d d   r~ |  j r~ |  j   r~ | j | |  j  q | j |  n |  j	 r |  j	 j
   n  d S|  j   r |  j   } | d k r |  j	 j
   d Sn  | s |  j   } n | } | r|  j |  n |  j	 j
   d S(   Nt   interpt   breakR(   (   RK   t   flistt   askopenfilet   getattrR?   Rc   RZ   RL   t   loadfileR	   t	   focus_sett	   maybesave(   R.   t   eventt   editFileRh   Rc   t   reply(    (    s"   lib/python2.7/idlelib/IOBinding.pyRL      s6    	
	s   (\r\n)|\n|\rc         C   sW  y( t  | d   } | j   } Wd  QXWn3 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 Errort   parenti    R   s   \ns   1.0t   endR%   (   RL   t   readt   IOErrort   tkMessageBoxt	   showerrorRE   R	   R   t   decodet   eol_ret   searchRA   t   eol_conventiont
   isinstancet   unicodet   encodet   subt   deleteRe   R?   R%   R]   t   mark_sett   yviewt   updaterecentfileslistt   True(   R.   Rc   t   ft   charst   msgt   firsteol(    (    s"   lib/python2.7/idlelib/IOBinding.pyRk      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 correctlyRr   R   N(   t
   startswithR    Rx   t   UnicodeErrorRT   RI   RD   Rv   Rw   R	   R?   R}   t   encoding(   R.   R   R0   RH   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRx     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   Rr   R(   t   no(	   RZ   Rc   Rv   t   askyesnocancelt   YESR	   RN   R?   Rl   (   R.   R   t   confirmRp   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRm   A  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(   NRg   (
   Rc   RP   t	   writefileR[   R   RK   t   store_file_breakst   AttributeErrorR	   Rl   (   R.   Rn   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRN   W  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   Rg   (
   t   asksavefileR   Re   R[   RK   R   R   R	   Rl   R   (   R.   Rn   Rc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRP   d  s    
c         C   s@   |  j    } | r" |  j |  n  |  j j   |  j |  d S(   NRg   (   R   R   R	   Rl   R   (   R.   Rn   Rc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRR   r  s    c         C   s   |  j    |  j |  j j d d   } |  j d k rO | j d |  j  } n  y- t | d   } | j |  Wd  QXt SWn3 t	 k
 r } t
 j d t |  d |  j t SXd  S(   Ns   1.0s   end-1cs   
t   wbs	   I/O ErrorRr   (   t   fixlastlineR~   R	   t   getR{   t   replaceRL   t   writeR   Ru   Rv   Rw   RE   R   (   R.   Rc   R   R   R   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   z  s    

c   
      C   s  t  | t  r | Sy | j d  SWn t k
 r7 n Xy t |  } d  } Wn t k
 ro } | } 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
 rVy | j |  j
  SWqVt k
 rR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  re|  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-8Rr   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(   R|   RE   R~   R   RI   R?   RD   Rv   Rw   R	   RT   R    R   t	   GetOptionR   R   R   R   RK   R   t   got   numR   R   R%   (
   R.   R   R0   t   failedR   t   config_encodingt   ask_usert   dialogt   enclinet	   firstline(    (    s"   lib/python2.7/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"   lib/python2.7/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 |  }	 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   Rr   Rg   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(   Rv   t   askokcancelt   OKR	   Rl   R?   RZ   Rc   t   tempfilet   mkstempR`   RY   R   t   unlinkRH   R   R   R   R   t   pipest   quotet   popenRt   t   stript   reprRw   t   showinfo(   R.   Rn   R   t   tempfilenamet   savedRc   t   tfdt   platformt   printPlatformR   t   pipet   outputt   statusR   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRU     sX    				
s   Python filess
   *.py *.pywt   TEXTs
   Text filess   *.txts	   All filesR   t   darwins   .pyR   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(   NRL   Rr   t	   filetypest
   initialdirt   initialfile(   t   defaultfilenamet
   opendialogt   tkFileDialogt   OpenR	   R   t   showR|   R}   R~   t   filesystemencoding(   R.   t   dirt   baseRc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRi     s    	RL   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   (   Rc   R`   Ra   R<   Rd   t   getcwdt   error(   R.   t   modet   pwd(    (    s"   lib/python2.7/idlelib/IOBinding.pyR     s    		
c         C   s   |  j  d  \ } } |  j sK t j d |  j d |  j d |  j  |  _ n  |  j j d | d |  } t | t	  r | j
 t  } n  | S(   NRN   Rr   R   t   defaultextensionR   R   (   R   t
   savedialogR   t   SaveAsR	   R   R   R   R|   R}   R~   R   (   R.   R   R   Rc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   *  s    				c         C   s   |  j  j |  d S(   s-   Update recent file list on all editor windowsN(   RK   t   update_recent_files_list(   R.   Rc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   6  s    N(   s   Python filess
   *.py *.pywR   (   s
   Text filess   *.txtR   (   s	   All filesR   ()   R9   R:   R7   RY   RZ   R[   R]   R?   RX   R_   Rc   Rd   Re   RL   t   eolt   ret   compileRy   R`   t   linesepR{   Rk   Rx   Rm   RN   RP   RR   R   R~   R   RU   R   R   R   t   sysR   R   Ri   R   R   R   (    (    (    s"   lib/python2.7/idlelib/IOBinding.pyRJ      sD   							,			-						J		2		
	c         C   s   d d l  m } m } | |   } | j d  t t t t j d |  j	      \ } } } } | j	 d | | d f  d d	 d     Y} | |  }	 |	 j
   |	 j   | |	  }
 t |
  d  S(
   Ni(   R   t   Texts   Test IOBindings   [x+]s   +%d+%di   t	   MyEditWinc           B   sb   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   c         S   s   | |  _  d  |  _ |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  |  j  j d |  j  d  S(   Ns   <Control-o>s   <Control-p>s   <Control-s>s   <Alt-s>s   <Control-c>(	   R	   R?   Rh   R   RL   t   printerRN   t   saveast   savecopy(   R.   R	   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR7   C  s    		c         S   s   d S(   Ni    (    (   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRZ   K  s    c         S   s   d  S(   N(    (   R.   R\   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR[   L  s    c         S   s   d  S(   N(    (   R.   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR]   M  s    c         S   s   d  S(   N(    (   R.   Rc   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   N  s    c         S   s   |  j  j d  d  S(   Ns   <<open-window-from-file>>(   R	   t   event_generate(   R.   Rn   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRL   O  s    c         S   s   |  j  j d  d  S(   Ns   <<print-window>>(   R	   R   (   R.   Rn   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   Q  s    c         S   s   |  j  j d  d  S(   Ns   <<save-window>>(   R	   R   (   R.   Rn   (    (    s"   lib/python2.7/idlelib/IOBinding.pyRN   S  s    c         S   s   |  j  j d  d  S(   Ns   <<save-window-as-file>>(   R	   R   (   R.   Rn   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   U  s    c         S   s   |  j  j d  d  S(   Ns   <<save-copy-of-window-as-file>>(   R	   R   (   R.   Rn   (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   W  s    (   R9   R:   R7   RZ   R[   R]   R   RL   R   RN   R   R   (    (    (    s"   lib/python2.7/idlelib/IOBinding.pyR   B  s   									(    (   t   TkinterR   R   R   t   listt   mapt   intR   R<   t   geometryR!   Rl   RJ   (   Rr   R   R   R   t   widtht   heightt   xt   yR   R	   RK   (    (    s"   lib/python2.7/idlelib/IOBinding.pyt   _io_binding;  s    3

t   __main__(   t   run(*   RB   R    R`   R   R   R   R   R   R   Rv   R   t   idlelib.configHandlerR   R   t	   setlocalet   LC_CTYPEt   ImportErrort   Errort   getfilesystemencodingR   R   R   t   getdefaultlocaleRC   RD   t   nl_langinfot   CODESETR?   t	   NameErrorR   t
   ValueErrort   lowerR   R=   R@   R   RI   RJ   R   R9   t   idlelib.idle_test.htestR   (    (    (    s"   lib/python2.7/idlelib/IOBinding.pyt   <module>   s`   
		/	 	%