diff --git a/command_seq_reader.py b/command_seq_reader.py index 8e63d35..1c3aff3 100644 --- a/command_seq_reader.py +++ b/command_seq_reader.py @@ -21,7 +21,7 @@ def items_of_interest(dct, types_of_interest): return [(k, v) for (k, v) in dct.items() if isinstance(v, types_of_interest)] -def recordingexec(arg, types_of_interest = (int, basestring)): +def recordingexec(arg, types_of_interest = (int, str)): cmdbuf = [] lastcmd = '' commandInProgress = [] @@ -41,14 +41,14 @@ def recordingexec(arg, types_of_interest = (int, basestring)): commandInProgress = [] except IndentationError: pass - except SyntaxError, e: + except SyntaxError as e: if not commandUnfinished.search(str(e)): raise - except Exception, e: - raise Exception, '%s:\n%s' % (e, line) + except Exception as e: + raise Exception(f'{e}:\n{line}') return (lastcmd, dict(lastlocals)) -def last_assignment_or_evaluatable(s, types_of_interest=(basestring, int, float)): +def last_assignment_or_evaluatable(s, types_of_interest=(str, int, float)): s = s.strip() if not s: return None @@ -56,12 +56,12 @@ def last_assignment_or_evaluatable(s, types_of_interest=(basestring, int, float) (lastcmd, lastlocals) = recordingexec(s, types_of_interest) try: return eval(lastcmd) - except SyntaxError, e: + except SyntaxError as e: if 'invalid syntax' not in str(e): raise if len(lastlocals) > 1: - raise ValueError, "Multiple assignments - couldn't determine which one" - return eval(lastlocals.keys()[0]) + raise ValueError("Multiple assignments - couldn't determine which one") + return eval(next(lastlocals.keys())) class RecordingExecTestSuite(unittest.TestCase): def testSimpleAssignments(self): @@ -78,7 +78,7 @@ def testIgnoreObj(self): uts = unittest.TestSuite() ''', (unittest.TestSuite)) self.assertEqual(lastcmd, 'uts = unittest.TestSuite()') - self.assertEqual(lastlocals.keys(), ['uts']) + self.assertEqual(list(lastlocals.keys()), ['uts']) def testExecutableLastLine(self): (lastcmd, lastlocals) = recordingexec(''' a = 1 @@ -116,4 +116,4 @@ def testEmpty(self): if __name__ == '__main__': #unittest.main() - doctest.testmod() \ No newline at end of file + doctest.testmod() diff --git a/pyparsing_helper.py b/pyparsing_helper.py index 5f483a0..a06789b 100755 --- a/pyparsing_helper.py +++ b/pyparsing_helper.py @@ -8,7 +8,7 @@ By Catherine Devlin (http://catherinedevlin.blogspot.com) ''' -from Tkinter import * +from tkinter import * from command_seq_reader import last_assignment_or_evaluatable import pyparsing import time, threading, functools, string, optparse, sys @@ -25,14 +25,14 @@ def _eq_monkeypatch(self, other): if isinstance(other, pyparsing.ParserElement): return self.__dict__ == other.__dict__ - elif isinstance(other, basestring): + elif isinstance(other, str): try: (self + StringEnd()).parseString(_ustr(other)) return True - except ParseBaseException: + except pyparsing.ParseBaseException: return False else: - return super(ParserElement,self)==other + return super(pyparsing.ParserElement, self) == other pyparsing.ParserElement.__eq__ = _eq_monkeypatch @@ -79,8 +79,8 @@ def apply_grammar(self, i): result = self.grammar.transformString(target) else: result = self.grammar.parseString(target).dump() - except Exception, e: - result = '%s\n%s' % (str(e.__class__), str(e)) + except Exception as e: + result = f'{e.__class__}\n{e}' self.set_result(i, result) def set_result(self, i, txt): @@ -97,14 +97,14 @@ def set_all_results(self, txt): def reparse(self, event=None): self.grammar = self.grammar_text.get(1.0, END).strip() if self.grammar: - self.grammar = '%s\n%s' % (self.import_type.get(), self.grammar) + self.grammar = f'{self.import_type.get()}\n{self.grammar}' try: self.grammar = last_assignment_or_evaluatable(self.grammar, types_of_interest=(pyparsing.ParserElement)) for i in range(self.num_targets): self.apply_grammar(i) - except Exception, e: + except Exception as e: if hasattr(e, 'text'): - errtxt = '%s\n\n%s' % (str(e), e.text) + errtxt = f'{e}\n\n{e.text}' else: errtxt = str(e) self.set_all_results(errtxt) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5d2de54 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=46.1.0", "wheel"] +build-backend = "setuptools.build_meta"