showerror('pyedit''could not decode and open file fileelseself setalltext(textself setfilename(fileself text edit_reset( clear undo/redo stks self text edit_modified( clear modified flag def onsave(self)self onsaveas(self currfilemay be none def onsaveas(selfforcefile=none)"" total rewrite for unicode supporttext content is always returned as strso we must deal with encodings to save to file hereregardless of open mode of the output file (binary requires bytesand text must encode)tries the encoding used when opened or saved (if known)user inputconfig file settingand platform default lastmost users can use platform defaultretains successful encoding name here for next savebecause this may be the first save after new or manual text insertionsave and saveas may both use last known encodingper config file (it probably should be used for savebut saveas usage is unclear)gui prompts are prefilled with the known encoding if there is onedoes manual text encode(to avoid creating filetext mode files perform platform specific end-line conversionwindows \ dropped if present on open by text mode (autoand binary mode (manually)if manual content insertsmust delete \ else duplicates hereknownencoding=none before first open or saveafter newif binary openencoding behavior is configurable in the local textconfig py if savesuseknownencoding try encoding from last open or save if savesaskuser truetry user input next (prefill with known? if savesencoding nonemptytry this encoding next'utf- 'etc tries sys getdefaultencoding(as last resort ""filename forcefile or self my_asksaveasfilename(if not filenamereturn text self getalltext(encpick none str stringwith \ eolnseven if read/inserted as bytes try known encoding at latest open or saveif any if self knownencoding and (forcefile and self savesuseknownencoding > or (not forcefile and self savesuseknownencoding > ))trytext encode(self knownencodingencpick self knownencoding except unicodeerrorpass enc knownon saveon saveaspyedita text editor program/object