[Python-checkins] r88710 - python/branches/py3k/Objects/unicodeobject.c
victor.stinner
python-checkins at python.org
Wed Mar 2 02:21:47 CET 2011
Author: victor.stinner
Date: Wed Mar 2 02:21:46 2011
New Revision: 88710
Log:
Fix my previous commit (r88709) for str.encode(errors=...)
Modified:
python/branches/py3k/Objects/unicodeobject.c
Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c (original)
+++ python/branches/py3k/Objects/unicodeobject.c Wed Mar 2 02:21:46 2011
@@ -1709,21 +1709,26 @@
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) ||
More information about the Python-checkins
mailing list