Added code to correct combining str and unicode in ''.format(). Added test case.

This commit is contained in:
Eric Smith 2008-02-18 18:02:34 +00:00
parent 5299935be5
commit bc32fee029
2 changed files with 25 additions and 0 deletions

View file

@ -493,6 +493,22 @@ render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
if (result == NULL)
goto done;
#if PY_VERSION_HEX >= 0x03000000
assert(PyString_Check(result));
#else
assert(PyString_Check(result) || PyUnicode_Check(result));
/* Convert result to our type. We could be str, and result could
be unicode */
{
PyObject *tmp = STRINGLIB_TOSTR(result);
if (tmp == NULL)
goto done;
Py_DECREF(result);
result = tmp;
}
#endif
ok = output_data(output,
STRINGLIB_STR(result), STRINGLIB_LEN(result));
done: