فهرست منبع

The 'new' module has been deprecated since 2.6 and removed in Python 3, let's not use it (use 'types' module instead)

rdb 12 سال پیش
والد
کامیت
c729775265

+ 6 - 7
direct/src/fsm/State.py

@@ -23,7 +23,6 @@ class State(DirectObject):
 
         @classmethod
         def replaceMethod(self, oldFunction, newFunction):
-            import new
             import types
             count = 0        
             for state in self.States:
@@ -34,16 +33,16 @@ class State(DirectObject):
                 if type(enterFunc) == types.MethodType:
                     if (enterFunc.im_func == oldFunction):
                         # print 'found: ', enterFunc, oldFunction
-                        state.setEnterFunc(new.instancemethod(newFunction,
-                                                              enterFunc.im_self,
-                                                              enterFunc.im_class))
+                        state.setEnterFunc(types.MethodType(newFunction,
+                                                            enterFunc.im_self,
+                                                            enterFunc.im_class))
                         count += 1
                 if type(exitFunc) == types.MethodType:
                     if (exitFunc.im_func == oldFunction):
                         # print 'found: ', exitFunc, oldFunction
-                        state.setExitFunc(new.instancemethod(newFunction,
-                                                             exitFunc.im_self,
-                                                             exitFunc.im_class))
+                        state.setExitFunc(types.MethodType(newFunction,
+                                                           exitFunc.im_self,
+                                                           exitFunc.im_class))
                         count += 1
             return count
 

+ 3 - 4
direct/src/interval/FunctionInterval.py

@@ -28,7 +28,6 @@ class FunctionInterval(Interval.Interval):
 
         @classmethod
         def replaceMethod(self, oldFunction, newFunction):
-            import new
             import types
             count = 0        
             for ival in self.FunctionIntervals:
@@ -37,9 +36,9 @@ class FunctionInterval(Interval.Interval):
                 if type(ival.function) == types.MethodType:
                     if (ival.function.im_func == oldFunction):
                         # print 'found: ', ival.function, oldFunction
-                        ival.function = new.instancemethod(newFunction,
-                                                           ival.function.im_self,
-                                                           ival.function.im_class)
+                        ival.function = types.MethodType(newFunction,
+                                                         ival.function.im_self,
+                                                         ival.function.im_class)
                         count += 1
             return count
 

+ 0 - 1
direct/src/p3d/Packager.py

@@ -10,7 +10,6 @@ import sys
 import os
 import glob
 import marshal
-import new
 import string
 import types
 import getpass

+ 1 - 2
direct/src/showbase/Messenger.py

@@ -506,7 +506,6 @@ class Messenger:
         This is only used by Finder.py - the module that lets
         you redefine functions with Control-c-Control-v
         """
-        import new
         retFlag = 0
         for entry in self.__callbacks.items():
             event, objectDict = entry
@@ -522,7 +521,7 @@ class Messenger:
                 #       'oldMethod: ' + repr(oldMethod) + '\n' +
                 #       'newFunction: ' + repr(newFunction) + '\n')
                 if (function == oldMethod):
-                    newMethod = new.instancemethod(
+                    newMethod = types.MethodType(
                         newFunction, method.im_self, method.im_class)
                     params[0] = newMethod
                     # Found it retrun true

+ 12 - 14
direct/src/showbase/PythonUtil.py

@@ -45,7 +45,6 @@ import os
 import sys
 import random
 import time
-import new
 import gc
 #if __debug__:
 import traceback
@@ -1203,16 +1202,15 @@ def getSetter(targetObj, valueName, prefix='set'):
 def mostDerivedLast(classList):
     """pass in list of classes. sorts list in-place, with derived classes
     appearing after their bases"""
-    def compare(a, b):
-        if issubclass(a, b):
-            result=1
-        elif issubclass(b, a):
-            result=-1
-        else:
-            result=0
-        #print a, b, result
-        return result
-    classList.sort(compare)
+
+    class ClassSortKey(object):
+        __slots__ = 'classobj',
+        def __init__(self, classobj):
+            self.classobj = classobj
+        def __lt__(self, other):
+            return issubclass(other.classobj, self.classobj)
+
+    classList.sort(key=ClassSortKey)
 
 """
 ParamObj/ParamSet
@@ -1509,7 +1507,7 @@ class ParamObj:
                 # then the applier, or b) call the setter and queue the
                 # applier, depending on whether our params are locked
                 """
-                setattr(self, setterName, new.instancemethod(
+                setattr(self, setterName, types.MethodType(
                     Functor(setterStub, param, setterFunc), self, self.__class__))
                     """
                 def setterStub(self, value, param=param, origSetterName=origSetterName):
@@ -2734,7 +2732,7 @@ def tagRepr(obj, tag):
             return s
         oldRepr = Functor(stringer, repr(obj))
         stringer = None
-    obj.__repr__ = new.instancemethod(Functor(reprWithTag, oldRepr, tag), obj, obj.__class__)
+    obj.__repr__ = types.MethodType(Functor(reprWithTag, oldRepr, tag), obj, obj.__class__)
     reprWithTag = None
     return obj
 
@@ -2761,7 +2759,7 @@ def appendStr(obj, st):
             return s
         oldStr = Functor(stringer, str(obj))
         stringer = None
-    obj.__str__ = new.instancemethod(Functor(appendedStr, oldStr, st), obj, obj.__class__)
+    obj.__str__ = types.MethodType(Functor(appendedStr, oldStr, st), obj, obj.__class__)
     appendedStr = None
     return obj
 

+ 0 - 1
direct/src/showbase/VFSImporter.py

@@ -1,6 +1,5 @@
 from libpandaexpress import Filename, VirtualFileSystem, VirtualFileMountSystem, OFileStream, copyStream
 import sys
-import new
 import os
 import marshal
 import imp

+ 3 - 4
direct/src/task/Task.py

@@ -560,10 +560,9 @@ class TaskManager:
         else:
             function = method
         if (function == oldMethod):
-            import new
-            newMethod = new.instancemethod(newFunction,
-                                           method.im_self,
-                                           method.im_class)
+            newMethod = types.MethodType(newFunction,
+                                         method.im_self,
+                                         method.im_class)
             task.setFunction(newMethod)
             # Found a match
             return 1