mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
Fixes for Python 3.2
This commit is contained in:
parent
6bb5fdc5e0
commit
40cddd6280
@ -68,7 +68,7 @@ class panda3d_import_manager:
|
||||
target = dir
|
||||
break
|
||||
if target == None:
|
||||
raise ImportError, "Cannot find %s" % (filename)
|
||||
raise ImportError("Cannot find %s" % (filename))
|
||||
target = cls.os.path.abspath(target)
|
||||
|
||||
# And add that directory to the system library path.
|
||||
@ -110,8 +110,10 @@ class panda3d_import_manager:
|
||||
# Try to import it normally first.
|
||||
try:
|
||||
return __import__(name)
|
||||
except ImportError, err:
|
||||
if str(err) != "No module named " + name:
|
||||
except ImportError:
|
||||
_, err, _ = cls.sys.exc_info()
|
||||
if str(err) != "No module named " + name and \
|
||||
str(err) != "No module named '%s'" % name:
|
||||
raise
|
||||
|
||||
# Hm, importing normally didn't work. Let's try imp.load_dynamic.
|
||||
@ -130,7 +132,7 @@ class panda3d_import_manager:
|
||||
break
|
||||
if target == None:
|
||||
message = "DLL loader cannot find %s." % name
|
||||
raise ImportError, message
|
||||
raise ImportError(message)
|
||||
target = cls.os.path.abspath(target)
|
||||
|
||||
# Now import the file explicitly.
|
||||
@ -173,7 +175,7 @@ class panda3d_submodule(type(sys)):
|
||||
return value
|
||||
|
||||
# Not found? Raise the error that Python would normally raise.
|
||||
raise AttributeError, "'module' object has no attribute '%s'" % name
|
||||
raise AttributeError("'module' object has no attribute '%s'" % name)
|
||||
|
||||
class panda3d_multisubmodule(type(sys)):
|
||||
""" Represents a submodule of 'panda3d' that represents multiple
|
||||
@ -192,10 +194,11 @@ class panda3d_multisubmodule(type(sys)):
|
||||
for lib in self.__libraries__:
|
||||
try:
|
||||
self.__manager__.libimport(lib)
|
||||
except ImportError, msg:
|
||||
except ImportError:
|
||||
_, msg, _ = self.__manager__.sys.exc_info()
|
||||
err.append(str(msg).rstrip('.'))
|
||||
if len(err) > 0:
|
||||
raise ImportError, ', '.join(err)
|
||||
raise ImportError(', '.join(err))
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == "__all__":
|
||||
@ -217,7 +220,7 @@ class panda3d_multisubmodule(type(sys)):
|
||||
return value
|
||||
|
||||
# Not found? Raise the error that Python would normally raise.
|
||||
raise AttributeError, "'module' object has no attribute '%s'" % name
|
||||
raise AttributeError("'module' object has no attribute '%s'" % name)
|
||||
|
||||
class panda3d_module(type(sys)):
|
||||
""" Represents the main 'panda3d' module. """
|
||||
@ -232,10 +235,11 @@ class panda3d_module(type(sys)):
|
||||
for module in self.modules:
|
||||
try:
|
||||
self.__manager__.sys.modules["panda3d.%s" % module].__load__()
|
||||
except ImportError, msg:
|
||||
except ImportError:
|
||||
_, msg, _ = self.__manager__.sys.exc_info()
|
||||
err.append(str(msg).rstrip('.'))
|
||||
if len(err) > 0:
|
||||
raise ImportError, ', '.join(err)
|
||||
raise ImportError(', '.join(err))
|
||||
|
||||
|
||||
def __getattr__(self, name):
|
||||
@ -250,7 +254,7 @@ class panda3d_module(type(sys)):
|
||||
return value
|
||||
|
||||
# Not found? Raise the error that Python would normally raise.
|
||||
raise AttributeError, "'module' object has no attribute '%s'" % name
|
||||
raise AttributeError("'module' object has no attribute '%s'" % name)
|
||||
|
||||
# Create the fake module objects and insert them into sys.modules.
|
||||
this = panda3d_module("panda3d")
|
||||
|
@ -109,30 +109,42 @@ int write_python_table_native(ostream &out) {
|
||||
|
||||
pset<std::string >::iterator ii;
|
||||
for(ii = Libraries.begin(); ii != Libraries.end(); ii++) {
|
||||
printf("Referencing Library %s\n",(*ii).c_str());
|
||||
out << "extern LibraryDef "<< *ii << "_moddef ;\n";
|
||||
printf("Referencing Library %s\n",(*ii).c_str());
|
||||
out << "extern LibraryDef "<< *ii << "_moddef;\n";
|
||||
}
|
||||
|
||||
out << "#ifdef _WIN32\n"
|
||||
<< "extern \"C\" __declspec(dllexport) void init" << library_name << "();\n"
|
||||
out << "\n"
|
||||
<< "#if PY_MAJOR_VERSION >= 3\n"
|
||||
<< "#define INIT_FUNC PyObject *PyInit_" << library_name << "\n"
|
||||
<< "#else\n"
|
||||
<< "extern \"C\" void init" << library_name << "();\n"
|
||||
<< "#define INIT_FUNC void init" << library_name << "\n"
|
||||
<< "#endif\n\n"
|
||||
<< "void init" << library_name << "() \n{\n";
|
||||
|
||||
|
||||
<< "#ifdef _WIN32\n"
|
||||
<< "extern \"C\" __declspec(dllexport) INIT_FUNC();\n"
|
||||
<< "#else\n"
|
||||
<< "extern \"C\" INIT_FUNC();\n"
|
||||
<< "#endif\n\n"
|
||||
|
||||
<< "INIT_FUNC() {\n";
|
||||
|
||||
if (track_interpreter) {
|
||||
out << " in_interpreter = 1;\n";
|
||||
out << " in_interpreter = 1;\n";
|
||||
}
|
||||
|
||||
out << " LibraryDef *defs[] = {";
|
||||
for(ii = Libraries.begin(); ii != Libraries.end(); ii++)
|
||||
out << "&"<< *ii << "_moddef,";
|
||||
out << " LibraryDef *defs[] = {";
|
||||
for(ii = Libraries.begin(); ii != Libraries.end(); ii++) {
|
||||
out << "&"<< *ii << "_moddef, ";
|
||||
}
|
||||
|
||||
out << " NULL };\n ";
|
||||
out << "NULL};\n\n";
|
||||
|
||||
|
||||
out << " Dtool_PyModuleInitHelper( defs, \"" << library_name << "\");\n";
|
||||
out << "\n\n\n}\n";
|
||||
out << "#if PY_MAJOR_VERSION >= 3\n";
|
||||
out << " return Dtool_PyModuleInitHelper(defs, \"" << library_name << "\");\n";
|
||||
out << "#else\n";
|
||||
out << " Dtool_PyModuleInitHelper(defs, \"" << library_name << "\");\n";
|
||||
out << "#endif\n";
|
||||
out << "}\n";
|
||||
|
||||
return count;
|
||||
}
|
||||
|
@ -51,6 +51,11 @@ PythonTask(PyObject *function, const string &name) :
|
||||
// Ensure that the Python threading system is initialized and ready
|
||||
// to go.
|
||||
#ifdef WITH_THREAD // This symbol defined within Python.h
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03020000
|
||||
Py_Initialize();
|
||||
#endif
|
||||
|
||||
PyEval_InitThreads();
|
||||
#endif
|
||||
#endif
|
||||
|
@ -70,6 +70,11 @@ Thread(const string &name, const string &sync_name) :
|
||||
// Ensure that the Python threading system is initialized and ready
|
||||
// to go.
|
||||
#ifdef WITH_THREAD // This symbol defined within Python.h
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03020000
|
||||
Py_Initialize();
|
||||
#endif
|
||||
|
||||
PyEval_InitThreads();
|
||||
#endif
|
||||
#endif
|
||||
|
@ -523,6 +523,11 @@ init_pointers() {
|
||||
#ifdef HAVE_PYTHON
|
||||
// Ensure that the Python threading system is initialized and ready
|
||||
// to go.
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03020000
|
||||
Py_Initialize();
|
||||
#endif
|
||||
|
||||
PyEval_InitThreads();
|
||||
#endif
|
||||
}
|
||||
|
@ -41,6 +41,11 @@ PythonCallbackObject(PyObject *function) {
|
||||
// Ensure that the Python threading system is initialized and ready
|
||||
// to go.
|
||||
#ifdef WITH_THREAD // This symbol defined within Python.h
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03020000
|
||||
Py_Initialize();
|
||||
#endif
|
||||
|
||||
PyEval_InitThreads();
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user