Merge pull request #1563 from pbrod/Fix_issue1555

Fixes issue 1555
This commit is contained in:
Robin Dunn
2020-03-20 15:06:21 -07:00
committed by GitHub

View File

@@ -839,16 +839,12 @@ class ShellFrameMixin:
def SaveHistory(self):
if self.dataDir:
try:
name = os.path.join(self.dataDir, 'history')
f = open(name, 'wb')
hist = []
enc = 'utf-8'
for h in self.shell.history:
h = h.encode(enc)
hist.append(h)
hist = b'\x00\n'.join(hist)
f.write(hist)
f.close()
hist = b'\x00\n'.join([h.encode(enc)
for h in self.shell.history])
name = os.path.join(self.dataDir, 'history')
with open(name, 'wb') as f:
f.write(hist)
except:
d = wx.MessageDialog(self, "Error saving history file.",
"Error", wx.ICON_EXCLAMATION|wx.OK)
@@ -861,9 +857,9 @@ class ShellFrameMixin:
name = os.path.join(self.dataDir, 'history')
if os.path.exists(name):
try:
f = open(name, 'rb')
hist = f.read()
f.close()
with open(name, 'rb') as f:
hist = f.read()
enc = 'utf-8'
hist = [h.decode(enc) for h in hist.split(b'\x00\n')]
self.shell.history = hist
@@ -908,9 +904,8 @@ class ShellFrameMixin:
## d.Destroy()
try:
f = open(fileName, "w")
f.write(text)
f.close()
with open(fileName, "w") as f:
f.write(text)
except:
d = wx.MessageDialog(self, u'Error saving session',u'Error',
wx.OK | wx.ICON_ERROR)
@@ -923,8 +918,8 @@ class ShellFrameMixin:
import io
# Use newline=None to translate \n \r \r\n to \n on read. The
# old-style mode='U' is deprecated.
text = io.open(self.startupScript, 'r',
newline=None, encoding='utf-8').read()
with io.open(self.startupScript, 'r', newline=None, encoding='utf-8') as fid:
text = fid.read()
else:
text = ''
@@ -932,9 +927,8 @@ class ShellFrameMixin:
if dlg.ShowModal() == wx.ID_OK:
text = dlg.GetText()
try:
f = open(self.startupScript, 'wb')
f.write(text.encode('utf-8'))
f.close()
with open(self.startupScript, 'wb') as f:
f.write(text.encode('utf-8'))
except:
d = wx.MessageDialog(self, "Error saving startup file.",
"Error", wx.ICON_EXCLAMATION|wx.OK)