[!M@sddlZddlZddlZddlZddlZddlZddljZddl j Z ddl Z ddl TddlmZddlmZddlmZy#ddlZejejdWneejfk rYnXejZdZejdkrGy!ejd ZejeWnek rCYnXnyDejej Zedkpqedkr}dZnejeWnxe!e"efk ryBejd ZedkpedkrdZnejeWne#efk rYnXYnXej$ZeZ%e j&d e j'Z(e j&d e j'Z)d d Z*GdddZ+ddZ,e-dkrddl.m/Z/e/e,ndS)N)*) askstring)idleConf)BOM_UTF8asciiZwin32z%^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)z^[ \t\f]*(?:[#\r\n]|$)c Cst|tr!|jd}n|}d|krR|jdddd}n4d|kr}|jdddd}n |g}xD|D]8}tj|}|dk rPntj|sdSqWdS|jd}ytj |Wn"t k rt 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: ) isinstancebytesdecodesplit coding_rematchblank_regroupcodecslookup LookupError)datalinesZlstlinernamer'/usr/lib/python3.4/idlelib/IOBinding.py coding_specEs*       rc@seZdZddZddZddZddZd d Zd Zd d Z d Z d Z ddZ d d ddZ dZejeZejZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd Zd Z d:d;d<gZ!e"j#d.krJd/nd0Z$d1d2Z%d3d4d5Z&d6d7Z'd8d9Z(d S)= IOBindingcCs||_|j|_|jjd|j|_|jjd|j|_|jjd|j|_|jjd|j |_ d|_ |jjd|j |_ dS)Nz<>z<>z<>z<>z<>)editwintextbindopen_IOBinding__id_opensave_IOBinding__id_savesave_as_IOBinding__id_saveas save_a_copy_IOBinding__id_savecopy fileencoding print_window_IOBinding__id_print)selfrrrr__init__ps     zIOBinding.__init__cCs|jjd|j|jjd|j|jjd|j|jjd|j|jjd|jd|_d|_d|_dS)Nz<>z<>z<>z<>z<>) r Zunbindr#r%r'r)r,rfilename_change_hook)r-rrrclose|s  zIOBinding.closecCs |jjS)N)r get_saved)r-rrrr1szIOBinding.get_savedcCs|jj|dS)N)r set_saved)r-flagrrrr2szIOBinding.set_savedcCs|jjdS)N)r reset_undo)r-rrrr4szIOBinding.reset_undoNcCs ||_dS)N)r/)r-hookrrrset_filename_change_hooksz"IOBinding.set_filename_change_hookcCsf|r-tjj|r-d|_||_n5||_d|_|jd|jrb|jndS)Nr)ospathisdirfilenamedirnamer2r/)r-r:rrr set_filenames      zIOBinding.set_filenamecCs%|jj}|r|s'|j}n|}|r|jr~t|jdd r~|j r~|jr~|j||jq|j|n|jr|jj ndS|jr|j }|dkr|jj dSn|s|j}n|}|r|j|n |jj dS)NZinterpbreakcancel) rflist askopenfilegetattrr:r1r"loadfiler focus_set maybesave)r-eventZeditFiler?r:replyrrrr"s6          zIOBinding.openz (\r\n)|\n|\rc CsyKt|d6}|j|j}|jd|j}WdQXWnHtk r}z(tjdt|d|jdSWYdd}~XnX|j ||\}}|dkrtjdd|d|jdS|j j |}|r|j d|_ |j jd |}n|jjd d |jd|jjd ||j|j||r}|jdn|jjd d |jjd |j|d S)Nrbrz I/O ErrormasterFzDecoding ErrorzFile %s Failed to Decodeparentz\nz1.0endinsertT)r"readlineseekreadOSError tkMessageBox showerrorstrr _decodeeol_researchreol_conventionsubZdeleter<rKr4r2Zmark_setZyviewupdaterecentfileslist) r-r:f two_linesr msgcharsZ convertedZfirsteolrrrrBs:         zIOBinding.loadfilec;Csd}|jtray|ddjd}Wntk rJdSYqaXd|_|dfSnyt|}Wnctk r}z.tjdddd |d |j d}WYdd}~Xntk rdSYnX|ry&t ||}||_|dfSWqtk rYqXny&t |d }d|_|dfSWntk rUYnXy&t |d}d|_|dfSWntk rYnXy`|j j j t d d dtd|j j }|rt ||}d|_n|dfSWnttfk r YnXdS)zCreate a Unicode string.Nzutf-8FBOMtitlezError loading the filemessagez^The encoding '%s' is not known to this Python installation. The file may not display correctlyrHrzSpecify 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 initialvaluerIT)NF)NF)NF) startswithrrUnicodeDecodeErrorr*rrrPrQr rRrupdaterlocale_encoding)r-rZr r\encrrrrrSsh               zIOBinding._decodec Cs|jrdSd|jpd}tjddd|dtjd|j}|r~d}|jd|jsd }qn|dkrd }nd }|jj|S) NZyesz&Do you want to save %s before closing?zthis untitled documentr_z Save On Closer`defaultrHr>Zno)r1r:rPZaskyesnocancelZYESr r$rC)r-r`confirmrFrrrrD<s&          zIOBinding.maybesavec Csr|js|j|nH|j|jra|jdy|jjWqatk r]YqaXn|jjdS)NTr=) r:r& writefiler2rstore_file_breaksAttributeErrorr rC)r-rErrrr$Rs    zIOBinding.savec Cs|j}|rg|j|rg|j||jdy|jjWqdtk r`YqdXqgn|jj|j |dS)Nrr=) asksavefilerhr<r2rrirjr rCrX)r-rEr:rrrr&_s       zIOBinding.save_ascCs@|j}|r"|j|n|jj|j|dS)Nr=)rkrhr rCrX)r-rEr:rrrr(ms    zIOBinding.save_a_copycCs|j|jjdd}|jdkrF|jd|j}n|j|}y-t|d}|j|WdQXdSWnHtk r}z(t j dt |d|jdSWYdd}~XnXdS) Nz1.0zend-1cr wbTz I/O ErrorrHF) fixlastliner getrVreplaceencoder"writerOrPrQrR)r-r:r r\rYr[rrrrhus  zIOBinding.writefilec#Cst|tr|S|jdkr3t|jdSy|jdSWntk rXYnXyt|}d}Wn1tk r}z|}d}WYdd}~XnX|sd}n|ry|j|SWqtk rd|}YqXntj dd|d|j t|jdS)Nr^zutf-8rzInvalid encoding '%s'z I/O Errorz%s. Saving as UTF-8rH) r r r*rrp UnicodeErrorrrrPrQr )r-r\reZfailedr[rrrrps4       zIOBinding.encodecCs8|jjd}|dkr4|jjddndS)Nzend-2cr zend-1c)r rnrK)r-crrrrms zIOBinding.fixlastlinec Cstjdddddtjd|j}|sA|jjdSd}|j}|re|j}n| sx|dkrtjdd \}}|}t j ||j |st j |dSnt j }d }|d krtjd d d} | d} n*|dkr'tjd d d} nd}|r| tj|} t j| d} | jj} | j } | rd| | } n| rdt| | } tjd| d|jqn#d|} tjd| d|j|rt j |ndS)Nr_ZPrintr`zPrint to Default PrinterrfrHr=prefixZ IDLE_tmp_TposixmainZGeneralzprint-command-posixz 2>&1ntzprint-command-winFrz#Printing failed (exit status 0x%x) zPrinting command: %s z Print statusz-Printing is not enabled for this platform: %s)rPZ askokcancelZOKr rCr1r:tempfileZmkstempr7r0rhunlinkrrZ GetOptionshlexZquotepopenrNstripreprrQZshowinfo)r-rErgZ tempfilenameZsavedr:ZtfdplatformZ printPlatformZcommandpipeoutputZstatusr`rrrr+sX                zIOBinding.print_window Python files *.py *.pywTEXT Text files*.txt All filesrdarwinz.pyrcCsa|jd\}}|jsBtjd|jd|j|_n|jjd|d|}|S)Nr"rH filetypes initialdir initialfile)defaultfilename opendialog tkFileDialogZOpenr rshow)r-dirbaser:rrrr@s  zIOBinding.askopenfiler"c Csk|jrtjj|jS|jr2|jdfSytj}Wntk r\d}YnX|dfSdS)Nr)r:r7r8rr;getcwdrO)r-modepwdrrrrs     zIOBinding.defaultfilenamecCsj|jd\}}|jsKtjd|jd|jd|j|_n|jjd|d|}|S)Nr$rHrdefaultextensionrr)r savedialogrZSaveAsr rrr)r-rrr:rrrrks    zIOBinding.asksavefilecCs#|jjr|jj|ndS)z-Update recent file list on all editor windowsN)rr?Zupdate_recent_files_list)r-r:rrrrX s zIOBinding.updaterecentfileslist)rrr)rrr)rr))__name__ __module__ __qualname__r.r0r1r2r4r/r6r:r;r<r"ZeolrecompilerTr7lineseprVrBrSrDr$r&r(rhrprmr+rrrsysrrr@rrkrXrrrrrnsD      ,  $ D     '  2   rc Cst}|jdttttjd|j\}}}}|jd||dfGddd}t|}|j |j ||}t |} dS)NzTest IOBindingz[x+]z+%d+%dc@sXeZdZddZddZddZddZd d Zd d Zd S)z_io_binding..MyEditWincSsB||_d|_|jjd|j|jjd|jdS)Nz z )r r?r!r"r$)r-r rrrr.s  z'_io_binding..MyEditWin.__init__cSsdS)Nrr)r-rrrr1sz(_io_binding..MyEditWin.get_savedcSsdS)Nr)r-r3rrrr2sz(_io_binding..MyEditWin.set_savedcSsdS)Nr)r-rrrr4sz)_io_binding..MyEditWin.reset_undocSs|jjddS)Nz<>)r event_generate)r-rErrrr"sz#_io_binding..MyEditWin.opencSs|jjddS)Nz<>)r r)r-rErrrr$ sz#_io_binding..MyEditWin.saveN) rrrr.r1r2r4r"r$rrrr MyEditWins      r) ZTkr_listmapintrrZgeometryZTextZpackrCr) rIrootwidthZheightxyrr riorrr _io_bindings  3    r__main__)run)0r7typesr{rrryZtkinter.filedialogZ filedialogrZtkinter.messageboxZ messageboxrPrZtkinterZtkinter.simpledialogrZidlelib.configHandlerrrZlocale setlocaleLC_CTYPE ImportErrorErrorgetfilesystemencodingZfilesystemencodingrdrZgetdefaultlocalerr nl_langinfoCODESET NameErrorrj ValueErrorlowerencodingrASCIIrrrrrrZidlelib.idle_test.htestrrrrrsb                )