mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
object to Py_FileSystemDefaultEncoding with the "surrogateescape" error handler, return a bytes object. If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8.
This commit is contained in:
parent
59e62db0a3
commit
ae6265f8d0
10 changed files with 46 additions and 26 deletions
|
@ -1633,8 +1633,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
|
|||
if (!v)
|
||||
return NULL;
|
||||
if (PyUnicode_Check(v)) {
|
||||
v = PyUnicode_AsEncodedString(v,
|
||||
Py_FileSystemDefaultEncoding, NULL);
|
||||
v = PyUnicode_EncodeFSDefault(v);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2752,14 +2751,7 @@ ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
|
|||
char *subname;
|
||||
PyObject *submod;
|
||||
char *p;
|
||||
if (!Py_FileSystemDefaultEncoding) {
|
||||
item8 = PyUnicode_EncodeASCII(PyUnicode_AsUnicode(item),
|
||||
PyUnicode_GetSize(item),
|
||||
NULL);
|
||||
} else {
|
||||
item8 = PyUnicode_AsEncodedString(item,
|
||||
Py_FileSystemDefaultEncoding, NULL);
|
||||
}
|
||||
item8 = PyUnicode_EncodeFSDefault(item);
|
||||
if (!item8) {
|
||||
PyErr_SetString(PyExc_ValueError, "Cannot encode path item");
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue