This patch adds a new builtin unistr() which behaves like str()

except that it always returns Unicode objects.

A new C API PyObject_Unicode() is also provided.

This closes patch #101664.

Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
This commit is contained in:
Marc-André Lemburg 2001-01-17 17:09:53 +00:00
parent d5c43065d5
commit ad7c98e264
10 changed files with 119 additions and 6 deletions

View file

@ -214,6 +214,17 @@ if str(()) != '()': raise TestFailed, 'str(())'
if str([]) != '[]': raise TestFailed, 'str([])'
if str({}) != '{}': raise TestFailed, 'str({})'
print 'unistr'
if unistr('') <> u'': raise TestFailed, 'unistr(\'\')'
if unistr('a') <> u'a': raise TestFailed, 'unistr(\'a\')'
if unistr(u'') <> u'': raise TestFailed, 'unistr(u\'\')'
if unistr(u'a') <> u'a': raise TestFailed, 'unistr(u\'a\')'
if unistr(0) <> u'0': raise TestFailed, 'unistr(0)'
if unistr(0L) <> u'0': raise TestFailed, 'unistr(0L)'
if unistr(()) <> u'()': raise TestFailed, 'unistr(())'
if unistr([]) <> u'[]': raise TestFailed, 'unistr([])'
if unistr({}) <> u'{}': raise TestFailed, 'unistr({})'
print 'tuple'
if tuple(()) != (): raise TestFailed, 'tuple(())'
if tuple((0, 1, 2, 3)) != (0, 1, 2, 3): raise TestFailed, 'tuple((0, 1, 2, 3))'