diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-15 16:27:27 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-15 16:27:27 (GMT) |
commit | ae6265f8d06dbec7d08c73ca23dad0f040d09b8e (patch) | |
tree | 3598426233e690b284bce322194f51be94ab6799 /Objects | |
parent | 59e62db0a39eb89930ed3ae1730726cd15b7d640 (diff) | |
download | cpython-ae6265f8d06dbec7d08c73ca23dad0f040d09b8e.zip cpython-ae6265f8d06dbec7d08c73ca23dad0f040d09b8e.tar.gz cpython-ae6265f8d06dbec7d08c73ca23dad0f040d09b8e.tar.bz2 |
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.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 307027a..b97621b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1461,6 +1461,18 @@ PyObject *PyUnicode_AsEncodedObject(PyObject *unicode, return NULL; } +PyObject *PyUnicode_EncodeFSDefault(PyObject *unicode) +{ + if (Py_FileSystemDefaultEncoding) + return PyUnicode_AsEncodedString(unicode, + Py_FileSystemDefaultEncoding, + "surrogateescape"); + else + return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode), + PyUnicode_GET_SIZE(unicode), + "surrogateescape"); +} + PyObject *PyUnicode_AsEncodedString(PyObject *unicode, const char *encoding, const char *errors) @@ -1646,9 +1658,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr) arg = PyUnicode_FromObject(arg); if (!arg) return 0; - output = PyUnicode_AsEncodedObject(arg, - Py_FileSystemDefaultEncoding, - "surrogateescape"); + output = PyUnicode_EncodeFSDefault(arg); Py_DECREF(arg); if (!output) return 0; |