mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
Fix my previous commit (r88709) for str.encode(errors=...)
This commit is contained in:
parent
a5c68c3cb7
commit
2f283c2c19
1 changed files with 10 additions and 5 deletions
|
@ -1709,22 +1709,27 @@ PyUnicode_AsEncodedString(PyObject *unicode,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding == NULL)
|
if (encoding == NULL) {
|
||||||
|
if (errors == NULL || strcmp(errors, "strict") == 0)
|
||||||
return PyUnicode_AsUTF8String(unicode);
|
return PyUnicode_AsUTF8String(unicode);
|
||||||
|
else
|
||||||
|
return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
|
||||||
|
PyUnicode_GET_SIZE(unicode),
|
||||||
|
errors);
|
||||||
|
}
|
||||||
|
|
||||||
/* Shortcuts for common default encodings */
|
/* Shortcuts for common default encodings */
|
||||||
if (normalize_encoding(encoding, lower, sizeof(lower))) {
|
if (normalize_encoding(encoding, lower, sizeof(lower))) {
|
||||||
if ((strcmp(lower, "utf-8") == 0) ||
|
if ((strcmp(lower, "utf-8") == 0) ||
|
||||||
(strcmp(lower, "utf8") == 0))
|
(strcmp(lower, "utf8") == 0))
|
||||||
{
|
{
|
||||||
if (errors == NULL || strcmp(errors, "strict") == 0) {
|
if (errors == NULL || strcmp(errors, "strict") == 0)
|
||||||
return PyUnicode_AsUTF8String(unicode);
|
return PyUnicode_AsUTF8String(unicode);
|
||||||
} else {
|
else
|
||||||
return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
|
return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
|
||||||
PyUnicode_GET_SIZE(unicode),
|
PyUnicode_GET_SIZE(unicode),
|
||||||
errors);
|
errors);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if ((strcmp(lower, "latin-1") == 0) ||
|
else if ((strcmp(lower, "latin-1") == 0) ||
|
||||||
(strcmp(lower, "latin1") == 0) ||
|
(strcmp(lower, "latin1") == 0) ||
|
||||||
(strcmp(lower, "iso-8859-1") == 0))
|
(strcmp(lower, "iso-8859-1") == 0))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue