B ÁW“¬­Uuã @sØddlZddlmZddlZddlZddlZddlZddlZddlmZ ddl m Z ddl mZddlZddlmZejr„dZdZnÞyddlZe ejd¡Wneejfk r¸YnXejdkrÎdZdZn”ye ej¡Zerêe e¡WnXee e!fk rDy e "¡d Zer"e e¡Wne#e!fk r>YnXYnXerZe $¡Zd Znd ZdZe %d ej&¡Z'e %d ej&¡Z(dd„Z)Gdd„dƒZ*dd„Z+e,dkrÔddl-m.Z.e.ddddddl/m0Z0e0e+ƒdS)éN)ÚBOM_UTF8)Ú askstring)ÚidleConfzutf-8ÚsurrogateescapeÚZwin32éÚstrictÚasciiz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)z^[ \t\f]*(?:[#\r\n]|$)cCsÎt|tƒr| d¡}n|}d|kr8| dd¡dd…}n$d|krV| dd¡dd…}n|g}x2|D]&}t |¡}|dk rzPt |¡sbdSqbWdS| d¡}yt  |¡Wn t k rÈt d|ƒ‚YnX|S)aVReturn the encoding declaration according to PEP 263. When checking encoded data, only the first two lines should be passed in to avoid a UnicodeDecodeError if the rest of the data is not unicode. The first two lines would contain the encoding specification. Raise a LookupError if the encoding is declared but unknown. z iso-8859-1Ú éNú rzUnknown encoding: ) Ú isinstanceÚbytesÚdecodeÚsplitÚ coding_reÚmatchÚblank_reÚgroupÚcodecsÚlookupÚ LookupError)ÚdataÚlinesZlstÚlinerÚname©rú3/opt/alt/python37/lib64/python3.7/idlelib/iomenu.pyÚ coding_specBs*      rc@sþeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd Zd d „Z d Z d Z dd„Z d4dd„Z dZe e¡ZejZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd Zd Z d'Z!e"j#d(krÔd)nd*Z$d+d,„Z%d5d.d/„Z&d0d1„Z'd2d3„Z(d S)6Ú IOBindingcCsr||_|j|_|j d|j¡|_|j d|j¡|_|j d|j¡|_|j d|j ¡|_ d|_ |j d|j ¡|_ dS)Nz<>z<>z<>z<>z<>)Ú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 rrrÚ__init__ps  zIOBinding.__init__cCsf|j d|j¡|j d|j¡|j d|j¡|j d|j¡|j d|j¡d|_d|_d|_dS)Nz<>z<>z<>z<>z<>) r!Zunbindr$r&r(r*r-r Úfilename_change_hook)r.rrrÚclose|szIOBinding.closecCs |j ¡S)N)r Ú get_saved)r.rrrr2ˆszIOBinding.get_savedcCs|j |¡dS)N)r Ú set_saved)r.Úflagrrrr3‹szIOBinding.set_savedcCs|j ¡dS)N)r Ú reset_undo)r.rrrr5ŽszIOBinding.reset_undoNcCs ||_dS)N)r0)r.ÚhookrrrÚset_filename_change_hook“sz"IOBinding.set_filename_change_hookcCsF|rtj |¡rd|_||_n$||_d|_| d¡|jrB| ¡dS)Nr)ÚosÚpathÚisdirÚfilenameÚdirnamer3r0)r.r;rrrÚ set_filename™s zIOBinding.set_filenamecCsÊ|jj}|rt|s| ¡}n|}|r`|jrTt|jddƒsT|jsT| ¡rT| ||j¡qp| |¡n|jrp|j  ¡dS| ¡rš|  ¡}|dkrš|j  ¡dS|s¨| ¡}n|}|r¼| |¡n |j  ¡dS)NÚinterpÚbreakÚcancel) r ÚflistÚ askopenfileÚgetattrr;r2r#Úloadfiler!Ú focus_setÚ maybesave)r.ÚeventZeditFilerAr;Úreplyrrrr#¤s6       zIOBinding.openz (\r\n)|\n|\rc CsBy|j j   ¡t d d t|j j d }|rnt ||ƒ}d|_|dfSttfk rŽYnXdS)zCreate a Unicode string.Nézutf-8)NFÚBOMFzError loading the filez^The encoding '%s' is not known to this Python installation. The file may not display correctly)ÚtitleÚmessagerJr zSpecify 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?)Z initialvaluerJT)Ú startswithrrÚUnicodeDecodeErrorr+rrrQrRr!rSr ÚupdaterÚencoding)r.r\rr^ÚencrrrrrTøsh         zIOBinding._decodecCsp| ¡r dSd|jpd}tjd|tj|jd}|rPd}| d¡| ¡sbd}n|dkr^d}nd}|j ¡|S)NZyesz&Do you want to save %s before closing?zthis untitled documentz Save On Close)rarbÚdefaultrJr@Zno)r2r;rQZaskyesnocancelZYESr!r%rE)r.rbÚconfirmrHrrrrF<s&    zIOBinding.maybesavecCsZ|js| |¡n:| |j¡rL| d¡y|j ¡Wntk rJYnX|j ¡dS)NTr?) r;r'Ú writefiler3r Ústore_file_breaksÚAttributeErrorr!rE)r.rGrrrr%Rs    zIOBinding.savecCsf| ¡}|rN| |¡rN| |¡| d¡y|j ¡Wntk rLYnX|j ¡|  |¡dS)Nrr?) Ú asksavefilerjr=r3r rkrlr!rErZ)r.rGr;rrrr'_s     zIOBinding.save_ascCs.| ¡}|r| |¡|j ¡| |¡dS)Nr?)rmrjr!rErZ)r.rGr;rrrr)ms    zIOBinding.save_a_copyc CsŠ| ¡}| |¡}y:t|dƒ&}| |¡| ¡t | ¡¡WdQRXdStk r„}zt j dt |ƒ|j ddSd}~XYnXdS)NÚwbTz I/O Error)rJF) Ú fixnewlinesÚencoder#ÚwriteÚflushr8ÚfsyncÚfilenorPrQrRrSr!)r.r;r!r^r[r]rrrrjus     zIOBinding.writefilecCsT|j d¡dkr*t|jdƒs*|j dd¡|j dd¡}|jdkrP| d|j¡}|S)z/Return text with final if needed and os eols.zend-2cr r>zend-1cz1.0)r!ÚgetÚhasattrr rLrWÚreplace)r.r!rrrroƒs  zIOBinding.fixnewlinesc CsÚt|tƒr|S|jdkr&t| d¡Sy | d¡Stk rDYnXyt|ƒ}d}Wn*tk r€}z |}d}Wdd}~XYn X|sŠd}|r¶y | |¡Stk r´d|}YnXtj dd||j dt| d¡S)Nr`zutf-8r zInvalid encoding '%s'z I/O Errorz%s. Saving as UTF-8)rJ) r rr+rrpÚ UnicodeErrorrrrQrRr!)r.r^rgZfailedr]rrrrps4     zIOBinding.encodecCsdtjddtj|jd}|s(|j ¡dSd}| ¡}|r>|j}|rJ|dkr€tjdd\}}|}t   |¡|  |¡s€t   |¡dSt j }d}|dkrªt d d d ¡} | d } n|d krÂt d d d¡} nd}|r6| t |¡} t  | d¡} |  ¡ ¡} |   ¡} | r d| | } | rPdt| ƒ| } tjd| |jdnd|} tjd| |jd|r`t   |¡dS)NZPrintzPrint to Default Printer)rarbrhrJr?Z IDLE_tmp_)ÚprefixTÚposixÚmainZGeneralzprint-command-posixz 2>&1Úntzprint-command-winFÚrz#Printing failed (exit status 0x%x) zPrinting command: %s z Print status)rJz-Printing is not enabled for this platform: %s)rQZ askokcancelZOKr!rEr2r;ÚtempfileZmkstempr8r1rjÚunlinkrrZ GetOptionÚshlexZquoteÚpopenrOÚstripÚreprrRZshowinfo)r.rGriZ tempfilenameZsavedr;ZtfdÚplatformZ printPlatformZcommandÚpipeÚoutputZstatusrbrrrr,´sX           zIOBinding.print_window))z Python filesz *.py *.pywÚTEXT)z Text filesz*.txtr‡)z All filesÚ*Údarwinz.pyrcCs<| d¡\}}|js(tj|j|jd|_|jj||d}|S)Nr#)rJÚ filetypes)Ú initialdirÚ initialfile)ÚdefaultfilenameÚ opendialogÚ tkFileDialogZOpenr!rŠÚshow)r.ÚdirÚbaser;rrrrBñs  zIOBinding.askopenfiler#cCsV|jrtj |j¡S|jr$|jdfSy t ¡}Wntk rHd}YnX|dfSdS)Nr)r;r8r9rr<ÚgetcwdrP)r.ÚmodeÚpwdrrrrùs   zIOBinding.defaultfilenamecCs@| d¡\}}|js,tj|j|j|jd|_|jj||d}|S)Nr%)rJrŠÚdefaultextension)r‹rŒ)rÚ savedialogrZSaveAsr!rŠr–r)r.r‘r’r;rrrrms zIOBinding.asksavefilecCs|jjr|j |¡dS)z-Update recent file list on all editor windowsN)r rAZupdate_recent_files_list)r.r;rrrrZszIOBinding.updaterecentfileslist)NN)r#))Ú__name__Ú __module__Ú __qualname__r/r1r2r3r5r0r7r;r<r=r#ZeolÚreÚcompilerUr8ÚlineseprWrDrTrFr%r'r)rjrorpr,rŽr—rŠÚsysr„r–rBrrmrZrrrrrks@   , $D  '2  rc Cs’ddlm}m}||ƒ}| d¡tt| ¡ d¡dd…ƒ\}}| d||df¡Gdd „d ƒ}||ƒ}| ¡|  ¡||ƒ}t |ƒdS) Nr)ÚToplevelÚTextzTest IOBindingú+rz+%d+%dé¯c@sTeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)z_io_binding..MyEditWincSs`||_d|_|j d|j¡|j d|j¡|j d|j¡|j d|j¡|j d|j¡dS)Nz z z zz )r!rAr"r#Úprintr%ÚsaveasÚsavecopy)r.r!rrrr/sz'_io_binding..MyEditWin.__init__cSsdS)Nrr)r.rrrr2$óz(_io_binding..MyEditWin.get_savedcSsdS)Nr)r.r4rrrr3%r¦z(_io_binding..MyEditWin.set_savedcSsdS)Nr)r.rrrr5&r¦z)_io_binding..MyEditWin.reset_undocSs|j d¡dS)Nz<>)r!Úevent_generate)r.rGrrrr#'sz#_io_binding..MyEditWin.opencSs|j d¡dS)Nz<>)r!r§)r.rGrrrr£)sz$_io_binding..MyEditWin.printcSs|j d¡dS)Nz<>)r!r§)r.rGrrrr%+sz#_io_binding..MyEditWin.savecSs|j d¡dS)Nz<>)r!r§)r.rGrrrr¤-sz%_io_binding..MyEditWin.saveascSs|j d¡dS)Nz<>)r!r§)r.rGrrrr¥/sz'_io_binding..MyEditWin.savecopyN) r˜r™ršr/r2r3r5r#r£r%r¤r¥rrrrÚ MyEditWinsr¨) ZtkinterrŸr raÚmapÚintZgeometryrZpackrEr) rJrŸr ÚrootÚxÚyr¨r!r rrrÚ _io_bindings  r®Ú__main__)r{zidlelib.idle_test.test_iomenur F)Ú verbosityÚexit)Úrun)1rrr8r›r€ržr~Ztkinter.filedialogZ filedialogrZtkinter.messageboxZ messageboxrQZtkinter.simpledialogrZidlelibZidlelib.configrZtestingrfÚerrorsZlocaleÚ setlocaleÚLC_CTYPEÚ ImportErrorÚErrorr„Ú nl_langinfoÚCODESETZlocale_encodingrÚ NameErrorrlrZgetdefaultlocaleÚ ValueErrorÚlowerrœÚASCIIrrrrr®r˜Zunittestr{Zidlelib.idle_test.htestr²rrrrÚsf         ),$