diff options
Diffstat (limited to 'lib/kross/python')
7 files changed, 62 insertions, 62 deletions
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): |