diff --git a/direct/src/fsm/State.py b/direct/src/fsm/State.py index 3842b0844b..07df3dd9d0 100644 --- a/direct/src/fsm/State.py +++ b/direct/src/fsm/State.py @@ -4,6 +4,7 @@ __all__ = ['State'] from direct.directnotify.DirectNotifyGlobal import directNotify from direct.showbase.DirectObject import DirectObject +import sys class State(DirectObject): @@ -32,16 +33,24 @@ class State(DirectObject): if type(enterFunc) == types.MethodType: if enterFunc.__func__ == oldFunction: # print 'found: ', enterFunc, oldFunction - state.setEnterFunc(types.MethodType(newFunction, - enterFunc.__self__, - enterFunc.__self__.__class__)) + if sys.version_info >= (3, 0): + state.setEnterFunc(types.MethodType(newFunction, + enterFunc.__self__)) + else: + state.setEnterFunc(types.MethodType(newFunction, + enterFunc.__self__, + enterFunc.__self__.__class__)) count += 1 if type(exitFunc) == types.MethodType: if exitFunc.__func__ == oldFunction: # print 'found: ', exitFunc, oldFunction - state.setExitFunc(types.MethodType(newFunction, - exitFunc.__self__, - exitFunc.__self__.__class__)) + if sys.version_info >= (3, 0): + state.setExitFunc(types.MethodType(newFunction, + exitFunc.__self__)) + else: + state.setExitFunc(types.MethodType(newFunction, + exitFunc.__self__, + exitFunc.__self__.__class__)) count += 1 return count diff --git a/direct/src/interval/FunctionInterval.py b/direct/src/interval/FunctionInterval.py index db626c404e..942875d4e3 100644 --- a/direct/src/interval/FunctionInterval.py +++ b/direct/src/interval/FunctionInterval.py @@ -7,6 +7,7 @@ from panda3d.direct import * from direct.showbase.MessengerGlobal import * from direct.directnotify.DirectNotifyGlobal import directNotify from . import Interval +import sys ############################################################# @@ -36,9 +37,13 @@ class FunctionInterval(Interval.Interval): if type(ival.function) == types.MethodType: if ival.function.__func__ == oldFunction: # print 'found: ', ival.function, oldFunction - ival.function = types.MethodType(newFunction, - ival.function.__self__, - ival.function.__self__.__class__) + if sys.version_info >= (3, 0): + ival.function = types.MethodType(newFunction, + ival.function.__self__) + else: + ival.function = types.MethodType(newFunction, + ival.function.__self__, + ival.function.__self__.__class__) count += 1 return count diff --git a/direct/src/showbase/Messenger.py b/direct/src/showbase/Messenger.py index e4ba5ccda8..457eba20c8 100644 --- a/direct/src/showbase/Messenger.py +++ b/direct/src/showbase/Messenger.py @@ -8,6 +8,7 @@ __all__ = ['Messenger'] from .PythonUtil import * from direct.directnotify import DirectNotifyGlobal import types +import sys from direct.stdpy.threading import Lock @@ -464,8 +465,11 @@ class Messenger: # 'oldMethod: ' + repr(oldMethod) + '\n' + # 'newFunction: ' + repr(newFunction) + '\n') if (function == oldMethod): - newMethod = types.MethodType( - newFunction, method.__self__, method.__self__.__class__) + if sys.version_info >= (3, 0): + newMethod = types.MethodType(newFunction, method.__self__) + else: + newMethod = types.MethodType( + newFunction, method.__self__, method.__self__.__class__) params[0] = newMethod # Found it retrun true retFlag += 1 diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index e92025a775..98753a7622 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -1600,7 +1600,10 @@ def appendStr(obj, st): return s oldStr = Functor(stringer, str(obj)) stringer = None - obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj, obj.__class__) + if sys.version_info >= (3, 0): + obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj) + else: + obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj, obj.__class__) appendedStr = None return obj diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 93e30eb3db..bc7b9b6e6a 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -599,9 +599,13 @@ class TaskManager: else: function = method if (function == oldMethod): - newMethod = types.MethodType(newFunction, - method.__self__, - method.__self__.__class__) + if sys.version_info >= (3, 0): + newMethod = types.MethodType(newFunction, + method.__self__) + else: + newMethod = types.MethodType(newFunction, + method.__self__, + method.__self__.__class__) task.setFunction(newMethod) # Found a match return 1