diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-02 01:21:46 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-02 01:21:46 (GMT) |
commit | 2f283c2c19f821dd5a0f2ad4a4da4c90fe583bb9 (patch) | |
tree | 478c6aca969229e8d14f685f8c6b76a7b5a5eb05 /Objects | |
parent | a5c68c3cb7bc5068833742dc10a3cd5a19e69e12 (diff) | |
download | cpython-2f283c2c19f821dd5a0f2ad4a4da4c90fe583bb9.zip cpython-2f283c2c19f821dd5a0f2ad4a4da4c90fe583bb9.tar.gz cpython-2f283c2c19f821dd5a0f2ad4a4da4c90fe583bb9.tar.bz2 |
Fix my previous commit (r88709) for str.encode(errors=...)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 6801259..1d0e97b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1709,21 +1709,26 @@ PyUnicode_AsEncodedString(PyObject *unicode, return NULL; } - if (encoding == NULL) - return PyUnicode_AsUTF8String(unicode); + if (encoding == NULL) { + if (errors == NULL || strcmp(errors, "strict") == 0) + return PyUnicode_AsUTF8String(unicode); + else + return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode), + PyUnicode_GET_SIZE(unicode), + errors); + } /* Shortcuts for common default encodings */ if (normalize_encoding(encoding, lower, sizeof(lower))) { if ((strcmp(lower, "utf-8") == 0) || (strcmp(lower, "utf8") == 0)) { - if (errors == NULL || strcmp(errors, "strict") == 0) { + if (errors == NULL || strcmp(errors, "strict") == 0) return PyUnicode_AsUTF8String(unicode); - } else { + else return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode), errors); - } } else if ((strcmp(lower, "latin-1") == 0) || (strcmp(lower, "latin1") == 0) || |