mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-27 15:25:54 -04:00
general: Clean up hacks to support Python 3.5 from codebase
This commit is contained in:
parent
e879817ed5
commit
e060a29228
@ -53,9 +53,6 @@ __init__(PyObject *path) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *path_str;
|
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03060000
|
|
||||||
// It must be an os.PathLike object. Check for an __fspath__ method.
|
// It must be an os.PathLike object. Check for an __fspath__ method.
|
||||||
PyObject *fspath = PyObject_GetAttrString((PyObject *)Py_TYPE(path), "__fspath__");
|
PyObject *fspath = PyObject_GetAttrString((PyObject *)Py_TYPE(path), "__fspath__");
|
||||||
if (fspath == nullptr) {
|
if (fspath == nullptr) {
|
||||||
@ -63,20 +60,8 @@ __init__(PyObject *path) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
path_str = PyObject_CallFunctionObjArgs(fspath, path, nullptr);
|
PyObject *path_str = PyObject_CallFunctionObjArgs(fspath, path, nullptr);
|
||||||
Py_DECREF(fspath);
|
Py_DECREF(fspath);
|
||||||
#else
|
|
||||||
// There is no standard path protocol before Python 3.6, but let's try and
|
|
||||||
// support taking pathlib paths anyway. We don't version check this to
|
|
||||||
// allow people to use backports of the pathlib module.
|
|
||||||
if (PyObject_HasAttrString(path, "_format_parsed_parts")) {
|
|
||||||
path_str = PyObject_Str(path);
|
|
||||||
} else {
|
|
||||||
PyErr_Format(PyExc_TypeError, "expected str, bytes, Path or Filename object, not %s", Py_TYPE(path)->tp_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (path_str == nullptr) {
|
if (path_str == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -73,36 +73,6 @@ static struct _inittab extensions[] = {
|
|||||||
static wchar_t *log_pathw = NULL;
|
static wchar_t *log_pathw = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) && PY_VERSION_HEX < 0x03060000
|
|
||||||
static int supports_code_page(UINT cp) {
|
|
||||||
if (cp == 0) {
|
|
||||||
cp = GetACP();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Shortcut, because we know that these encodings are bundled by default--
|
|
||||||
* see FreezeTool.py and Python's encodings/aliases.py */
|
|
||||||
if (cp != 0 && cp != 1252 && cp != 367 && cp != 437 && cp != 850 && cp != 819) {
|
|
||||||
const struct _frozen *moddef;
|
|
||||||
char codec[100];
|
|
||||||
|
|
||||||
/* Check if the codec was frozen into the program. We can't check this
|
|
||||||
* using _PyCodec_Lookup, since Python hasn't been initialized yet. */
|
|
||||||
PyOS_snprintf(codec, sizeof(codec), "encodings.cp%u", (unsigned int)cp);
|
|
||||||
|
|
||||||
moddef = PyImport_FrozenModules;
|
|
||||||
while (moddef->name) {
|
|
||||||
if (strcmp(moddef->name, codec) == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
++moddef;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main_dir field of the blobinfo structure, but only if it wasn't
|
* Sets the main_dir field of the blobinfo structure, but only if it wasn't
|
||||||
* already set.
|
* already set.
|
||||||
@ -408,19 +378,6 @@ int Py_FrozenMain(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MS_WINDOWS) && PY_VERSION_HEX >= 0x03040000 && PY_VERSION_HEX < 0x03060000
|
|
||||||
if (!supports_code_page(GetConsoleOutputCP()) ||
|
|
||||||
!supports_code_page(GetConsoleCP())) {
|
|
||||||
/* Revert to the active codepage, and tell Python to use the 'mbcs'
|
|
||||||
* encoding (which always uses the active codepage). In 99% of cases,
|
|
||||||
* this will be the same thing anyway. */
|
|
||||||
UINT acp = GetACP();
|
|
||||||
SetConsoleCP(acp);
|
|
||||||
SetConsoleOutputCP(acp);
|
|
||||||
Py_SetStandardStreamEncoding("mbcs", NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
|
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
|
||||||
Py_NoSiteFlag = 0;
|
Py_NoSiteFlag = 0;
|
||||||
Py_NoUserSiteDirectory = 1;
|
Py_NoUserSiteDirectory = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user