mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue #9425: Create PyModule_GetFilenameObject() function
... to get the filename as a unicode object, instead of a byte string. Function needed to support unencodable filenames. Deprecate PyModule_GetFilename() in favor on the new function.
This commit is contained in:
parent
6951157475
commit
6c00c1464f
4 changed files with 32 additions and 9 deletions
|
|
@ -188,8 +188,8 @@ PyModule_GetName(PyObject *m)
|
|||
return _PyUnicode_AsString(nameobj);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
module_getfilename(PyObject *m)
|
||||
PyObject*
|
||||
PyModule_GetFilenameObject(PyObject *m)
|
||||
{
|
||||
PyObject *d;
|
||||
PyObject *fileobj;
|
||||
|
|
@ -205,6 +205,7 @@ module_getfilename(PyObject *m)
|
|||
PyErr_SetString(PyExc_SystemError, "module filename missing");
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(fileobj);
|
||||
return fileobj;
|
||||
}
|
||||
|
||||
|
|
@ -212,10 +213,13 @@ const char *
|
|||
PyModule_GetFilename(PyObject *m)
|
||||
{
|
||||
PyObject *fileobj;
|
||||
fileobj = module_getfilename(m);
|
||||
char *utf8;
|
||||
fileobj = PyModule_GetFilenameObject(m);
|
||||
if (fileobj == NULL)
|
||||
return NULL;
|
||||
return _PyUnicode_AsString(fileobj);
|
||||
utf8 = _PyUnicode_AsString(fileobj);
|
||||
Py_DECREF(fileobj);
|
||||
return utf8;
|
||||
}
|
||||
|
||||
PyModuleDef*
|
||||
|
|
@ -346,19 +350,21 @@ static PyObject *
|
|||
module_repr(PyModuleObject *m)
|
||||
{
|
||||
const char *name;
|
||||
PyObject *filename;
|
||||
PyObject *filename, *repr;
|
||||
|
||||
name = PyModule_GetName((PyObject *)m);
|
||||
if (name == NULL) {
|
||||
PyErr_Clear();
|
||||
name = "?";
|
||||
}
|
||||
filename = module_getfilename((PyObject *)m);
|
||||
filename = PyModule_GetFilenameObject((PyObject *)m);
|
||||
if (filename == NULL) {
|
||||
PyErr_Clear();
|
||||
return PyUnicode_FromFormat("<module '%s' (built-in)>", name);
|
||||
}
|
||||
return PyUnicode_FromFormat("<module '%s' from '%U'>", name, filename);
|
||||
repr = PyUnicode_FromFormat("<module '%s' from '%U'>", name, filename);
|
||||
Py_DECREF(filename);
|
||||
return repr;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue