mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Implement PEP 393.
This commit is contained in:
parent
48d49497c5
commit
d63a3b8beb
102 changed files with 8153 additions and 5431 deletions
|
@ -498,17 +498,19 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
|
|||
*filename = PyDict_GetItemString(globals, "__file__");
|
||||
if (*filename != NULL && PyUnicode_Check(*filename)) {
|
||||
Py_ssize_t len = PyUnicode_GetSize(*filename);
|
||||
Py_UNICODE *unicode = PyUnicode_AS_UNICODE(*filename);
|
||||
int kind = PyUnicode_KIND(*filename);
|
||||
void *data = PyUnicode_DATA(*filename);
|
||||
|
||||
/* if filename.lower().endswith((".pyc", ".pyo")): */
|
||||
if (len >= 4 &&
|
||||
unicode[len-4] == '.' &&
|
||||
Py_UNICODE_TOLOWER(unicode[len-3]) == 'p' &&
|
||||
Py_UNICODE_TOLOWER(unicode[len-2]) == 'y' &&
|
||||
(Py_UNICODE_TOLOWER(unicode[len-1]) == 'c' ||
|
||||
Py_UNICODE_TOLOWER(unicode[len-1]) == 'o'))
|
||||
PyUnicode_READ(kind, data, len-4) == '.' &&
|
||||
Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-3)) == 'p' &&
|
||||
Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-2)) == 'y' &&
|
||||
(Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-1)) == 'c' ||
|
||||
Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-1)) == 'o'))
|
||||
{
|
||||
*filename = PyUnicode_FromUnicode(unicode, len-1);
|
||||
*filename = PyUnicode_Substring(*filename, 0,
|
||||
PyUnicode_GET_LENGTH(*filename)-1);
|
||||
if (*filename == NULL)
|
||||
goto handle_error;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue