Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 66811) +++ Python/pythonrun.c (working copy) @@ -1150,6 +1150,52 @@ PyErr_PrintEx(1); } +static int +adjust_offset(int offset, const char *text) +{ + PyObject *unicode; + wchar_t *buf; + Py_ssize_t len; + int res; + + unicode = PyUnicode_FromStringAndSize(text, offset); + if (unicode == NULL) + return offset; + + res = len = PyUnicode_GET_SIZE(unicode); + buf = PyMem_New(wchar_t, len); + if (!buf) { + PyErr_NoMemory(); + goto done; + } + if (PyUnicode_AsWideChar((PyUnicodeObject*)unicode, buf, len) == -1) + goto done; + +#if defined(HAVE_WCSWIDTH) + { + char *oldloc; + int r; + + oldloc = setlocale(LC_ALL, NULL); + setlocale(LC_ALL, ""); + r = wcswidth(buf, len); + setlocale(LC_ALL, oldloc); + if (r != -1) res = r; + } +#elif defined(MS_WINDOWS) + { + int r; + + r = WideCharToMultiByte(CP_ACP, 0, buf, len, NULL, 0, NULL, NULL); + if (r != FALSE) res = r; + } +#endif +done: + if (buf) PyMem_FREE(buf); + Py_DECREF(unicode); + return res; +} + static void print_error_text(PyObject *f, int offset, const char *text) { @@ -1176,6 +1222,7 @@ if (offset == -1) return; PyFile_WriteString(" ", f); + offset = adjust_offset(offset, text); offset--; while (offset > 0) { PyFile_WriteString(" ", f);