Kaydet (Commit) 57fadc88 authored tarafından Pedro Giffuni's avatar Pedro Giffuni

#i121496# - [PyUNO] Python3 support

Add initial python 3 compatibility to native scripts now that
pyuno supports python3.

This is the result of running the python 2to3 script with
conservative settings.

Still more porting work may be required and any regression
with the default Python 2.7.3 should be considered a bug.
üst 1a699e62
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
class _const: class _const:
class ConstError(TypeError): pass class ConstError(TypeError): pass
def __setattr__(self, name, value): def __setattr__(self, name, value):
if self.__dict__.has_key(name): if name in self.__dict__:
raise self.ConstError, "Can't rebind const(%s)"%name raise self.ConstError("Can't rebind const(%s)"%name)
self.__dict__[name] = value self.__dict__[name] = value
import sys import sys
......
...@@ -123,7 +123,7 @@ class AbstractL10nTool: ...@@ -123,7 +123,7 @@ class AbstractL10nTool:
try: try:
shutil.copy(inputfilename, outputfilename) shutil.copy(inputfilename, outputfilename)
except IOError: except IOError:
print "ERROR: Can not copy file '" + inputfilename + "' to " + "'" + outputfilename + "'" print("ERROR: Can not copy file '" + inputfilename + "' to " + "'" + outputfilename + "'")
sys.exit(-1) sys.exit(-1)
def extract(self): def extract(self):
...@@ -131,7 +131,7 @@ class AbstractL10nTool: ...@@ -131,7 +131,7 @@ class AbstractL10nTool:
f = open(self._options.outputfile, "w+") f = open(self._options.outputfile, "w+")
f.write(self.extract_file(self._options.inputfile)) f.write(self.extract_file(self._options.inputfile))
except IOError: except IOError:
print "ERROR: Can not write file " + self._options.outputfile print("ERROR: Can not write file " + self._options.outputfile)
else: else:
f.close() f.close()
...@@ -173,7 +173,7 @@ class AbstractL10nTool: ...@@ -173,7 +173,7 @@ class AbstractL10nTool:
dir = filename[:filename.rfind('/')] dir = filename[:filename.rfind('/')]
if os.path.exists(dir): if os.path.exists(dir):
if os.path.isfile(dir): if os.path.isfile(dir):
print "ERROR: There is a file '"+dir+"' where I want create a directory" print("ERROR: There is a file '"+dir+"' where I want create a directory")
sys.exit(-1) sys.exit(-1)
else: else:
return return
...@@ -181,7 +181,7 @@ class AbstractL10nTool: ...@@ -181,7 +181,7 @@ class AbstractL10nTool:
try: try:
os.makedirs(dir) os.makedirs(dir)
except IOError: except IOError:
print "Error: Can not create dir " + dir print("Error: Can not create dir " + dir)
sys.exit(-1) sys.exit(-1)
def test_options(self): def test_options(self):
...@@ -191,7 +191,7 @@ class AbstractL10nTool: ...@@ -191,7 +191,7 @@ class AbstractL10nTool:
( is_valid(opt.inputfile) and (( is_valid(opt.path_prefix) and is_valid(opt.path_postfix) ) or is_valid(opt.outputfile)) and \ ( is_valid(opt.inputfile) and (( is_valid(opt.path_prefix) and is_valid(opt.path_postfix) ) or is_valid(opt.outputfile)) and \
( ( is_valid(opt.input_sdf_file) and ( is_valid(opt.outputfile) or ( is_valid(opt.path_prefix) and is_valid(opt.path_postfix) ) or \ ( ( is_valid(opt.input_sdf_file) and ( is_valid(opt.outputfile) or ( is_valid(opt.path_prefix) and is_valid(opt.path_postfix) ) or \
( is_valid(opt.inputfile) and is_valid(opt.outputFile)) )))) ( is_valid(opt.inputfile) and is_valid(opt.outputFile)) ))))
print "Strange options ..." print("Strange options ...")
sys.exit( -1 ) sys.exit( -1 )
def read_inputfile_list(self): def read_inputfile_list(self):
...@@ -201,7 +201,7 @@ class AbstractL10nTool: ...@@ -201,7 +201,7 @@ class AbstractL10nTool:
f = open(self._options.inputfile[1:], "r") f = open(self._options.inputfile[1:], "r")
lines = [line.strip('\n') for line in f.readlines()] lines = [line.strip('\n') for line in f.readlines()]
except IOError: except IOError:
print "ERROR: Can not read file list " + self._options.inputfile[2:] print("ERROR: Can not read file list " + self._options.inputfile[2:])
sys.exit(-1) sys.exit(-1)
else: else:
f.close() f.close()
......
...@@ -38,7 +38,7 @@ class PseudoSet: ...@@ -38,7 +38,7 @@ class PseudoSet:
tmplist.extend(other) tmplist.extend(other)
return PseudoSet(self._remove_dupes(tmplist)) return PseudoSet(self._remove_dupes(tmplist))
else: else:
print "__or__(None)" print("__or__(None)")
def __sub__(self,other): def __sub__(self,other):
tmplist = [] tmplist = []
...@@ -46,7 +46,7 @@ class PseudoSet: ...@@ -46,7 +46,7 @@ class PseudoSet:
tmplist.extend(self._list) tmplist.extend(self._list)
[tmplist.remove(key) for key in other if key in tmplist] [tmplist.remove(key) for key in other if key in tmplist]
else: else:
print "__sub__(none)" print("__sub__(none)")
return PseudoSet(tmplist) return PseudoSet(tmplist)
def __and__(self, other): def __and__(self, other):
...@@ -55,13 +55,13 @@ class PseudoSet: ...@@ -55,13 +55,13 @@ class PseudoSet:
[tmplist.append(key) for key in self._list if key in other] [tmplist.append(key) for key in self._list if key in other]
return PseudoSet(tmplist) return PseudoSet(tmplist)
else: else:
print "__and__(None)" print("__and__(None)")
def __iter__(self): def __iter__(self):
return self._list.__iter__() return self._list.__iter__()
def __items__(self): def __items__(self):
return self._list.items() return list(self._list.items())
def __keys__(self): def __keys__(self):
return keys(self._list) return keys(self._list)
...@@ -70,7 +70,7 @@ class PseudoSet: ...@@ -70,7 +70,7 @@ class PseudoSet:
tmpdict = {} tmpdict = {}
for key in list: for key in list:
tmpdict[key] = 1 tmpdict[key] = 1
return tmpdict.keys() return list(tmpdict.keys())
# incomplete OrderedDict() class implementation # incomplete OrderedDict() class implementation
class PseudoOrderedDict(dict): class PseudoOrderedDict(dict):
...@@ -79,7 +79,7 @@ class PseudoOrderedDict(dict): ...@@ -79,7 +79,7 @@ class PseudoOrderedDict(dict):
def __init__(self, defaults={}): def __init__(self, defaults={}):
dict.__init__(self) dict.__init__(self)
for n,v in defaults.items(): for n,v in list(defaults.items()):
self[n] = v self[n] = v
def __setitem__(self, key, value): def __setitem__(self, key, value):
...@@ -105,10 +105,10 @@ class PseudoOrderedDict(dict): ...@@ -105,10 +105,10 @@ class PseudoOrderedDict(dict):
def iteritems(self): def iteritems(self):
#return self._valuelist #return self._valuelist
return zip(self._keylist, self._valuelist) return list(zip(self._keylist, self._valuelist))
def items(self): def items(self):
return zip(self._keylist,self._valuelist) return list(zip(self._keylist,self._valuelist))
def __keys__(self): def __keys__(self):
return self._keylist return self._keylist
...@@ -140,23 +140,23 @@ def _testdriver_set(): ...@@ -140,23 +140,23 @@ def _testdriver_set():
list1.append("e") list1.append("e")
if "a" in list: if "a" in list:
print "YEAH!" print("YEAH!")
a = PseudoSet(list) a = PseudoSet(list)
b = PseudoSet(list1) b = PseudoSet(list1)
print "a="+str(a) print("a="+str(a))
print "b="+str(b) print("b="+str(b))
print "a|b=" + str(a|b) print("a|b=" + str(a|b))
print "a="+str(a) print("a="+str(a))
print "b="+str(b) print("b="+str(b))
print "a&b=" + str(a&b) print("a&b=" + str(a&b))
print "a="+str(a) print("a="+str(a))
print "b="+str(b) print("b="+str(b))
print "a-b" + str(a-b) print("a-b" + str(a-b))
for key in a: for key in a:
print key print(key)
def _testdriver_dict(): def _testdriver_dict():
d = PseudoOrderedDict() d = PseudoOrderedDict()
...@@ -167,12 +167,12 @@ def _testdriver_dict(): ...@@ -167,12 +167,12 @@ def _testdriver_dict():
d["e"] = 5 d["e"] = 5
d["f"] = 6 d["f"] = 6
print "a="+str(d["a"]) print("a="+str(d["a"]))
print "e="+str(d["e"]) print("e="+str(d["e"]))
for key,value in d.iteritems(): for key,value in d.items():
print "d["+key+"]="+str(d[key]) print("d["+key+"]="+str(d[key]))
print "key="+str(key)+" value="+str(value) print("key="+str(key)+" value="+str(value))
print "keys="+str(d.keys()) print("keys="+str(list(d.keys())))
#_testdriver_dict() #_testdriver_dict()
...@@ -31,13 +31,13 @@ class SdfData: ...@@ -31,13 +31,13 @@ class SdfData:
self._filename = filename self._filename = filename
def __getitem__(self, key): def __getitem__(self, key):
if self._dict.has_key(key): if key in self._dict:
return self._dict[key] return self._dict[key]
else: else:
return None return None
def has_key(self, key): def has_key(self, key):
return self._dict.has_key(key) return key in self._dict
def __setitem__(self, key, value): def __setitem__(self, key, value):
self._dict[key] = value self._dict[key] = value
...@@ -50,7 +50,7 @@ class SdfData: ...@@ -50,7 +50,7 @@ class SdfData:
f = open(self._filename, "r") f = open(self._filename, "r")
lines = [line.rstrip('\n') for line in f.readlines()] lines = [line.rstrip('\n') for line in f.readlines()]
except IOError: except IOError:
print "ERROR: Trying to read "+ self._filename print("ERROR: Trying to read "+ self._filename)
raise raise
else: else:
f.close() f.close()
...@@ -63,11 +63,11 @@ class SdfData: ...@@ -63,11 +63,11 @@ class SdfData:
def write(self, filename): def write(self, filename):
try: try:
f = open(filename, "w+") f = open(filename, "w+")
for value in self._dict.itervalues(): for value in self._dict.values():
#f.write( repr(value)+"\n" ) #f.write( repr(value)+"\n" )
f.write(value + "\n") f.write(value + "\n")
except IOError: except IOError:
print "ERROR: Trying to write " + filename print("ERROR: Trying to write " + filename)
raise raise
else: else:
f.close() f.close()
......
...@@ -39,14 +39,14 @@ class Xtxex(AbstractL10nTool): ...@@ -39,14 +39,14 @@ class Xtxex(AbstractL10nTool):
return return
# merge usual lang # merge usual lang
sdfline = self.prepare_sdf_line(inputfilename,lang) sdfline = self.prepare_sdf_line(inputfilename,lang)
if sdfdata.has_key(sdfline.get_id()): if sdfline.get_id() in sdfdata:
line = sdfdata[sdfline.get_id()].text.replace("\\n", '\n') line = sdfdata[sdfline.get_id()].text.replace("\\n", '\n')
self.make_dirs(outputfilename) self.make_dirs(outputfilename)
try: try:
f = open(outputfilename, "w+") f = open(outputfilename, "w+")
f.write(line) f.write(line)
except IOError: except IOError:
print "ERROR: Can not write file " + outputfilename print("ERROR: Can not write file " + outputfilename)
sys.exit(-1) sys.exit(-1)
else: else:
f.close() f.close()
...@@ -62,7 +62,7 @@ class Xtxex(AbstractL10nTool): ...@@ -62,7 +62,7 @@ class Xtxex(AbstractL10nTool):
f = open(inputfile, "r") f = open(inputfile, "r")
lines = f.readlines() lines = f.readlines()
except IOError: except IOError:
print "ERROR: Can not open file " + inputfile print("ERROR: Can not open file " + inputfile)
sys.exit(-1) sys.exit(-1)
else: else:
f.close() f.close()
......
...@@ -25,7 +25,7 @@ import sys ...@@ -25,7 +25,7 @@ import sys
localeNames = {'fr': 'French', 'hu': 'Hungarian', 'de': 'German'} localeNames = {'fr': 'French', 'hu': 'Hungarian', 'de': 'German'}
def getLocaleName (code): def getLocaleName (code):
global localeNames global localeNames
if localeNames.has_key(code): if code in localeNames:
return localeNames[code] return localeNames[code]
else: else:
return "(unknown locale)" return "(unknown locale)"
...@@ -42,7 +42,7 @@ class LocaleData(object): ...@@ -42,7 +42,7 @@ class LocaleData(object):
self.funcList = {} self.funcList = {}
def addKeywordMap (self, funcName, localeName, engName): def addKeywordMap (self, funcName, localeName, engName):
if not self.funcList.has_key(funcName): if funcName not in self.funcList:
self.funcList[funcName] = [] self.funcList[funcName] = []
self.funcList[funcName].append([localeName, engName]) self.funcList[funcName].append([localeName, engName])
...@@ -136,7 +136,7 @@ class Parser(object): ...@@ -136,7 +136,7 @@ class Parser(object):
for item in buf: for item in buf:
sys.stdout.write(chr(item)) sys.stdout.write(chr(item))
if linefeed: if linefeed:
print '' print('')
def parse (self): def parse (self):
......
...@@ -211,7 +211,7 @@ class TestCase( unittest.TestCase): ...@@ -211,7 +211,7 @@ class TestCase( unittest.TestCase):
wasHere = 0 wasHere = 0
try: try:
raise ioExc( "huhuh" , self.tobj ) raise ioExc( "huhuh" , self.tobj )
except unoExc , instance: except unoExc as instance:
wasHere = 1 wasHere = 1
self.failUnless( wasHere , "exceptiont test 1" ) self.failUnless( wasHere , "exceptiont test 1" )
...@@ -239,7 +239,7 @@ class TestCase( unittest.TestCase): ...@@ -239,7 +239,7 @@ class TestCase( unittest.TestCase):
self.failUnless( 0 , "exception test 5a" ) self.failUnless( 0 , "exception test 5a" )
except ioExc: except ioExc:
self.failUnless( 0 , "exception test 5b" ) self.failUnless( 0 , "exception test 5b" )
except illegalArg, i: except illegalArg as i:
self.failUnless( 1 == i.ArgumentPosition , "exception member test" ) self.failUnless( 1 == i.ArgumentPosition , "exception member test" )
self.failUnless( "foo" == i.Message , "exception member test 2 " ) self.failUnless( "foo" == i.Message , "exception member test 2 " )
wasHere = 1 wasHere = 1
......
...@@ -31,7 +31,7 @@ class DlgLayoutBuilder(object): ...@@ -31,7 +31,7 @@ class DlgLayoutBuilder(object):
def addWidget (self, elem): def addWidget (self, elem):
x, y = int(elem.getAttr('x')), int(elem.getAttr('y')) x, y = int(elem.getAttr('x')), int(elem.getAttr('y'))
self.rows[y] = self.rows.get (y, {}) self.rows[y] = self.rows.get (y, {})
while self.rows[y].has_key(x): while x in self.rows[y]:
y += 1 y += 1
self.rows[y] = self.rows.get (y, {}) self.rows[y] = self.rows.get (y, {})
self.rows[y][x] = elem self.rows[y][x] = elem
......
...@@ -125,4 +125,4 @@ class ExpParser(object): ...@@ -125,4 +125,4 @@ class ExpParser(object):
def dumpTree (self): def dumpTree (self):
self.jumpToRoot() self.jumpToRoot()
print toString(self.ptr) print(toString(self.ptr))
...@@ -108,7 +108,7 @@ class Element(Node): ...@@ -108,7 +108,7 @@ class Element(Node):
return chars return chars
def hasAttr (self, name): def hasAttr (self, name):
return self.attrs.has_key(name) return name in self.attrs
def getAttr (self, name): def getAttr (self, name):
return self.attrs[name] return self.attrs[name]
...@@ -121,7 +121,7 @@ class Element(Node): ...@@ -121,7 +121,7 @@ class Element(Node):
return return
def clone (self, elem): def clone (self, elem):
keys = elem.attrs.keys() keys = list(elem.attrs.keys())
for key in keys: for key in keys:
self.attrs[key] = elem.attrs[key] self.attrs[key] = elem.attrs[key]
self.rid = elem.rid self.rid = elem.rid
......
...@@ -31,7 +31,7 @@ class TestCase: ...@@ -31,7 +31,7 @@ class TestCase:
mcExpander.debug = True mcExpander.debug = True
mcExpander.expand() mcExpander.expand()
tokens = mcExpander.getTokens() tokens = mcExpander.getTokens()
print tokens print(tokens)
@staticmethod @staticmethod
def simpleNoArgs (): def simpleNoArgs ():
...@@ -79,13 +79,13 @@ class TestCase: ...@@ -79,13 +79,13 @@ class TestCase:
TestCase.run(tokens, defines) TestCase.run(tokens, defines)
def main (): def main ():
print "simple expansion with no arguments" print("simple expansion with no arguments")
TestCase.simpleNoArgs() TestCase.simpleNoArgs()
print "simple argument expansion" print("simple argument expansion")
TestCase.simpleArgs() TestCase.simpleArgs()
print "multi-token argument expansion" print("multi-token argument expansion")
TestCase.multiTokenArgs() TestCase.multiTokenArgs()
print "nested argument expansion" print("nested argument expansion")
TestCase.nestedTokenArgs() TestCase.nestedTokenArgs()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -37,8 +37,8 @@ A macro with arguments must have its open paren immediately following ...@@ -37,8 +37,8 @@ A macro with arguments must have its open paren immediately following
its name without any whitespace. its name without any whitespace.
""" """
if self.debug: if self.debug:
print "-"*68 print("-"*68)
print "parsing '%s'"%self.buffer print("parsing '%s'"%self.buffer)
i = 0 i = 0
bufSize = len(self.buffer) bufSize = len(self.buffer)
...@@ -105,17 +105,17 @@ character is the open paren. ...@@ -105,17 +105,17 @@ character is the open paren.
def setMacro (self, name, vars, content): def setMacro (self, name, vars, content):
if self.debug: if self.debug:
print "-"*68 print("-"*68)
print "name: %s"%name print("name: %s"%name)
for var in vars: for var in vars:
print "var: %s"%var print("var: %s"%var)
if len(vars) == 0: if len(vars) == 0:
print "no vars" print("no vars")
print "content: '%s'"%content print("content: '%s'"%content)
if len(content) > 0: if len(content) > 0:
self.macro = Macro(name) self.macro = Macro(name)
for i in xrange(0, len(vars)): for i in range(0, len(vars)):
self.macro.vars[vars[i]] = i self.macro.vars[vars[i]] = i
# tokinize it using lexer. # tokinize it using lexer.
...@@ -125,16 +125,16 @@ character is the open paren. ...@@ -125,16 +125,16 @@ character is the open paren.
mclexer.tokenize() mclexer.tokenize()
self.macro.tokens = mclexer.getTokens() self.macro.tokens = mclexer.getTokens()
if self.debug: if self.debug:
print self.macro.tokens print(self.macro.tokens)
if not self.isValidMacro(self.macro): if not self.isValidMacro(self.macro):
self.macro = None self.macro = None
if self.debug: if self.debug:
if self.macro != None: if self.macro != None:
print "macro registered!" print("macro registered!")
else: else:
print "macro not registered" print("macro not registered")
def isValidMacro (self, macro): def isValidMacro (self, macro):
......
...@@ -182,12 +182,12 @@ def dry_one_file (file_name, options): ...@@ -182,12 +182,12 @@ def dry_one_file (file_name, options):
try: try:
str = convert(file_name, options) str = convert(file_name, options)
progress (" SUCCESS\n") progress (" SUCCESS\n")
except Exception, e: except Exception as e:
if options.keep_going: if options.keep_going:
progress (" FAILED\n") progress (" FAILED\n")
else: else:
import traceback import traceback
print traceback.format_exc (None) print(traceback.format_exc (None))
raise e raise e
def post_process (s): def post_process (s):
......
...@@ -303,14 +303,14 @@ build the syntax tree. ...@@ -303,14 +303,14 @@ build the syntax tree.
self.handleMacroInclude(buf) self.handleMacroInclude(buf)
elif command == 'ifdef': elif command == 'ifdef':
defineName = buf.strip() defineName = buf.strip()
if self.defines.has_key(defineName): if defineName in self.defines:
self.visibilityStack.append(SrcLexer.VISIBLE) self.visibilityStack.append(SrcLexer.VISIBLE)
else: else:
self.visibilityStack.append(SrcLexer.INVISIBLE_PRE) self.visibilityStack.append(SrcLexer.INVISIBLE_PRE)
elif command == 'ifndef': elif command == 'ifndef':
defineName = buf.strip() defineName = buf.strip()
if self.defines.has_key(defineName): if defineName in self.defines:
self.visibilityStack.append(SrcLexer.INVISIBLE_PRE) self.visibilityStack.append(SrcLexer.INVISIBLE_PRE)
else: else:
self.visibilityStack.append(SrcLexer.VISIBLE) self.visibilityStack.append(SrcLexer.VISIBLE)
...@@ -351,8 +351,8 @@ build the syntax tree. ...@@ -351,8 +351,8 @@ build the syntax tree.
elif command in ['error', 'pragma']: elif command in ['error', 'pragma']:
pass pass
else: else:
print "'%s' '%s'"%(command, buf) print("'%s' '%s'"%(command, buf))
print self.filepath print(self.filepath)
sys.exit(0) sys.exit(0)
return i return i
...@@ -407,10 +407,10 @@ build the syntax tree. ...@@ -407,10 +407,10 @@ build the syntax tree.
progress ("%s already included\n"%headerPath) progress ("%s already included\n"%headerPath)
return return
if SrcLexer.headerCache.has_key(headerPath): if headerPath in SrcLexer.headerCache:
if self.debug: if self.debug:
progress ("%s in cache\n"%headerPath) progress ("%s in cache\n"%headerPath)
for key in SrcLexer.headerCache[headerPath].defines.keys(): for key in list(SrcLexer.headerCache[headerPath].defines.keys()):
self.defines[key] = SrcLexer.headerCache[headerPath].defines[key] self.defines[key] = SrcLexer.headerCache[headerPath].defines[key]
return return
...@@ -422,7 +422,7 @@ build the syntax tree. ...@@ -422,7 +422,7 @@ build the syntax tree.
hdrData = HeaderData() hdrData = HeaderData()
hdrData.tokens = mclexer.getTokens() hdrData.tokens = mclexer.getTokens()
headerDefines = mclexer.getDefines() headerDefines = mclexer.getDefines()
for key in headerDefines.keys(): for key in list(headerDefines.keys()):
defines[key] = headerDefines[key] defines[key] = headerDefines[key]
hdrData.defines[key] = headerDefines[key] hdrData.defines[key] = headerDefines[key]
...@@ -430,15 +430,15 @@ build the syntax tree. ...@@ -430,15 +430,15 @@ build the syntax tree.
SrcLexer.headerCache[headerPath] = hdrData SrcLexer.headerCache[headerPath] = hdrData
# Update the list of headers that have already been expaneded. # Update the list of headers that have already been expaneded.
for key in mclexer.headerDict.keys(): for key in list(mclexer.headerDict.keys()):
self.headerDict[key] = True self.headerDict[key] = True
if self.debug: if self.debug:
progress ("defines found in header %s:\n"%headerSub) progress ("defines found in header %s:\n"%headerSub)
for key in defines.keys(): for key in list(defines.keys()):
progress (" '%s'\n"%key) progress (" '%s'\n"%key)
for key in defines.keys(): for key in list(defines.keys()):
self.defines[key] = defines[key] self.defines[key] = defines[key]
......
...@@ -108,12 +108,12 @@ class MacroExpander(object): ...@@ -108,12 +108,12 @@ class MacroExpander(object):
def expandToken (self): def expandToken (self):
token = self.tokens[self.pos] token = self.tokens[self.pos]
if not self.defines.has_key(token): if token not in self.defines:
self.pos += 1 self.pos += 1
return return
macro = self.defines[token] macro = self.defines[token]
nvars = len(macro.vars.keys()) nvars = len(list(macro.vars.keys()))
if nvars == 0: if nvars == 0:
# Simple expansion # Simple expansion
self.tokens[self.pos:self.pos+1] = macro.tokens self.tokens[self.pos:self.pos+1] = macro.tokens
...@@ -123,7 +123,7 @@ class MacroExpander(object): ...@@ -123,7 +123,7 @@ class MacroExpander(object):
values, lastPos = self.parseValues() values, lastPos = self.parseValues()
newtokens = [] newtokens = []
for mtoken in macro.tokens: for mtoken in macro.tokens:
if macro.vars.has_key(mtoken): if mtoken in macro.vars:
# variable # variable
pos = macro.vars[mtoken] pos = macro.vars[mtoken]
valtokens = values[pos] valtokens = values[pos]
...@@ -155,15 +155,15 @@ words, whitespace does not end a token. ...@@ -155,15 +155,15 @@ words, whitespace does not end a token.
tk = self.tokens[self.pos+i] tk = self.tokens[self.pos+i]
except IndexError: except IndexError:
progress ("error parsing values (%d)\n"%i) progress ("error parsing values (%d)\n"%i)
for j in xrange(0, i): for j in range(0, i):
print self.tokens[self.pos+j], print(self.tokens[self.pos+j], end=' ')
print '' print('')
srclexer.dumpTokens(self.tokens) srclexer.dumpTokens(self.tokens)
srclexer.dumpTokens(self.newtokens) srclexer.dumpTokens(self.newtokens)
print "tokens expanded so far:" print("tokens expanded so far:")
for tk in self.expandedTokens: for tk in self.expandedTokens:
print "-"*20 print("-"*20)
print tk print(tk)
srclexer.dumpTokens(self.defines[tk].tokens) srclexer.dumpTokens(self.defines[tk].tokens)
sys.exit(1) sys.exit(1)
if tk == '(': if tk == '(':
...@@ -207,7 +207,7 @@ class SrcParser(object): ...@@ -207,7 +207,7 @@ class SrcParser(object):
# Expand defined macros. # Expand defined macros.
if self.debug: if self.debug:
progress ("-"*68+"\n") progress ("-"*68+"\n")
for key in self.defines.keys(): for key in list(self.defines.keys()):
progress ("define: %s\n"%key) progress ("define: %s\n"%key)
self.expandMacro() self.expandMacro()
...@@ -314,7 +314,7 @@ handler. ...@@ -314,7 +314,7 @@ handler.
def closeBrace (self, i): def closeBrace (self, i):
if len(self.tokenBuf) > 0: if len(self.tokenBuf) > 0:
if self.debug: if self.debug:
print self.tokenBuf print(self.tokenBuf)
raise ParseError ('') raise ParseError ('')
self.elementStack.pop() self.elementStack.pop()
return i return i
......
...@@ -29,7 +29,7 @@ def grep(pattern,dirname,names): ...@@ -29,7 +29,7 @@ def grep(pattern,dirname,names):
lines = open(filename,"r").readlines() lines = open(filename,"r").readlines()
for line in lines: for line in lines:
if pattern.search(line): if pattern.search(line):
print filename print(filename)
break break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment