Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c4d8d0

Browse files
committed
Fix for bug #480188: printing unicode objects
1 parent 4586d2c commit 0c4d8d0

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

Lib/test/output/test_unicode

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@ Testing builtin unicode()... done.
66
Testing builtin codecs... done.
77
Testing standard mapping codecs... 0-127... 128-255... done.
88
Testing Unicode string concatenation... done.
9+
Testing Unicode printing... abc
10+
abc def
11+
abc def
12+
abc def
13+
abc
14+
15+
abc
16+
abc
17+
def
18+
19+
def
20+
21+
done.

Lib/test/test_unicode.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,16 @@ def __str__(self):
644644
verify((u"abc" u"def" "ghi") == u"abcdefghi")
645645
verify(("abc" "def" u"ghi") == u"abcdefghi")
646646
print 'done.'
647+
648+
print 'Testing Unicode printing...',
649+
print u'abc'
650+
print u'abc', u'def'
651+
print u'abc', 'def'
652+
print 'abc', u'def'
653+
print u'abc\n'
654+
print u'abc\n',
655+
print u'abc\n',
656+
print u'def\n'
657+
print u'def\n'
658+
print 'done.'
659+

Python/ceval.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,14 +1349,24 @@ eval_frame(PyFrameObject *f)
13491349
err = PyFile_WriteString(" ", w);
13501350
if (err == 0)
13511351
err = PyFile_WriteObject(v, w, Py_PRINT_RAW);
1352-
if (err == 0 && PyString_Check(v)) {
1352+
if (err == 0) {
13531353
/* XXX move into writeobject() ? */
1354-
char *s = PyString_AsString(v);
1355-
int len = PyString_Size(v);
1354+
if (PyString_Check(v)) {
1355+
char *s = PyString_AS_STRING(v);
1356+
int len = PyString_GET_SIZE(v);
13561357
if (len > 0 &&
13571358
isspace(Py_CHARMASK(s[len-1])) &&
13581359
s[len-1] != ' ')
13591360
PyFile_SoftSpace(w, 0);
1361+
}
1362+
else if (PyUnicode_Check(v)) {
1363+
Py_UNICODE *s = PyUnicode_AS_UNICODE(v);
1364+
int len = PyUnicode_GET_SIZE(v);
1365+
if (len > 0 &&
1366+
Py_UNICODE_ISSPACE(s[len-1]) &&
1367+
s[len-1] != ' ')
1368+
PyFile_SoftSpace(w, 0);
1369+
}
13601370
}
13611371
Py_DECREF(v);
13621372
Py_XDECREF(stream);

0 commit comments

Comments
 (0)