forked from Mirrors/apostrophe
Use io instead of codec
Drop the deprecated codec module for parsing files. Better handling of file URIsui^2
parent
66af5f8217
commit
0647b41340
|
@ -14,7 +14,7 @@
|
|||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# END LICENSE
|
||||
|
||||
import codecs
|
||||
import io
|
||||
import locale
|
||||
import logging
|
||||
import os
|
||||
|
@ -218,7 +218,7 @@ class MainWindow(StyledWindow):
|
|||
if self.filename:
|
||||
LOGGER.info("saving")
|
||||
filename = self.filename
|
||||
file_to_save = codecs.open(filename, encoding="utf-8", mode='w')
|
||||
file_to_save = io.open(filename, encoding="utf-8", mode='w')
|
||||
file_to_save.write(self.text_view.get_text())
|
||||
file_to_save.close()
|
||||
if self.did_change:
|
||||
|
@ -252,7 +252,7 @@ class MainWindow(StyledWindow):
|
|||
except:
|
||||
pass
|
||||
|
||||
file_to_save = codecs.open(filename, encoding="utf-8", mode='w')
|
||||
file_to_save = io.open(filename, encoding="utf-8", mode='w')
|
||||
file_to_save.write(self.text_view.get_text())
|
||||
file_to_save.close()
|
||||
|
||||
|
@ -293,7 +293,7 @@ class MainWindow(StyledWindow):
|
|||
except:
|
||||
pass
|
||||
|
||||
file_to_save = codecs.open(filename, encoding="utf-8", mode='w')
|
||||
file_to_save = io.open(filename, encoding="utf-8", mode='w')
|
||||
file_to_save.write(self.text_view.get_text())
|
||||
file_to_save.close()
|
||||
|
||||
|
@ -437,16 +437,18 @@ class MainWindow(StyledWindow):
|
|||
|
||||
def load_file(self, filename=None):
|
||||
"""Open File from command line or open / open recent etc."""
|
||||
LOGGER.info("trying to open " + filename)
|
||||
if self.check_change() == Gtk.ResponseType.CANCEL:
|
||||
return
|
||||
|
||||
if filename:
|
||||
print(urllib.parse.unquote(filename))
|
||||
if filename.startswith('file://'):
|
||||
filename = filename[7:]
|
||||
filename = urllib.parse.unquote(filename)[7:]
|
||||
self.text_view.clear()
|
||||
try:
|
||||
if os.path.exists(filename):
|
||||
with codecs.open(filename, encoding="utf-8", mode='r') as current_file:
|
||||
with io.open(filename, encoding="utf-8", mode='r') as current_file:
|
||||
self.text_view.set_text(current_file.read())
|
||||
else:
|
||||
dialog = Gtk.MessageDialog(self,
|
||||
|
|
Loading…
Reference in New Issue