Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 61597:b5ba7ea4246b
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.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 15 May 2010 16:27:27 +0000 |
| parents | cab14be0ada1 |
| children | 46ab5e4dba6b |
line wrap: on
line diff
--- a/Python/import.c Sat May 15 13:14:32 2010 +0000 +++ b/Python/import.c Sat May 15 16:27:27 2010 +0000 @@ -1633,8 +1633,7 @@ 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 @@ 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;
