
   ̈́aFS                   ,   S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  SR                  S \ 5       5      rS	r\R"                  S
:X  a  SOSr " S S5      rS r\S:X  a  S SKJr  \" SSSS9  S SKJr  \" \5        gg)    N)
filedialog)
messagebox)	askstring)idleConf)py_extensions c              #   ,   #    U  H
  nS U-   v   M     g7f)*N ).0exts     %/usr/lib/python3.13/idlelib/iomenu.py	<genexpr>r      s     :MSSMs   utf-8win32surrogatepasssurrogateescapec                       \ rS rSrS rS rS rS rS rSr	S r
SrSrS	 rS S
 jr\R                   rS rS rS rS rS rS rS rS rS rSrSrS\S4SS4r\R@                  S:X  a  SOSr!S r"S!S jr#S r$S r%Sr&g)"	IOBinding   c                    Xl         UR                  U l        U R                  R                  SU R                  5      U l        U R                  R                  SU R
                  5      U l        U R                  R                  SU R                  5      U l        U R                  R                  SU R                  5      U l
        SU l        U R                  R                  SU R                  5      U l        g )N<<open-window-from-file>><<save-window>><<save-window-as-file>><<save-copy-of-window-as-file>>r   <<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)selfr   s     r   __init__IOBinding.__init__   s    LL	(CTYYO(9499E99>>*C*.,,8!YY^^,M,0,<,<>#))..);T=N=NO    c                    U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R
                  5        U R                   R                  SU R                  5        S U l        S U l         S U l        g )Nr   r   r   r   r   )	r   unbindr!   r#   r%   r'   r*   r   filename_change_hookr+   s    r   closeIOBinding.close%   s    		4dnnE		*DNN;		243C3CD		:D<N<NO		+T__=	$(!r.   c                 6    U R                   R                  5       $ N)r   	get_savedr2   s    r   r7   IOBinding.get_saved1   s    ||%%''r.   c                 :    U R                   R                  U5        g r6   )r   	set_savedr+   flags     r   r:   IOBinding.set_saved4   s    t$r.   c                 8    U R                   R                  5         g r6   )r   
reset_undor2   s    r   r?   IOBinding.reset_undo7   s    !r.   Nc                     Xl         g r6   )r1   )r+   hooks     r   set_filename_change_hook"IOBinding.set_filename_change_hook<   s    $(!r.   c                     U(       a2  [         R                  R                  U5      (       a  S U l        Xl        g Xl        S U l        U R                  S5        U R                  (       a  U R                  5         g g )N   )ospathisdirfilenamedirnamer:   r1   r+   rJ   s     r   set_filenameIOBinding.set_filenameB   sU    h// DM#L$MDLNN1(())+ )r.   c                    U R                   R                  nU(       a  U(       d  U R                  5       nOUnU(       a  U R                   (       a^  [        U R                   SS 5      (       dB  U R                  (       d1  U R                  5       (       a  UR                  X@R                  5        gUR                  U5         gU R                  (       a  U R                  R                  5         gU R                  5       (       a1  U R                  5       nUS:X  a  U R                  R                  5         gU(       d  U R                  5       nOUnU(       a  U R                  U5        gU R                  R                  5         g)Ninterpbreakcancel)r   flistaskopenfilegetattrrJ   r7   r    loadfiler   	focus_set	maybesave)r+   eventeditFilerS   rJ   replys         r   r    IOBinding.openM   s   ""++-! LL#DLL(DAA MM((JJx7 	 JJx(  99II'') >>NN$E 		##%'')HHMM(#  II!r.   c                 2     [         R                  " U5       nUR                  5       nUR                  nUR                  nSnS S S 5        [        W[        5      (       d5  Ub"  [        R                   " SSU R                  S	9  Sn["        R$                  nU R                  R'                  SS5        U R)                  S 5        WU l        XPl        U R                  R/                  SW5        U R1                  5         U R)                  U5        W(       a  U R3                  S5        U R                  R5                  SS5        U R                  R7                  S5        U R9                  U5        g! , (       d  f       GN1= f! [
        [        4 a    U R                  R                  R                  5         [        SSSU R                  R                  S9n[        XS9 nUR                  5       nUR                  nUR                  nSnS S S 5         GM  ! , (       d  f        GN= ff = f! [         a3  n[        R                  " S[        U5      U R                  S	9   S nAgS nAf[
         a&    [        R                  " S
SU-  U R                  S	9   gf = f)NFzSpecify 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?r   )initialvalueparent)encodingT	I/O Errorr_   zDecoding ErrorzFile %s
Failed to DecodezMixed Newlinesz:Mixed newlines detected.
The file will be changed on save.1.0endinsert)tokenizer    readr`   newlinesUnicodeDecodeErrorSyntaxErrorr   r   updater   OSErrorr   	showerrorstr
isinstanceshowwarningrG   linesepdeleterM   r(   eol_conventionre   r?   r:   mark_setyviewupdaterecentfileslist)	r+   rJ   fcharsr(   rs   	convertedencerrs	            r   rV   IOBinding.loadfile{   s   	%]]8,FFHE#$::L%&ZZN %I	 -: .#.. )&&'7*M04		; !	ZZN		&$(,		&(# NN5!		8U+		!""8,m -,
 '4 %!!((*+@ ")<<,,. (1QFFHE#$::L%&ZZN $I	 2111%  	  c#htyyI! 	  !1#>#I*.))5 		sq   F  +E.F  .
E=8F  =F   AH(+HH(H+ 
H$	H(!H+ $H((H+ +
J5)I##0JJc                 h   U R                  5       (       a  gSU R                  =(       d    S S3n[        R                  " SU[        R                  U R
                  S9nU(       a+  U R                  S5        U R                  5       (       a  SOSnOUc  SOS	nU R
                  R                  5         U$ )
zReturn 'yes', 'no', 'cancel' as appropriate.

Tkinter messagebox.askyesnocancel converts these tk responses
to True, False, None.  Convert back, as now expected elsewhere.
yeszDo you want to save zthis untitled documentz before closing?zSave On Closetitlemessagedefaultr_   NrR   no)r7   rJ   r   askyesnocancelYESr   r"   rW   )r+   r   confirmr[   s       r   rX   IOBinding.maybesave   s     >>)mm?'?@%& ++'!$..	$
 IIdO!^^--E8E#*?xu		r.   c                 6   U R                   (       d  U R                  U5        OLU R                  U R                   5      (       a,  U R                  S5         U R                  R                  5         U R                  R                  5         g! [         a     N'f = f)NTrQ   )	rJ   r$   	writefiler:   r   store_file_breaksAttributeErrorr   rW   r+   rY   s     r   r"   IOBinding.save   sr    }}LL~~dmm,,t$LL224 			 & s   B 
BBc                 N   U R                  5       nU(       aS  U R                  U5      (       a=  U R                  U5        U R                  S5         U R                  R                  5         U R                  R                  5         U R                  U5        g! [         a     N8f = f)NrF   rQ   )
asksavefiler   rM   r:   r   r   r   r   rW   rv   r+   rY   rJ   s      r   r$   IOBinding.save_as   s    ##%~~h''!!(+q!LL224 			""8,	 & s   B 
B$#B$c                     U R                  5       nU(       a  U R                  U5        U R                  R                  5         U R	                  U5        g)NrQ   )r   r   r   rW   rv   r   s      r   r&   IOBinding.save_a_copy   s@    ##%NN8$		""8,r.   c                    U R                  5       nU R                  U5      n [        US5       nUR                  U5        UR	                  5         [
        R                  " UR                  5       5        S S S 5        g! , (       d  f       g= f! [         a3  n[        R                  " S[        U5      U R                  S9   S nAgS nAff = f)NwbTra   rb   F)fixnewlinesencoder    writeflushrG   fsyncfilenorl   r   rm   rn   r   )r+   rJ   r   rx   rw   msgs         r   r   IOBinding.writefile   s    !D!		h%	$ & 	 &%  	  c#h*.))5	s5   B AA>5B >
BB B 
C)CCc                    [        U R                  S5      (       a6  U R                  R                  SU R                  R	                  S5      5      nOWU R                  R                  S5      S:w  a  U R                  R                  SS5        U R                  R                  SS5      nU R                  S:w  a  UR                  SU R                  5      nU$ )zVReturn text with os eols.

       Add prompts if shell else final 
if missing.
       rP   rc   zend-1czend-2c
)	hasattrr   get_prompt_textr   indexgetre   rs   replacer+   r   s     r   r   IOBinding.fixnewlines   s     4<<**<<//tyyx7PQDyy}}X&$.		  4099==1D$&<<d&9&9:Dr.   c                 6   [        U[        5      (       a  U$ U R                  S:X  a  UR                  S5      $  UR                  S5      $ ! [         a     Of = f UR                  SS5      n[
        R                  " [        R                  " U5      R                  5      u  p4UR                  U5      $ ! [         a  n[        U5      n S nAOS nAf[         a    SW-  n Of = f[        R                  " SSU-  U R                  S9  UR                  S5      $ )Nz	utf-8-sigasciir   zInvalid encoding '%s'ra   z%s.
Saving as UTF-8rb   )ro   bytesr(   r   UnicodeEncodeErrorrf   detect_encodingioBytesIOreadlinerj   rn   r   rm   r   )r+   rx   encodedrz   _r{   faileds          r   r   IOBinding.encode  s    eU## L+<<,,	<<((! 			3ll7I6G--bjj.A.J.JKFC<<$$ 	XF! 	3,s2F	3"V+99	 ||K((s0   A 
AAAB5 5
C$?CC$#C$c                 B   [         R                  " SS[         R                  U R                  S9nU(       d  U R                  R	                  5         gS nU R                  5       nU(       a  U R                  nU(       a  Wc[  [        R                  " SS9u  pcUn[        R                  " U5        U R                  U5      (       d  [        R                  " U5        g[        R                  nSnUS:X  a  [        R                  " S	S
S5      n	U	S-   n	O!US:X  a  [        R                  " S	S
S5      n	OSnU(       a  W	[         R"                  " U5      -  n	[        R$                  " U	S5      n
U
R'                  5       R)                  5       nU
R                  5       nU(       a  SU-  U-   nU(       a0  S[+        U	5      -  U-   n[         R,                  " SXR                  S9  O$SU-  n[         R.                  " SXR                  S9  U(       a  [        R                  " U5        g)NPrintzPrint to Default Printerr   rQ   	IDLE_tmp_)prefixTposixmainGeneralzprint-command-posixz 2>&1ntzprint-command-winFrz#Printing failed (exit status 0x%x)
zPrinting command: %s
zPrint statusrb   z-Printing is not enabled for this platform: %s)r   askokcancelOKr   rW   r7   rJ   tempfilemkstemprG   r3   r   unlinknamer   	GetOptionshlexquotepopenrg   stripreprrm   showinfo)r+   rY   r   tempfilenamesavedrJ   tfdplatformprintPlatformcommandpipeoutputstatusr   s                 r   r)   IOBinding.print_window-  s   ((4$--	$
 II! }}H("*"2"2+"FS#HHHSM>>,//		,'77w((	)>@G'G((	:MNG!MH 55G88GS)DYY[&&(FZZ\F? "()1DMAFJ$$^VIINEPG		JIIl#r.   zPython filesTEXT)z
Text filesz*.txtr   )z	All filesr
   darwinz.py c                     U R                  S5      u  pU R                  (       d.  [        R                  " U R                  U R
                  S9U l        U R                  R                  XS9nU$ )Nr    )r_   	filetypes
initialdirinitialfile)defaultfilename
opendialogr   Openr   r   showr+   dirbaserJ   s       r   rT   IOBinding.askopenfilej  sU    ((0	(ooTYY:>..JDO??''3'Ir.   c                    U R                   (       a)  [        R                  R                  U R                   5      $ U R                  (       a  U R                  S4$  [        R
                  " 5       nUS4$ ! [         a    Sn US4$ f = f)Nr   )rJ   rG   rH   splitrK   getcwdrl   )r+   modepwds      r   r   IOBinding.defaultfilenamer  sp    ==77==//\\<<##iik 7N  7Ns   A4 4BBc                     U R                  S5      u  pU R                  (       d9  [        R                  " U R                  U R
                  U R                  S9U l        U R                  R                  XS9nU$ )Nr"   )r_   r   defaultextensionr   )r   
savedialogr   SaveAsr   r   r   r   r   s       r   r   IOBinding.asksavefile~  sb    ((0	(//99"nn%)%:%:<DO ??''3'Ir.   c                 r    U R                   R                  (       a  U R                   R                  U5        gg)z-Update recent file list on all editor windowsN)r   rS   update_recent_files_listrL   s     r   rv   IOBinding.updaterecentfileslist  s&    <<LL11(; r.   )	__id_open
__id_print	__id_save__id_saveas__id_savecopyrK   r   rs   r(   rJ   r1   r   r   r   )NN)r    )'__name__
__module____qualname____firstlineno__r,   r3   r7   r:   r?   r1   rC   rJ   rK   rM   r    rG   rq   rs   rV   rX   r"   r$   r&   r   r   r   r)   r   r   r   r   sysr   r   rT   r   r   rv   __static_attributes__r   r.   r   r   r      s    

P
)(%"  ) HG	,*X ZZN9v. )>0d JJ 
/'
I !$ 8ub
<r.   r   c                 d   SSK JnJn  U" U 5      nUR                  S5        [	        [
        U R                  5       R                  S5      SS  5      u  pEUR                  SXES-   4-  5         " S S	5      nU" U5      nUR                  5         UR                  5         U" U5      n[        U5        g )
Nr   )ToplevelTextzTest IOBinding+rF   z+%d+%d   c                   J    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSrg)_io_binding.<locals>.MyEditWini  c                    Xl         S U l        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R
                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        g )Nz<Control-o>z<Control-p>z<Control-s>z<Alt-s>z<Control-c>)r   rS   r   r    printr"   saveassavecopyr   s     r   r,   '_io_binding.<locals>.MyEditWin.__init__  s|    IDJIINN=$))4IINN=$**5IINN=$))4IINN9dkk2IINN=$--8r.   c                     g)Nr   r   r2   s    r   r7   (_io_binding.<locals>.MyEditWin.get_saved  s    Ar.   c                     g r6   r   r;   s     r   r:   (_io_binding.<locals>.MyEditWin.set_saved  s    4r.   c                     g r6   r   r2   s    r   r?   )_io_binding.<locals>.MyEditWin.reset_undo  s    dr.   c                 :    U R                   R                  S5        g )Nr   r   event_generater   s     r   r    #_io_binding.<locals>.MyEditWin.open  s    II$$%@Ar.   c                 :    U R                   R                  S5        g )Nr   r  r   s     r   r  $_io_binding.<locals>.MyEditWin.print  s    II$$%78r.   c                 :    U R                   R                  S5        g )Nr   r  r   s     r   r"   #_io_binding.<locals>.MyEditWin.save  s    II$$%67r.   c                 :    U R                   R                  S5        g )Nr   r  r   s     r   r  %_io_binding.<locals>.MyEditWin.saveas  s    II$$%>?r.   c                 :    U R                   R                  S5        g )Nr   r  r   s     r   r  '_io_binding.<locals>.MyEditWin.savecopy  s    II$$%FGr.   )rS   r   N)r   r   r   r   r,   r7   r:   r?   r    r  r"   r  r  r   r   r.   r   	MyEditWinr    s.    	9 	&'"	B	9	8	@	Hr.   r  )tkinterr   r   r   mapintgeometryr   packrW   r   )	r_   r   r   topxyr  r   r   s	            r   _io_bindingr#    s    &
6
CIIsFOO%++C045DALLQCL()H H. 9DIIKNNoGgr.   __main__)r   zidlelib.idle_test.test_iomenu   F)	verbosityexit)run)r   rG   r   r   r   rf   r  r   r   tkinter.simpledialogr   idlelib.configr   idlelib.utilr   joinr`   r   errorsr   r#  r   unittestr   idlelib.idle_test.htestr(  r   r.   r   <module>r0     s    	 	  
     * # &:M::LLG39Jw< w<t#L z	(AEB+ r.   