Fix multiple Python 3 compatibility issues

Changes in Python 3 that made the code choke:

  o basestring is merged into str
  o print() needs parentesis
  o Class inheritance syntax changed
  o Abstract baseclass (ABCMeta) syntax changed
  o map.iteritems() is replaced by map.items()
  o Inconsistent use of tabs and spaces are no longer tolerated

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2019-03-10 16:38:59 +01:00
commit 6dd594d47b
8 changed files with 44 additions and 32 deletions

View file

@ -2,6 +2,12 @@ from collections import namedtuple
import re
import shlex
# --- python 2 / 3 compatibility stuff
try:
basestring
except NameError:
basestring = str
L, R = 'Left Right'.split()
ARG, KEYW, QUOTED, LPAREN, RPAREN = 'arg kw quoted ( )'.split()
@ -49,7 +55,7 @@ class ShuntingYard(object): # export
for count, thing in enumerate(args):
msg += ' ' + str(thing)
if len(msg):
print msg[1:]
print(msg[1:])
def token_string(self):
r = ""
@ -65,7 +71,7 @@ class ShuntingYard(object): # export
if len(r):
return r[2:]
return r
return r
def tokenize(self, spec):
@ -162,9 +168,9 @@ class ShuntingYard(object): # export
if self.do_debug:
maxcolwidths = [len(max(x, key=len)) for x in zip(*table)]
row = table[0]
print( ' '.join('{cell:^{width}}'.format(width=width, cell=cell) for (width, cell) in zip(maxcolwidths, row)))
print(' '.join('{cell:^{width}}'.format(width=width, cell=cell) for (width, cell) in zip(maxcolwidths, row)))
for row in table[1:]:
print( ' '.join('{cell:<{width}}'.format(width=width, cell=cell) for (width, cell) in zip(maxcolwidths, row)))
print(' '.join('{cell:<{width}}'.format(width=width, cell=cell) for (width, cell) in zip(maxcolwidths, row)))
return table[-1][2]
def infix_to_postfix_orig(self, infix):