Skip to content

Commit 17f47a6

Browse files
committed
Re-establish try/except for file open errors after Micropython glitch has been fixed
1 parent d0e9871 commit 17f47a6

File tree

6 files changed

+18
-40
lines changed

6 files changed

+18
-40
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ c) expandtabs() and packtabs() with a second argument for tabsize (not for pye,
9292
- Removed skipping to the adjacent line with Right/Left in the WiPy Version
9393
- Temporary avoidance of the memory leak when a file is not found
9494

95+
**1.7c** Re-establish try-except for file-not-found error
96+
- Removed the temporary fix for memory corruption by exception for file-not-found error
97+
- Changed string formatting to Python3 style

pe.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ def handle_cursor_keys(self, key):
317317
self.cur_line = max(self.cur_line, self.top_line)
318318
self.scroll_down(3)
319319
elif key == 0x01:
320-
pat = self.line_edit("Case Sensitive Search %c, Autoindent %c, Tab Size %d, Write Tabs %c: " %
321-
(self.case, self.autoindent, self.tab_size, self.write_tabs), "")
320+
pat = self.line_edit("Case Sensitive Search {}, Autoindent {}, Tab Size {}, Write Tabs {}: ".format(self.case, self.autoindent, self.tab_size, self.write_tabs), "")
322321
try:
323322
res = [i.strip().lower() for i in pat.split(",")]
324323
if res[0]: self.case = 'y' if res[0][0] == 'y' else 'n'
@@ -562,12 +561,11 @@ def packtabs(self, s):
562561
sb.write(c)
563562
return sb.getvalue()
564563
def get_file(self, fname):
565-
from os import listdir
566-
if fname in listdir():
564+
try:
567565
with open(fname) as f:
568566
content = f.readlines()
569-
else:
570-
message = 'File {!r} is not in the local directory'.format(fname)
567+
except Exception as err:
568+
message = 'Could not load {}, {!r}'.format(fname, err)
571569
return (None, message)
572570
for i in range(len(content)):
573571
content[i] = self.expandtabs(content[i].rstrip('\r\n\t '))

pemin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,11 @@ def expandtabs(self, s):
408408
else:
409409
return s
410410
def get_file(self, fname):
411-
from os import listdir
412-
if fname in listdir():
411+
try:
413412
with open(fname) as f:
414413
content = f.readlines()
415-
else:
416-
message = 'File {!r} is not in the local directory'.format(fname)
414+
except Exception as err:
415+
message = 'Could not load {}, {!r}'.format(fname, err)
417416
return (None, message)
418417
for i in range(len(content)):
419418
content[i] = self.expandtabs(content[i].rstrip('\r\n\t '))

pye.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ def handle_cursor_keys(self, key): ## keys which move, sanity checks later
524524
self.cur_line = max(self.cur_line, self.top_line)
525525
self.scroll_down(3)
526526
elif key == KEY_TOGGLE: ## Toggle Autoindent/Statusline/Search case
527-
pat = self.line_edit("Case Sensitive Search %c, Autoindent %c, Tab Size %d, Write Tabs %c: " %
528-
(self.case, self.autoindent, self.tab_size, self.write_tabs), "")
527+
pat = self.line_edit("Case Sensitive Search {}, Autoindent {}, Tab Size {}, Write Tabs {}: ".format(self.case, self.autoindent, self.tab_size, self.write_tabs), "")
529528
try:
530529
res = [i.strip().lower() for i in pat.split(",")]
531530
if res[0]: self.case = 'y' if res[0][0] == 'y' else 'n'
@@ -801,8 +800,7 @@ def packtabs(self, s):
801800
return sb.getvalue()
802801
#endif
803802
def get_file(self, fname):
804-
from os import listdir
805-
if fname in listdir():
803+
try:
806804
#ifdef LINUX
807805
if sys.implementation.name == "cpython":
808806
with open(fname, errors="ignore") as f:
@@ -811,8 +809,8 @@ def get_file(self, fname):
811809
#endif
812810
with open(fname) as f:
813811
content = f.readlines()
814-
else:
815-
message = 'File {!r} is not in the local directory'.format(fname)
812+
except Exception as err:
813+
message = 'Could not load {}, {!r}'.format(fname, err)
816814
return (None, message)
817815
for i in range(len(content)): ## strip and convert
818816
content[i] = self.expandtabs(content[i].rstrip('\r\n\t '))

tuning_pye.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,7 @@ def packtabs(s, tabsize = 8):
121121
@staticmethod
122122
def cls():
123123
Editor.wr(b"\x1b[2J")
124-
#
125-
# This is a safe place for the initial get_file function, which is replaced by another one
126-
# until the MiPy error about stalling about non-existing files is solved
127-
#
128-
def get_file(self, fname):
129-
try:
130-
#ifdef LINUX
131-
if sys.implementation.name == "cpython":
132-
with open(fname, errors="ignore") as f:
133-
content = f.readlines()
134-
else:
135-
#endif
136-
with open(fname) as f:
137-
content = f.readlines()
138-
except Exception as err:
139-
message = 'Could not load {}, {!r}'.format(fname, err)
140-
return (None, message)
141-
for i in range(len(content)): ## strip and convert
142-
content[i] = self.expandtabs(content[i].rstrip('\r\n\t '))
143-
return (content, "")
124+
144125

145126

146127

wipye.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,11 @@ def expandtabs(self, s):
414414
else:
415415
return s
416416
def get_file(self, fname):
417-
from os import listdir
418-
if fname in listdir():
417+
try:
419418
with open(fname) as f:
420419
content = f.readlines()
421-
else:
422-
message = 'File {!r} is not in the local directory'.format(fname)
420+
except Exception as err:
421+
message = 'Could not load {}, {!r}'.format(fname, err)
423422
return (None, message)
424423
for i in range(len(content)):
425424
content[i] = self.expandtabs(content[i].rstrip('\r\n\t '))

0 commit comments

Comments
 (0)