Skip to content

Commit

Permalink
Log viewer/Python 3: save log file in UTF-8 format. Re nvaccess#9038.
Browse files Browse the repository at this point in the history
Reviewed by Mick Curran (NV Access): open log file for saving with UTF-8 encoding from the start. Note that Python 2's open function does not include encoding parameter directly, but Python 3 does.
  • Loading branch information
josephsl committed Jun 5, 2019
1 parent b3df158 commit 8bc558d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions source/gui/logViewer.py
Expand Up @@ -80,8 +80,9 @@ def onSaveAsCommand(self, evt):
try:
# codecs.open() forces binary mode, which is bad under Windows because line endings won't be converted to crlf automatically.
# Therefore, do the encoding manually.
# #9038 (Py3 review required): although eligible for "with open" function conversion, encoding issue must be settled first.
file(filename, "w").write(self.outputCtrl.GetValue().encode("UTF-8"))
# #9038: work with UTF-8 from the start.
with open(filename, "w", encoding="UTF-8") as f:
f.write(self.outputCtrl.GetValue())
except (IOError, OSError), e:
# Translators: Dialog text presented when NVDA cannot save a log file.
gui.messageBox(_("Error saving log: %s") % e.strerror, _("Error"), style=wx.OK | wx.ICON_ERROR, parent=self)
Expand Down

0 comments on commit 8bc558d

Please sign in to comment.