diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kformula/prototype/gensymbolfontmap.py | 48 | ||||
-rwxr-xr-x | lib/kformula/prototype/unicode.py | 18 | ||||
-rwxr-xr-x | lib/kformula/scripts/bycodes.py | 10 | ||||
-rwxr-xr-x | lib/kformula/scripts/bynames.py | 22 | ||||
-rwxr-xr-x | lib/kformula/scripts/oper-dict.py | 38 | ||||
-rw-r--r-- | lib/kross/python/scripts/RestrictedPython/Eval.py | 6 | ||||
-rw-r--r-- | lib/kross/python/scripts/RestrictedPython/Guards.py | 2 | ||||
-rw-r--r-- | lib/kross/python/scripts/RestrictedPython/Limits.py | 12 | ||||
-rw-r--r-- | lib/kross/python/scripts/RestrictedPython/MutatingWalker.py | 2 | ||||
-rw-r--r-- | lib/kross/python/scripts/RestrictedPython/RCompile.py | 4 | ||||
-rw-r--r-- | lib/kross/python/scripts/RestrictedPython/RestrictionMutator.py | 2 | ||||
-rwxr-xr-x | lib/kross/python/scripts/gui.py | 96 | ||||
-rw-r--r-- | lib/kross/test/testcase.py | 88 | ||||
-rw-r--r-- | lib/kross/test/testgui.py | 42 | ||||
-rw-r--r-- | lib/kross/test/testkexidb.py | 52 | ||||
-rwxr-xr-x | lib/kross/test/testperformance.py | 4 |
16 files changed, 223 insertions, 223 deletions
diff --git a/lib/kformula/prototype/gensymbolfontmap.py b/lib/kformula/prototype/gensymbolfontmap.py index df06eeed..1aec3d94 100644 --- a/lib/kformula/prototype/gensymbolfontmap.py +++ b/lib/kformula/prototype/gensymbolfontmap.py @@ -16,14 +16,14 @@ class ContentGenerator(handler.ContentHandler): def startElement(self, name, attrs): if name == 'unicodetable': self.font = None - for (name, value) in attrs.items(): + for (name, value) in list(attrs.items()): if name == "font" and value: self.font = value if value not in fonttable: fonttable[value] = [] elif self.font and name == 'entry': number = '' - for (name, value) in attrs.items(): + for (name, value) in list(attrs.items()): if name == "key": key = int(value) elif name == "number": number = value elif name == "name": latexName = value @@ -53,13 +53,13 @@ def writeFontTable(fontname, f): def write_header(f): - print >>f, '''// + print('''// // Created: ''' + time.ctime(time.time()) + ''' // by: gensymbolfontmap.py // from: symbol.xml // // WARNING! All changes made in this file will be lost! -''' +''', file=f) def main(): f = open('../symbolfontmapping.cpp', 'w') @@ -109,8 +109,8 @@ def main(): f = open('../unicodenames.cpp', 'w') write_header(f) - print >>f, 'struct UnicodeNameTable { short unicode; const char* name; };' - print >>f, 'static UnicodeNameTable nameTable[] = {' + print('struct UnicodeNameTable { short unicode; const char* name; };', file=f) + print('static UnicodeNameTable nameTable[] = {', file=f) nameDir = {} table = {} for style in unicodetable: @@ -121,9 +121,9 @@ def main(): if len(latexName) > 0: #for fn in fontnames: # if fontkey(fn, style, key): - print >>f, ' { ' + key + ', "' + latexName + '" },' + print(' { ' + key + ', "' + latexName + '" },', file=f) #break - print >>f, ' { 0, 0 }\n};' + print(' { 0, 0 }\n};', file=f) f.close() @@ -132,12 +132,12 @@ def make_unicode_table(): header = [] codes = {} f = open('../config/unicode.tbl', 'r') - for line in f.xreadlines(): + for line in f: if line[0] == '#': header.append(line.strip()) else: break - for line in f.xreadlines(): + for line in f: if len(line) > 0: codes[line.split(',')[0].strip()] = line f.close() @@ -151,9 +151,9 @@ def make_unicode_table(): f = open('../config/unicode.tbl', 'w') for line in header: - print >> f, line + print(line, file=f) for key in codes: - print >> f, codes[key] + print(codes[key], file=f) f.close() def make_font_table(font): @@ -178,7 +178,7 @@ def make_font_table(font): latexName, charClass = unicodetable[key] pos = fontkey(font, key) if pos: - print >> f, str(pos), key, charClass, latexName + print(str(pos), key, charClass, latexName, file=f) f.close() def make_all_font_tables(): @@ -186,30 +186,30 @@ def make_all_font_tables(): make_font_table(font) -def symbol_entry(pos, unicode, charClass, name): +def symbol_entry(pos, str, charClass, name): return ' <entry key="%d" number="%s" name="%s" class="%s"/>' % \ - (pos, unicode, name, charClass) + (pos, str, name, charClass) def compare_font(font): for line in file(font+".font"): list = line.split() pos = int(list[0]) - unicode = list[1] + str = list[1] charClass = list[2] if len(list)>3: name = list[3] else: name = "" - if (pos, unicode) not in fonttable[font]: - print "not in font", font, (pos, unicode) - print symbol_entry(pos, unicode, charClass, name) - if unicode not in unicodetable: - print font, unicode, (name, charClass) - print symbol_entry(pos, unicode, charClass, name) - elif unicodetable[unicode] != (name, charClass): - print font, unicode, pos, unicodetable[unicode], "!=", (name, charClass) + if (pos, str) not in fonttable[font]: + print("not in font", font, (pos, str)) + print(symbol_entry(pos, str, charClass, name)) + if str not in unicodetable: + print(font, str, (name, charClass)) + print(symbol_entry(pos, str, charClass, name)) + elif unicodetable[str] != (name, charClass): + print(font, str, pos, unicodetable[str], "!=", (name, charClass)) def compare(): fontnames = [ "symbol", diff --git a/lib/kformula/prototype/unicode.py b/lib/kformula/prototype/unicode.py index cee5ea6c..ca495d25 100755 --- a/lib/kformula/prototype/unicode.py +++ b/lib/kformula/prototype/unicode.py @@ -127,21 +127,21 @@ class Widget(TQWidget): self.fonts[self.child.fontName] = self.child.fontList() f = open("symbol.xml", "w") - print >> f, '<?xml version="1.0" encoding="iso-8859-1"?>' - print >> f, '<table>' + print('<?xml version="1.0" encoding="iso-8859-1"?>', file=f) + print('<table>', file=f) for font in self.fonts: - print >> f, ' <unicodetable font="' + font + '">' + print(' <unicodetable font="' + font + '">', file=f) for (key, number, latexName, charClass) in self.fonts[font]: if not charClass or charClass == '': charClass = 'ORDINARY' - print >> f, ' <entry key="' + str(key) + \ + print(' <entry key="' + str(key) + \ '" number="' + str(number) + \ '" name="' + str(latexName) + \ '" class="' + str(charClass) + \ - '"/>' + '"/>', file=f) - print >> f, ' </unicodetable>' - print >> f, '</table>' + print(' </unicodetable>', file=f) + print('</table>', file=f) f.close() @@ -153,14 +153,14 @@ class ContentGenerator(handler.ContentHandler): def startElement(self, name, attrs): if name == 'unicodetable': - for (name, value) in attrs.items(): + for (name, value) in list(attrs.items()): if name == "font": self.currentFont = value self.fonts[self.currentFont] = [] elif name == 'entry': if not self.currentFont: raise "entry must belong to a font" - for (name, value) in attrs.items(): + for (name, value) in list(attrs.items()): if name == "key": if len(value) > 1 and value[:2] == "0x": key = int(value[2:], 16) diff --git a/lib/kformula/scripts/bycodes.py b/lib/kformula/scripts/bycodes.py index 45b787a0..fdd84269 100755 --- a/lib/kformula/scripts/bycodes.py +++ b/lib/kformula/scripts/bycodes.py @@ -25,11 +25,11 @@ from TQt import qt def decode( fd, font, line ): begin = string.find( line, '"' ) end = string.find( line, '"', begin + 1) - unicode = line[begin + 2:end] # Remove 'U' from string aswell + str = line[begin + 2:end] # Remove 'U' from string aswell char_list = [] - separation = string.find( unicode, '-' ) + separation = string.find( str, '-' ) if separation != -1: - second = unicode + second = str while separation != -1: first = second[0:separation] second = second[separation + 2:] @@ -38,13 +38,13 @@ def decode( fd, font, line ): if separation == -1: char_list.append( string.atoi( second, 16 ) ) else: - char_list.append( string.atoi ( unicode, 16 ) ) + char_list.append( string.atoi ( str, 16 ) ) fm = qt.TQFontMetrics( qt.TQFont( font ) ) in_font = True for c in char_list: if not fm.inFont( qt.TQChar( c ) ): in_font = False - fd.write( unicode + ' ' + str( in_font ) + '\n') + fd.write( str + ' ' + str( in_font ) + '\n') def parse( file, font ): fd = open( file ) diff --git a/lib/kformula/scripts/bynames.py b/lib/kformula/scripts/bynames.py index 6b8c1d7a..fbd1ba5e 100755 --- a/lib/kformula/scripts/bynames.py +++ b/lib/kformula/scripts/bynames.py @@ -24,7 +24,7 @@ import time import os def write_header( f ): - print >> f, '''// + print('''// // Created: ''' + time.ctime(time.time()) + ''' // by: ''' + os.path.basename( sys.argv[0] ) + ''' // from: ''' + os.path.basename( sys.argv[1] ) + ''' @@ -49,10 +49,10 @@ def write_header( f ): the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -''' +''', file=f) def write_h( f ): - print >>f, ''' + print(''' #ifndef ENTITIES_H #define ENTITIES_H @@ -74,19 +74,19 @@ extern const entityMap entities[]; KFORMULA_NAMESPACE_END #endif // ENTITIES_H -''' +''', file=f) def write_cc( fr, fw ): - print >> fw, ''' + print(''' #include "entities.h" KFORMULA_NAMESPACE_BEGIN -const entityMap entities[] = {''' +const entityMap entities[] = {''', file=fw) parse( fr, fw ) - print >> fw, ''' + print(''' }; // Needed since sizeof is a macro and we cannot be used until size is known @@ -96,7 +96,7 @@ int entityMap::size() } KFORMULA_NAMESPACE_END - ''' + ''', file=fw) def name_cmp( a, b ): @@ -104,7 +104,7 @@ def name_cmp( a, b ): return -1 if a[0] > b[0]: return 1 - print 'WARNING: Same name in entity: ' + a[0] + ', ' + b[0] + print('WARNING: Same name in entity: ' + a[0] + ', ' + b[0]) return 0; def parse( fr, fw ): @@ -133,10 +133,10 @@ def parse( fr, fw ): while True: e = entries.pop() fd_list.write( e[0] + ' ' + e[1] + '\n') - print >> fw, ' {"' + e[0] + '", ' + e[1] + '}', + print(' {"' + e[0] + '", ' + e[1] + '}', end=' ', file=fw) if len( entries ) == 0: break - print >> fw, ',' + print(',', file=fw) fd_list.close() if __name__ == '__main__': diff --git a/lib/kformula/scripts/oper-dict.py b/lib/kformula/scripts/oper-dict.py index e9e10550..70f7868c 100755 --- a/lib/kformula/scripts/oper-dict.py +++ b/lib/kformula/scripts/oper-dict.py @@ -43,7 +43,7 @@ attr_list = [ def write_header( f ): - print >> f, '''// + print('''// // Created: ''' + time.ctime(time.time()) + ''' // by: ''' + os.path.basename( sys.argv[0] ) + ''' // from: ''' + os.path.basename( sys.argv[1] ) + ''' @@ -68,10 +68,10 @@ def write_header( f ): the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -''' +''', file=f) def write_h( f ): - print >>f, ''' + print(''' #ifndef OPERATORDICTIONARY_H #define OPERATORDICTIONARY_H @@ -119,20 +119,20 @@ extern const OperatorDictionary operators[]; KFORMULA_NAMESPACE_END #endif // OPERATORDICTIONARY_H -''' +''', file=f) def write_cc( fr, fw ): - print >> fw, ''' + print(''' #include "operatordictionary.h" KFORMULA_NAMESPACE_BEGIN -const OperatorDictionary operators[] = {''' +const OperatorDictionary operators[] = {''', file=fw) entities = get_entities() parse( fr, fw, entities ) - print >> fw, ''' + print(''' }; // Needed since sizeof is a macro and we cannot be used until size is known @@ -142,7 +142,7 @@ int OperatorDictionary::size() } KFORMULA_NAMESPACE_END - ''' + ''', file=fw) def get_entities(): # First, read entity list into a dict @@ -165,7 +165,7 @@ def key_cmp( a, b ): return -1 if a[1] > b[1]: return 1 - print 'WARNING: Same key in operator dictionary: ' + a[0] + ', ' + b[0] + print('WARNING: Same key in operator dictionary: ' + a[0] + ', ' + b[0]) return 0 def parse( fr, fw, entities ): @@ -203,8 +203,8 @@ def parse( fr, fw, entities ): # application. The best solution would probably to map to a single # character provided by the font in the private area of Unicode entity_name = name[begin + 1:end] - if entities.has_key( entity_name ) : - name = name.replace( '&' + entity_name + ';', unichr(entities[entity_name])); + if entity_name in entities : + name = name.replace( '&' + entity_name + ';', chr(entities[entity_name])); else: entities_found = False break @@ -213,9 +213,9 @@ def parse( fr, fw, entities ): fields.pop(0) # Remove form for f in fields: attr, value = string.split( f, '=' ) - if not attr_dict.has_key( attr ) : - print 'Unsupported attribute: ' + attr - print 'If it is valid, update attribute dictionary' + if attr not in attr_dict : + print('Unsupported attribute: ' + attr) + print('If it is valid, update attribute dictionary') sys.exit(-1) # Spec has a typo, fix it if string.count( value, '"' ) == 3: @@ -227,20 +227,20 @@ def parse( fr, fw, entities ): while True: e = entries.pop() - print >> fw, ' { {' + e[0] + ', ' + e[1] + '},' + print(' { {' + e[0] + ', ' + e[1] + '},', file=fw) d = e[2] for a in attr_list: # Convert, at least, bool values value = d[a] if value == '"true"' or value == '"false"': value = string.strip( value, '"' ) - print >> fw, '\t\t' + value, + print('\t\t' + value, end=' ', file=fw) if a != attr_list[len(attr_list) - 1]: - print >> fw, ',' - print >> fw, '}', + print(',', file=fw) + print('}', end=' ', file=fw) if len( entries ) == 0: break - print >> fw, ',\n' + print(',\n', file=fw) if __name__ == '__main__': fh = open( '../operatordictionary.h', 'w' ) diff --git a/lib/kross/python/scripts/RestrictedPython/Eval.py b/lib/kross/python/scripts/RestrictedPython/Eval.py index 841067a1..85802522 100644 --- a/lib/kross/python/scripts/RestrictedPython/Eval.py +++ b/lib/kross/python/scripts/RestrictedPython/Eval.py @@ -62,10 +62,10 @@ class RestrictionCapableEval: self.expr, '<string>') if PROFILE: end = clock() - print 'prepRestrictedCode: %d ms for %s' % ( - (end - start) * 1000, `self.expr`) + print('prepRestrictedCode: %d ms for %s' % ( + (end - start) * 1000, repr(self.expr))) if err: - raise SyntaxError, err[0] + raise SyntaxError(err[0]) self.used = tuple(used.keys()) self.rcode = co diff --git a/lib/kross/python/scripts/RestrictedPython/Guards.py b/lib/kross/python/scripts/RestrictedPython/Guards.py index 4fbdcad1..2338518f 100644 --- a/lib/kross/python/scripts/RestrictedPython/Guards.py +++ b/lib/kross/python/scripts/RestrictedPython/Guards.py @@ -93,7 +93,7 @@ def _write_wrapper(): try: f = getattr(self.ob, secattr) except AttributeError: - raise TypeError, error_msg + raise TypeError(error_msg) f(*args) return handler class Wrapper: diff --git a/lib/kross/python/scripts/RestrictedPython/Limits.py b/lib/kross/python/scripts/RestrictedPython/Limits.py index 3b782e65..4e4511f1 100644 --- a/lib/kross/python/scripts/RestrictedPython/Limits.py +++ b/lib/kross/python/scripts/RestrictedPython/Limits.py @@ -25,22 +25,22 @@ def limited_range(iFirst, *args): elif len(args) == 2: iStart, iEnd, iStep = iFirst, args[0], args[1] else: - raise AttributeError, 'range() requires 1-3 int arguments' - if iStep == 0: raise ValueError, 'zero step for range()' + raise AttributeError('range() requires 1-3 int arguments') + if iStep == 0: raise ValueError('zero step for range()') iLen = int((iEnd - iStart) / iStep) if iLen < 0: iLen = 0 - if iLen >= RANGELIMIT: raise ValueError, 'range() too large' - return range(iStart, iEnd, iStep) + if iLen >= RANGELIMIT: raise ValueError('range() too large') + return list(range(iStart, iEnd, iStep)) limited_builtins['range'] = limited_range def limited_list(seq): if isinstance(seq, str): - raise TypeError, 'cannot convert string to list' + raise TypeError('cannot convert string to list') return list(seq) limited_builtins['list'] = limited_list def limited_tuple(seq): if isinstance(seq, str): - raise TypeError, 'cannot convert string to tuple' + raise TypeError('cannot convert string to tuple') return tuple(seq) limited_builtins['tuple'] = limited_tuple diff --git a/lib/kross/python/scripts/RestrictedPython/MutatingWalker.py b/lib/kross/python/scripts/RestrictedPython/MutatingWalker.py index b0b8c9ce..7cde295d 100644 --- a/lib/kross/python/scripts/RestrictedPython/MutatingWalker.py +++ b/lib/kross/python/scripts/RestrictedPython/MutatingWalker.py @@ -26,7 +26,7 @@ class MutatingWalker: self._cache = {} def defaultVisitNode(self, node, walker=None, exclude=None): - for name, child in node.__dict__.items(): + for name, child in list(node.__dict__.items()): if exclude is not None and name in exclude: continue v = self.dispatchObject(child) diff --git a/lib/kross/python/scripts/RestrictedPython/RCompile.py b/lib/kross/python/scripts/RestrictedPython/RCompile.py index 0a538657..dc5f8d4e 100644 --- a/lib/kross/python/scripts/RestrictedPython/RCompile.py +++ b/lib/kross/python/scripts/RestrictedPython/RCompile.py @@ -52,7 +52,7 @@ class RestrictedCompileMode(AbstractCompileMode): tree = self.parse() MutatingWalker.walk(tree, self.rm) if self.rm.errors: - raise SyntaxError, self.rm.errors[0] + raise SyntaxError(self.rm.errors[0]) misc.set_filename(self.filename, tree) syntax.check(tree) return tree @@ -66,7 +66,7 @@ class RestrictedCompileMode(AbstractCompileMode): def compileAndTuplize(gen): try: gen.compile() - except SyntaxError, v: + except SyntaxError as v: return None, (str(v),), gen.rm.warnings, gen.rm.used_names return gen.getCode(), (), gen.rm.warnings, gen.rm.used_names diff --git a/lib/kross/python/scripts/RestrictedPython/RestrictionMutator.py b/lib/kross/python/scripts/RestrictedPython/RestrictionMutator.py index a8b3850e..d5f4bac0 100644 --- a/lib/kross/python/scripts/RestrictedPython/RestrictionMutator.py +++ b/lib/kross/python/scripts/RestrictedPython/RestrictionMutator.py @@ -26,7 +26,7 @@ from SelectCompiler import ast, parse, OP_ASSIGN, OP_DELETE, OP_APPLY # trees without affecting line numbers shown in tracebacks, etc. def rmLineno(node): """Strip lineno attributes from a code tree.""" - if node.__dict__.has_key('lineno'): + if 'lineno' in node.__dict__: del node.lineno for child in node.getChildren(): if isinstance(child, ast.Node): diff --git a/lib/kross/python/scripts/gui.py b/lib/kross/python/scripts/gui.py index 487a5862..693261dd 100755 --- a/lib/kross/python/scripts/gui.py +++ b/lib/kross/python/scripts/gui.py @@ -34,8 +34,8 @@ class TkDialog: """ This class is used to wrap Tkinter into a more abstract interface.""" def __init__(self, title): - import Tkinter - self.root = Tkinter.Tk() + import tkinter + self.root = tkinter.Tk() self.root.title(title) self.root.deiconify() @@ -52,42 +52,42 @@ class TkDialog: class Frame(Widget): def __init__(self, dialog, parent): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Frame(parent) + import tkinter + self.widget = tkinter.Frame(parent) self.widget.pack() class Label(Widget): def __init__(self, dialog, parent, caption): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Label(parent, text=caption) - self.widget.pack(side=Tkinter.TOP) + import tkinter + self.widget = tkinter.Label(parent, text=caption) + self.widget.pack(side=tkinter.TOP) class CheckBox(Widget): def __init__(self, dialog, parent, caption, checked = True): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.checkstate = Tkinter.IntVar() + import tkinter + self.checkstate = tkinter.IntVar() self.checkstate.set(checked) - self.widget = Tkinter.Checkbutton(parent, text=caption, variable=self.checkstate) - self.widget.pack(side=Tkinter.TOP) + self.widget = tkinter.Checkbutton(parent, text=caption, variable=self.checkstate) + self.widget.pack(side=tkinter.TOP) def isChecked(self): return self.checkstate.get() class List(Widget): def __init__(self, dialog, parent, caption, items): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter + import tkinter - listframe = Tkinter.Frame(parent) + listframe = tkinter.Frame(parent) listframe.pack() - Tkinter.Label(listframe, text=caption).pack(side=Tkinter.LEFT) + tkinter.Label(listframe, text=caption).pack(side=tkinter.LEFT) self.items = items - self.variable = Tkinter.StringVar() - itemlist = apply(Tkinter.OptionMenu, (listframe, self.variable) + tuple( items )) - itemlist.pack(side=Tkinter.LEFT) + self.variable = tkinter.StringVar() + itemlist = tkinter.OptionMenu(*(listframe, self.variable) + tuple( items )) + itemlist.pack(side=tkinter.LEFT) def get(self): return self.variable.get() def set(self, index): @@ -96,48 +96,48 @@ class TkDialog: class Button(Widget): def __init__(self, dialog, parent, caption, commandmethod): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Button(parent, text=caption, command=self.doCommand) + import tkinter + self.widget = tkinter.Button(parent, text=caption, command=self.doCommand) self.commandmethod = commandmethod - self.widget.pack(side=Tkinter.LEFT) + self.widget.pack(side=tkinter.LEFT) def doCommand(self): try: self.commandmethod() except: #TODO why the heck we arn't able to redirect exceptions? import traceback - import StringIO - fp = StringIO.StringIO() + import io + fp = io.StringIO() traceback.print_exc(file=fp) - import tkMessageBox - tkMessageBox.showerror("Exception", fp.getvalue()) + import tkinter.messagebox + tkinter.messagebox.showerror("Exception", fp.getvalue()) #self.dialog.root.destroy() class Edit(Widget): def __init__(self, dialog, parent, caption, text): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Frame(parent) + import tkinter + self.widget = tkinter.Frame(parent) self.widget.pack() - label = Tkinter.Label(self.widget, text=caption) - label.pack(side=Tkinter.LEFT) - self.entrytext = Tkinter.StringVar() + label = tkinter.Label(self.widget, text=caption) + label.pack(side=tkinter.LEFT) + self.entrytext = tkinter.StringVar() self.entrytext.set(text) - self.entry = Tkinter.Entry(self.widget, width=36, textvariable=self.entrytext) - self.entry.pack(side=Tkinter.LEFT) + self.entry = tkinter.Entry(self.widget, width=36, textvariable=self.entrytext) + self.entry.pack(side=tkinter.LEFT) def get(self): return self.entrytext.get() class FileChooser(Edit): def __init__(self, dialog, parent, caption, initialfile = None, filetypes = None): TkDialog.Edit.__init__(self, dialog, parent, caption, initialfile) - import Tkinter + import tkinter self.initialfile = initialfile self.entrytext.set(initialfile) - btn = Tkinter.Button(self.widget, text="...", command=self.browse) - btn.pack(side=Tkinter.LEFT) + btn = tkinter.Button(self.widget, text="...", command=self.browse) + btn.pack(side=tkinter.LEFT) if filetypes: self.filetypes = filetypes @@ -150,8 +150,8 @@ class TkDialog: d = os.path.dirname(text) or os.path.dirname(self.initialfile) f = os.path.basename(text) or os.path.basename(self.initialfile) - import tkFileDialog - file = tkFileDialog.asksaveasfilename( + import tkinter.filedialog + file = tkinter.filedialog.asksaveasfilename( initialdir=d, initialfile=f, #defaultextension='.html', @@ -167,11 +167,11 @@ class TkDialog: self.caption = str(caption) self.message = str(message) def show(self): - import tkMessageBox + import tkinter.messagebox if self.typename == "okcancel": - return tkMessageBox.askokcancel(self.caption, self.message,icon=tkmessageBox.QESTION) + return tkinter.messagebox.askokcancel(self.caption, self.message,icon=tkmessageBox.QESTION) else: - tkMessageBox.showinfo(self.caption, self.message) + tkinter.messagebox.showinfo(self.caption, self.message) return True def show(self): @@ -276,7 +276,7 @@ class TQtDialog: def browseButtonClicked(self): filtermask = "" import types - if isinstance(self.filetypes, types.TupleType): + if isinstance(self.filetypes, tuple): for ft in self.filetypes: if len(ft) == 1: filtermask += "%s\n" % (ft[0]) @@ -289,12 +289,12 @@ class TQtDialog: filename = None try: - print "TQtDialog.FileChooser.browseButtonClicked() tdefile.KFileDialog" + print("TQtDialog.FileChooser.browseButtonClicked() tdefile.KFileDialog") # try to use the tdefile module included in pytde import tdefile filename = tdefile.KFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") except: - print "TQtDialog.FileChooser.browseButtonClicked() qt.TQFileDialog" + print("TQtDialog.FileChooser.browseButtonClicked() qt.TQFileDialog") # fallback to TQt filedialog filename = qt.TQFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") if filename != None and filename != "": @@ -341,7 +341,7 @@ class TQtDialog: qt.TQApplication.restoreOverrideCursor() def close(self): - print "TQtDialog.close()" + print("TQtDialog.close()") self.dialog.close() #self.dialog.deleteLater() @@ -352,16 +352,16 @@ class Dialog: self.dialog = None try: - print "Trying to import PyTQt..." + print("Trying to import PyTQt...") self.dialog = TQtDialog(title) - print "PyTQt is our toolkit!" + print("PyTQt is our toolkit!") except: try: - print "Failed to import PyTQt. Trying to import TkInter..." + print("Failed to import PyTQt. Trying to import TkInter...") self.dialog = TkDialog(title) - print "Falling back to TkInter as our toolkit!" + print("Falling back to TkInter as our toolkit!") except: - raise "Failed to import GUI-toolkit. Please install the PyTQt or the Tkinter python module." + raise Exception("Failed to import GUI-toolkit. Please install the PyTQt or the Tkinter python module.") self.widget = self.dialog.widget def show(self): diff --git a/lib/kross/test/testcase.py b/lib/kross/test/testcase.py index 28917f87..6db6d980 100644 --- a/lib/kross/test/testcase.py +++ b/lib/kross/test/testcase.py @@ -59,84 +59,84 @@ class TestPlugin(unittest.TestCase): def setUp(self): import krosstestpluginmodule self.pluginobject1 = krosstestpluginmodule.testpluginobject1() - self.assert_( self.pluginobject1 ) + self.assertTrue( self.pluginobject1 ) self.pluginobject2 = krosstestpluginmodule.testpluginobject2() - self.assert_( self.pluginobject2 ) + self.assertTrue( self.pluginobject2 ) self.testqobject1 = krosstestpluginmodule.testqobject1() - self.assert_( self.testqobject1 ) + self.assertTrue( self.testqobject1 ) def testBasicDataTypes(self): - self.assert_( self.pluginobject1.uintfunc(177321) == 177321 ) - self.assert_( self.pluginobject1.intfunc(93675) == 93675 ) - self.assert_( self.pluginobject1.intfunc(-73673) == -73673 ) - self.assert_( self.pluginobject1.boolfunc(True) == True ) - self.assert_( self.pluginobject1.boolfunc(False) == False ) - self.assert_( self.pluginobject1.doublefunc(4265.3723) == 4265.3723 ) - self.assert_( self.pluginobject1.doublefunc(-4265.68) == -4265.68 ) - self.assert_( self.pluginobject1.cstringfunc(" This is a Test! ") == " This is a Test! " ) - self.assert_( self.pluginobject1.stringfunc(" Another \n\r Test! $%&\"") == " Another \n\r Test! $%&\"" ) + self.assertTrue( self.pluginobject1.uintfunc(177321) == 177321 ) + self.assertTrue( self.pluginobject1.intfunc(93675) == 93675 ) + self.assertTrue( self.pluginobject1.intfunc(-73673) == -73673 ) + self.assertTrue( self.pluginobject1.boolfunc(True) == True ) + self.assertTrue( self.pluginobject1.boolfunc(False) == False ) + self.assertTrue( self.pluginobject1.doublefunc(4265.3723) == 4265.3723 ) + self.assertTrue( self.pluginobject1.doublefunc(-4265.68) == -4265.68 ) + self.assertTrue( self.pluginobject1.cstringfunc(" This is a Test! ") == " This is a Test! " ) + self.assertTrue( self.pluginobject1.stringfunc(" Another \n\r Test! $%&\"") == " Another \n\r Test! $%&\"" ) #TODO #self.assert_( self.pluginobject1.stringfunc( unicode(" Unicode test ") ) == " Unicode test " ) #self.assert_( self.pluginobject1.stringfunc(unicode(" Another Test! ")) == unicode(" Another Test! ") ) - self.assert_( self.pluginobject1.stringstringfunc("MyString1", "MyString2") == "MyString1" ) - self.assert_( self.pluginobject1.uintdoublestringfunc(8529,285.246,"String") == 8529 ) - self.assert_( self.pluginobject1.stringlistbooluintdouble(["s1","s2"],True,6,7.0,"String") == ["s1","s2"] ) + self.assertTrue( self.pluginobject1.stringstringfunc("MyString1", "MyString2") == "MyString1" ) + self.assertTrue( self.pluginobject1.uintdoublestringfunc(8529,285.246,"String") == 8529 ) + self.assertTrue( self.pluginobject1.stringlistbooluintdouble(["s1","s2"],True,6,7.0,"String") == ["s1","s2"] ) def testStringList(self): - self.assert_( self.pluginobject1.stringlistfunc( [] ) == [] ) - self.assert_( self.pluginobject1.stringlistfunc( ["First Item"," Second Item "] ) == ["First Item"," Second Item "] ) - self.assert_( self.pluginobject1.stringlistfunc( ("Theird Item"," Forth Item ","Fifth Item") ) == ["Theird Item"," Forth Item ","Fifth Item"] ) + self.assertTrue( self.pluginobject1.stringlistfunc( [] ) == [] ) + self.assertTrue( self.pluginobject1.stringlistfunc( ["First Item"," Second Item "] ) == ["First Item"," Second Item "] ) + self.assertTrue( self.pluginobject1.stringlistfunc( ("Theird Item"," Forth Item ","Fifth Item") ) == ["Theird Item"," Forth Item ","Fifth Item"] ) def testVariant(self): - self.assert_( self.pluginobject1.variantfunc(True) == True ) - self.assert_( self.pluginobject1.variantfunc(False) == False ) - self.assert_( self.pluginobject1.variantfunc(187937) == 187937 ) - self.assert_( self.pluginobject1.variantfunc(-69825) == -69825 ) - self.assert_( self.pluginobject1.variantfunc(8632.274) == 8632.274 ) - self.assert_( self.pluginobject1.variantfunc(-8632.351) == -8632.351 ) - self.assert_( self.pluginobject1.variantfunc(" Test \n\r This String $%&\"") == " Test \n\r This String $%&\"") + self.assertTrue( self.pluginobject1.variantfunc(True) == True ) + self.assertTrue( self.pluginobject1.variantfunc(False) == False ) + self.assertTrue( self.pluginobject1.variantfunc(187937) == 187937 ) + self.assertTrue( self.pluginobject1.variantfunc(-69825) == -69825 ) + self.assertTrue( self.pluginobject1.variantfunc(8632.274) == 8632.274 ) + self.assertTrue( self.pluginobject1.variantfunc(-8632.351) == -8632.351 ) + self.assertTrue( self.pluginobject1.variantfunc(" Test \n\r This String $%&\"") == " Test \n\r This String $%&\"") def testObjects(self): - print "-----------------1" + print("-----------------1") newobjref = self.pluginobject1.objectfunc(self.pluginobject2) - print "-----------------2" - print str(newobjref) + print("-----------------2") + print(str(newobjref)) #self.assert_( newobjref.myuniqueid == self.pluginobject2.myuniqueid ) #print "===========> %s" % self.pluginobject2.myName() - print "testqobject1 properties=%s" % self.testqobject1.propertyNames() - print "testqobject1 Q_SLOTS=%s" % self.testqobject1.slotNames() - print "testqobject1 Q_SIGNALS=%s" % self.testqobject1.signalNames() - print "-----------------3" - print "DIR=>%s" % dir(self.testqobject1) + print("testqobject1 properties=%s" % self.testqobject1.propertyNames()) + print("testqobject1 Q_SLOTS=%s" % self.testqobject1.slotNames()) + print("testqobject1 Q_SIGNALS=%s" % self.testqobject1.signalNames()) + print("-----------------3") + print("DIR=>%s" % dir(self.testqobject1)) - print "===================> slotcall-result: %s" % self.testqobject1.slot("self()") + print("===================> slotcall-result: %s" % self.testqobject1.slot("self()")) #testobject = newobjref.get("TestObject") #print testobject - print "-----------------9" + print("-----------------9") def testDefaultArguments(self): - self.assert_( self.pluginobject1.uintfunc_defarg(98765) == 98765 ) - self.assert_( self.pluginobject1.uintfunc_defarg() == 12345 ) - self.assert_( self.pluginobject1.stringfunc_defarg("MyString") == "MyString" ) - self.assert_( self.pluginobject1.stringfunc_defarg() == "MyDefaultString" ) - self.assert_( self.pluginobject1.stringlistfunc_defarg(["s1","s2","s3"]) == ["s1","s2","s3"] ) - self.assert_( self.pluginobject1.stringlistfunc_defarg() == ["Default1","Default2"] ) - self.assert_( self.pluginobject1.variantfunc_defarg(822.75173) == 822.75173 ) - self.assert_( self.pluginobject1.variantfunc_defarg() == "MyDefaultVariantString" ) + self.assertTrue( self.pluginobject1.uintfunc_defarg(98765) == 98765 ) + self.assertTrue( self.pluginobject1.uintfunc_defarg() == 12345 ) + self.assertTrue( self.pluginobject1.stringfunc_defarg("MyString") == "MyString" ) + self.assertTrue( self.pluginobject1.stringfunc_defarg() == "MyDefaultString" ) + self.assertTrue( self.pluginobject1.stringlistfunc_defarg(["s1","s2","s3"]) == ["s1","s2","s3"] ) + self.assertTrue( self.pluginobject1.stringlistfunc_defarg() == ["Default1","Default2"] ) + self.assertTrue( self.pluginobject1.variantfunc_defarg(822.75173) == 822.75173 ) + self.assertTrue( self.pluginobject1.variantfunc_defarg() == "MyDefaultVariantString" ) #def testExpectedFailures(self): # to less arguments #self.assertRaises(ValueError, self.pluginobject1.uintfunc) #self.assert_( self.pluginobject1.uintfunc() != 8465 ) -print "__name__ = %s" % __name__ +print("__name__ = %s" % __name__) #print "self = %s" % self #print self.get("TestObject") diff --git a/lib/kross/test/testgui.py b/lib/kross/test/testgui.py index b5efb8dc..0a3cf822 100644 --- a/lib/kross/test/testgui.py +++ b/lib/kross/test/testgui.py @@ -8,32 +8,32 @@ class TkTest: def __init__(self): - import Tkinter - self.root = Tkinter.Tk() + import tkinter + self.root = tkinter.Tk() self.root.title("TkTest") self.root.deiconify() - self.mainframe = Tkinter.Frame(self.root) + self.mainframe = tkinter.Frame(self.root) self.mainframe.pack() - self.button1 = Tkinter.Button(self.mainframe, text="Button1", command=self.callback1) - self.button1.pack(side=Tkinter.LEFT) + self.button1 = tkinter.Button(self.mainframe, text="Button1", command=self.callback1) + self.button1.pack(side=tkinter.LEFT) - self.button2 = Tkinter.Button(self.mainframe, text="Button2", command=self.callback2) - self.button2.pack(side=Tkinter.LEFT) + self.button2 = tkinter.Button(self.mainframe, text="Button2", command=self.callback2) + self.button2.pack(side=tkinter.LEFT) - self.exitbutton = Tkinter.Button(self.mainframe, text="Exit", command=self.root.destroy) - self.exitbutton.pack(side=Tkinter.LEFT) + self.exitbutton = tkinter.Button(self.mainframe, text="Exit", command=self.root.destroy) + self.exitbutton.pack(side=tkinter.LEFT) self.root.mainloop() def callback1(self): - import tkMessageBox - tkMessageBox.showinfo("Callback1", "Callback1 called.") + import tkinter.messagebox + tkinter.messagebox.showinfo("Callback1", "Callback1 called.") def callback2(self): - import tkMessageBox - tkMessageBox.showinfo("Callback2", "Callback2 called.") + import tkinter.messagebox + tkinter.messagebox.showinfo("Callback2", "Callback2 called.") class TQtTest: def __init__(self): @@ -41,7 +41,7 @@ class TQtTest: class Button(qt.TQPushButton): def __init__(self, *args): - apply(qt.TQPushButton.__init__, (self,) + args) + qt.TQPushButton.__init__(*(self,) + args) class ComboBox(qt.TQHBox): def __init__(self, parent, caption, items = []): @@ -56,7 +56,7 @@ class TQtTest: class FileChooser(qt.TQHBox): def __init__(self, *args): - apply(qt.TQHBox.__init__, (self,) + args) + qt.TQHBox.__init__(*(self,) + args) self.defaultfilename = "~/output.html" self.setSpacing(6) @@ -119,7 +119,7 @@ class TQtTest: qt.TQObject.connect(cancelbutton, qt.SIGNAL("clicked()"), self, qt.SLOT("close()")) def accept(self): - print "ACCEPTTTTTTTT !!!!!!!!!!!!!!!!!!!!!!!!!!!!" + print("ACCEPTTTTTTTT !!!!!!!!!!!!!!!!!!!!!!!!!!!!") file = qt.TQFile( self.filechooser.file() ) #if not file.exists(): @@ -128,13 +128,13 @@ class TQtTest: # print "File '%s' does exist." % self.filechooser.file() def exportButtonClicked(self): - print "Export to HTML !!!!!!!!!!!!!!!!!!!!!!!!!!!!" + print("Export to HTML !!!!!!!!!!!!!!!!!!!!!!!!!!!!") def __getattr__(self, attr): - print "=> Dialog.__getattr__(self,attr)" + print("=> Dialog.__getattr__(self,attr)") #def closeEvent(self, ev): pass def event(self, e): - print "=> Dialog.event %s" % e + print("=> Dialog.event %s" % e) #self.deleteLater() #support.swapThreadState() # calls appropriate c-function return qt.TQDialog.event(self, e) @@ -143,7 +143,7 @@ class TQtTest: dialog = Dialog(app.mainWidget(), "Dialog", 1) dialog.show() -print "################## BEGIN" +print("################## BEGIN") #TkTest() TQtTest() -print "################## END" +print("################## END") diff --git a/lib/kross/test/testkexidb.py b/lib/kross/test/testkexidb.py index 803d6548..c85f9806 100644 --- a/lib/kross/test/testkexidb.py +++ b/lib/kross/test/testkexidb.py @@ -15,36 +15,36 @@ class KexiDBClass: #import KexiDB import krosskexidb self.kexidbmodule = krosskexidb - print "KrossKexiDB version=%s" % self.kexidbmodule.version() + print("KrossKexiDB version=%s" % self.kexidbmodule.version()) # Create and remember the drivermanager. self.drivermanager = self.kexidbmodule.DriverManager() # Print informations about the KexiDB module. def printKexiDB(self): - print "KexiDB = %s %s" % (str(self.kexidbmodule),dir(self.kexidbmodule)) + print("KexiDB = %s %s" % (str(self.kexidbmodule),dir(self.kexidbmodule))) # Each object has __name__ and __doc__ #print "KexiDB.__name__ = %s" % self.kexidbmodule.__name__ #print "KexiDB.__doc__ = %s" % self.kexidbmodule.__doc__ # Print some infos about the drivermanager. - print "drivermanager = %s %s" % (self.drivermanager,dir(self.drivermanager)) + print("drivermanager = %s %s" % (self.drivermanager,dir(self.drivermanager))) # The drivermanager holds a list of drivers he supports. - print "drivermanager.driverNames() = %s" % self.driverNames() + print("drivermanager.driverNames() = %s" % self.driverNames()) # Print informations about a driver. def printDriverManger(self, driver): - print "driver = %s %s" % (driver,dir(driver)) + print("driver = %s %s" % (driver,dir(driver))) # Each driver has a version to be able to determinate with what release we are working. - print "driver.versionMajor() = %s" % driver.versionMajor() - print "driver.versionMinor() = %s" % driver.versionMinor() + print("driver.versionMajor() = %s" % driver.versionMajor()) + print("driver.versionMinor() = %s" % driver.versionMinor()) # Show us what connections are opened right now. - print "driver.connectionsList() = %s" % str(driver.connectionsList()) + print("driver.connectionsList() = %s" % str(driver.connectionsList())) # Print informations about a connection. def printConnection(self, connection): - print "connection = %s %s" % (str(connection),dir(connection)) + print("connection = %s %s" % (str(connection),dir(connection))) # Print a list of all avaible databasenames this connection has. - print "connection.databaseNames() = %s" % connection.databaseNames() + print("connection.databaseNames() = %s" % connection.databaseNames()) # Return a list of drivernames. def driverNames(self): @@ -65,7 +65,7 @@ class KexiDBClass: # Fill the new connectiondata object with what we need to connect. connectiondata.setCaption("myFileConnection") connectiondata.setFileName(filename) - print "connectiondata.serverInfoString = %s" % connectiondata.serverInfoString() + print("connectiondata.serverInfoString = %s" % connectiondata.serverInfoString()) # Create the connection now. connection = driver.createConnection(connectiondata) # Establish the connection. @@ -98,23 +98,23 @@ class KexiDBClass: def testParser(self, connection, sqlstatement): parser = connection.parser() if not parser: - raise "ERROR in testParser(): Failed to create parser!" - print "parser.parse = %s" % parser.parse(sqlstatement) - print "parser.statement = %s" % parser.statement() - print "parser.operation = %s" % parser.operation() - print "parser.table = %s" % parser.table() - print "parser.query = %s" % parser.query() - print "parser.connection = %s" % parser.connection() + raise("ERROR in testParser(): Failed to create parser!") + print("parser.parse = %s" % parser.parse(sqlstatement)) + print("parser.statement = %s" % parser.statement()) + print("parser.operation = %s" % parser.operation()) + print("parser.table = %s" % parser.table()) + print("parser.query = %s" % parser.query()) + print("parser.connection = %s" % parser.connection()) # Execute the sql query statement and print the single string result. def printQuerySingleString(self, connection, sqlstatement): query = myfileconnection.querySingleString("SELECT * FROM table1", 0) - print "querySingleString = %s" % query + print("querySingleString = %s" % query) # Execute the sql query statement and print the single stringlist result. def printQueryStringList(self, connection, sqlstatement): query = myfileconnection.queryStringList("SELECT * FROM table1", 0) - print "queryStringList = %s" % query + print("queryStringList = %s" % query) # Walk through the KexiDBCursor and print all item values. def printQueryCursor(self, cursor): @@ -130,7 +130,7 @@ class KexiDBClass: while(not cursor.eof()): # Print for each item some infos about the fields and there content. for i in range( cursor.fieldCount() ): - print "Item='%s' Field='%s' Value='%s'" % (cursor.at(), i, cursor.value(i)) + print("Item='%s' Field='%s' Value='%s'" % (cursor.at(), i, cursor.value(i))) # Move to the next item cursor.moveNext() @@ -148,7 +148,7 @@ class KexiDBClass: field.setType("Text") field.setName(name) tableschema.fieldlist().addField(field) - print "tableschema.fieldlist().fieldCount() = %s" % tableschema.fieldlist().fieldCount() + print("tableschema.fieldlist().fieldCount() = %s" % tableschema.fieldlist().fieldCount()) return field # Create a table. @@ -156,7 +156,7 @@ class KexiDBClass: # First we need a new tableschema. tableschema = self.drivermanager.tableSchema(tablename) self.addField(tableschema, "myfield") - print "connection.createTable = %s" % connection.createTable(tableschema, True) + print("connection.createTable = %s" % connection.createTable(tableschema, True)) return tableschema # Drop a table. @@ -166,7 +166,7 @@ class KexiDBClass: # Alter the name of a table. def alterTableName(self, connection, tablename, newtablename): tableschema = connection.tableSchema(tablename) - print "alterTableName from=%s to=%s tableschema=%s" % (tablename, newtablename, tableschema) + print("alterTableName from=%s to=%s tableschema=%s" % (tablename, newtablename, tableschema)) connection.alterTableName(tableschema, newtablename) def testKexiDB(): @@ -209,6 +209,6 @@ def testKexiDB(): #del(mydriver) #del(mykexidbclass) -print "########## BEGIN TEST: KexiDB ##########" +print("########## BEGIN TEST: KexiDB ##########") testKexiDB() -print "########## END TEST: KexiDB ##########" +print("########## END TEST: KexiDB ##########") diff --git a/lib/kross/test/testperformance.py b/lib/kross/test/testperformance.py index a76453ed..bd9c6d2c 100755 --- a/lib/kross/test/testperformance.py +++ b/lib/kross/test/testperformance.py @@ -10,7 +10,7 @@ def runner(): testobject1 = krosstestpluginmodule.testpluginobject1() def testKexiDB(kexidbfile,drivername,sqlstring): - print "test kexidb" + print("test kexidb") import krosskexidb drivermanager = krosskexidb.DriverManager() connectiondata = drivermanager.createConnectionData() @@ -29,7 +29,7 @@ def runner(): cursor.moveNext() def test1(): - print "test1" + print("test1") for i in range(100000): testobject1.func1() testobject1.func1() |