Skip to content

Trying to adapt the code to Python3+ #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nodebox/ext/psyco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Try to import the dynamic-loading _psyco and report errors
try:
import _psyco
except ImportError, e:
except ImportError as e:
extramsg = ''
import sys, imp
try:
Expand All @@ -43,7 +43,7 @@
extramsg = (" (check that the compiled extension '%s' is for "
"the correct Python version; this is Python %s)" %
(filename, sys.version.split()[0]))
raise ImportError, str(e) + extramsg
raise ImportError(str(e) + extramsg)

# Publish important data by importing them in the package
from support import __version__, error, warning, _getrealframe, _getemulframe
Expand Down
12 changes: 6 additions & 6 deletions nodebox/ext/psyco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def bind(x, rec=None):
if isinstance(o, types.MethodType)
or isinstance(o, types.FunctionType)]
if not funcs:
raise error, ("nothing bindable found in %s object" %
raise error("nothing bindable found in %s object" %
type(x).__name__)
for o in funcs:
bind(o, rec)
return
raise TypeError, "cannot bind %s objects" % type(x).__name__
raise TypeError("cannot bind %s objects" % type(x).__name__)


def unbind(x):
Expand All @@ -167,7 +167,7 @@ def unbind(x):
or isinstance(o, types.FunctionType)):
unbind(o)
return
raise TypeError, "cannot unbind %s objects" % type(x).__name__
raise TypeError("cannot unbind %s objects" % type(x).__name__)


def proxy(x, rec=None):
Expand All @@ -186,7 +186,7 @@ def proxy(x, rec=None):
if isinstance(x, types.MethodType):
p = proxy(x.im_func, rec)
return new.instancemethod(p, x.im_self, x.im_class)
raise TypeError, "cannot proxy %s objects" % type(x).__name__
raise TypeError("cannot proxy %s objects" % type(x).__name__)


def unproxy(proxy):
Expand All @@ -198,7 +198,7 @@ def unproxy(proxy):
if isinstance(proxy, types.MethodType):
f = unproxy(proxy.im_func)
return new.instancemethod(f, proxy.im_self, proxy.im_class)
raise TypeError, "%s objects cannot be proxies" % type(proxy).__name__
raise TypeError("%s objects cannot be proxies" % type(proxy).__name__)


def cannotcompile(x):
Expand All @@ -211,7 +211,7 @@ def cannotcompile(x):
if isinstance(x, types.CodeType):
_psyco.cannotcompile(x)
else:
raise TypeError, "unexpected %s object" % type(x).__name__
raise TypeError("unexpected %s object" % type(x).__name__)


def dumpcodebuf():
Expand Down
6 changes: 3 additions & 3 deletions nodebox/ext/psyco/kdictproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def setdefault(self, key, default):
return default
def pop(self, key, *args):
if len(args) > 1:
raise TypeError, "pop expected at most 2 arguments, got "\
+ repr(1 + len(args))
raise TypeError("pop expected at most 2 arguments, got "\
+ repr(1 + len(args)))
try:
value = self[key]
except KeyError:
Expand All @@ -70,7 +70,7 @@ def popitem(self):
try:
k, v = self.iteritems().next()
except StopIteration:
raise KeyError, 'container is empty'
raise KeyError('container is empty')
del self[k]
return (k, v)
def update(self, other):
Expand Down
2 changes: 1 addition & 1 deletion nodebox/ext/psyco/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def start(self):

try:
self.do_start()
except error, e:
except error as e:
if logger:
logger.write('%s: disabled by psyco.error:' % (
self.__class__.__name__), 4)
Expand Down
12 changes: 6 additions & 6 deletions nodebox/ext/psyco/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def warn(msg):
#
__version__ = 0x010502f0
if _psyco.PSYVER != __version__:
raise error, "version mismatch between Psyco parts, reinstall it"
raise error("version mismatch between Psyco parts, reinstall it")

version_info = (__version__ >> 24,
(__version__ >> 16) & 0xff,
Expand Down Expand Up @@ -123,24 +123,24 @@ def __getattr__(self, attr):
elif attr == 'f_restricted':
result = self.f_builtins is not __builtins__
elif attr == 'f_locals':
raise AttributeError, ("local variables of functions run by Psyco "
raise AttributeError("local variables of functions run by Psyco "
"cannot be accessed in any way, sorry")
else:
raise AttributeError, ("emulated Psyco frames have "
"no '%s' attribute" % attr)
raise AttributeError("emulated Psyco frames have "
"no '" + str(attr) + "' attribute" )
self.__dict__[attr] = result
return result

def __setattr__(self, attr, value):
raise AttributeError, "Psyco frame objects are read-only"
raise AttributeError("Psyco frame objects are read-only")

def __delattr__(self, attr):
if attr == 'f_trace':
# for bdb which relies on CPython frames exhibiting a slightly
# buggy behavior: you can 'del f.f_trace' as often as you like
# even without having set it previously.
return
raise AttributeError, "Psyco frame objects are read-only"
raise AttributeError("Psyco frame objects are read-only")


def embedframe(result):
Expand Down
17 changes: 10 additions & 7 deletions nodebox/graphics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import bezier
import context
import geometry
import physics
import shader
import nodebox.graphics.bezier
import nodebox.graphics.context
import nodebox.graphics.geometry
import nodebox.graphics.physics
import nodebox.graphics.shader

from noise import noise
from context import *
from nodebox.graphics.noise import noise
from nodebox.graphics.context import *

physics.line = context.line
physics.ellipse = context.ellipse
Expand All @@ -20,6 +20,9 @@

canvas = Canvas()

def get_canvas():
return canvas

def size(width=None, height=None):
if width is not None:
canvas.width = width
Expand Down
14 changes: 7 additions & 7 deletions nodebox/graphics/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Thanks to Prof. F. De Smedt at the Vrije Universiteit Brussel.

from context import BezierPath, PathElement, PathError, Point, MOVETO, LINETO, CURVETO, CLOSE
from nodebox.graphics.context import BezierPath, PathElement, PathError, Point, MOVETO, LINETO, CURVETO, CLOSE
from math import sqrt, pow

class DynamicPathElement(PathElement):
Expand Down Expand Up @@ -156,7 +156,7 @@ def _locate(path, t, segments=None):
if segments == None:
segments = segment_lengths(path, relative=True)
if len(segments) == 0:
raise PathError, "The given path is empty"
raise PathError("The given path is empty")
for i, el in enumerate(path):
if i == 0 or el.cmd == MOVETO:
closeto = Point(el.x, el.y)
Expand All @@ -179,7 +179,7 @@ def point(path, t, segments=None):
the length during each iteration.
"""
if len(path) == 0:
raise PathError, "The given path is empty"
raise PathError("The given path is empty")
i, t, closeto = _locate(path, t, segments=segments)
x0, y0 = path[i].x, path[i].y
p1 = path[i+1]
Expand All @@ -198,14 +198,14 @@ def point(path, t, segments=None):
x, y, c1x, c1y, c2x, c2y = curvepoint(t, x0, y0, x1, y1, x2, y2, x3, y3)
return DynamicPathElement(CURVETO, ((c1x, c1y), (c2x, c2y), (x, y)))
else:
raise PathError, "Unknown cmd '%s' for p1 %s" % (p1.cmd, p1)
raise PathError("Unknown cmd '" + str(p1.cmd) + "' for p1 " + str(p1))

def points(path, amount=100, start=0.0, end=1.0, segments=None):
""" Returns an iterator with a list of calculated points for the path.
To omit the last point on closed paths: end=1-1.0/amount
"""
if len(path) == 0:
raise PathError, "The given path is empty"
raise PathError("The given path is empty")
n = end - start
d = n
if amount > 1:
Expand Down Expand Up @@ -344,7 +344,7 @@ def insert_point(path, t):
pt_x, pt_y, pt_c1x, pt_c1y, pt_c2x, pt_c2y, pt_h1x, pt_h1y, pt_h2x, pt_h2y = \
curvepoint(t, x0, y0, x1, y1, x2, y2, x3, y3, True)
else:
raise PathError, "Locate should not return a MOVETO"
raise PathError("Locate should not return a MOVETO")

# NodeBox for OpenGL modifies the path in place,
# NodeBox for Mac OS X returned a path copy (see inactive code below).
Expand All @@ -357,7 +357,7 @@ def insert_point(path, t):
elif pt_cmd == LINETO:
path.insert(i+1, PathElement(cmd=LINETO, pts=[(pt_x, pt_y)]))
else:
raise PathError, "Didn't expect pt_cmd %s here" % pt_cmd
raise PathError("Didn't expect pt_cmd " + str(pt_cmd) + " here")
return path[i+1]

#new_path = BezierPath(None)
Expand Down
Loading