Index: src/org/python/core/PyString.java =================================================================== --- src/org/python/core/PyString.java (revision 3142) +++ src/org/python/core/PyString.java (working copy) @@ -373,7 +373,7 @@ public PyObject __call__(PyObject arg0,PyObject arg1) { try { - return new PyString(((PyString)self).str_decode(arg0.asString(0),arg1.asString(1))); + return new PyUnicode(((PyString)self).str_decode(arg0.asString(0),arg1.asString(1))); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -390,7 +390,7 @@ public PyObject __call__(PyObject arg0) { try { - return new PyString(((PyString)self).str_decode(arg0.asString(0))); + return new PyUnicode(((PyString)self).str_decode(arg0.asString(0))); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -405,7 +405,7 @@ } public PyObject __call__() { - return new PyString(((PyString)self).str_decode()); + return new PyUnicode(((PyString)self).str_decode()); } } Index: src/org/python/core/PyUnicode.java =================================================================== --- src/org/python/core/PyUnicode.java (revision 3142) +++ src/org/python/core/PyUnicode.java (working copy) @@ -409,7 +409,7 @@ public PyObject __call__(PyObject arg0,PyObject arg1) { try { - return new PyUnicode(((PyUnicode)self).unicode_encode(arg0.asString(0),arg1.asString(1))); + return new PyString(((PyUnicode)self).unicode_encode(arg0.asString(0),arg1.asString(1))); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -426,7 +426,7 @@ public PyObject __call__(PyObject arg0) { try { - return new PyUnicode(((PyUnicode)self).unicode_encode(arg0.asString(0))); + return new PyString(((PyUnicode)self).unicode_encode(arg0.asString(0))); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -441,7 +441,7 @@ } public PyObject __call__() { - return new PyUnicode(((PyUnicode)self).unicode_encode()); + return new PyString(((PyUnicode)self).unicode_encode()); } } @@ -1513,6 +1513,10 @@ return str___unicode__(); } + public PyString __str__() { + return unicode___str__(); + } + public PyString unicode___str__() { return new PyString(toString()); } Index: src/templates/unicode.expose =================================================================== --- src/templates/unicode.expose (revision 3142) +++ src/templates/unicode.expose (working copy) @@ -21,7 +21,7 @@ expose_meth: :u center i expose_meth: :i count s i? i? expose_meth: :u decode s? s? -expose_meth: :u encode s? s? +expose_meth: :s encode s? s? expose_meth: :b endswith s i? i? expose_meth: :u expandtabs i? expose_meth: :i find s i? i? Index: src/templates/str.expose =================================================================== --- src/templates/str.expose (revision 3142) +++ src/templates/str.expose (working copy) @@ -21,7 +21,7 @@ expose_meth: :s capitalize expose_meth: :s center i expose_meth: :i count s i? i? -expose_meth: :s decode s? s? +expose_meth: :u decode s? s? expose_meth: :s encode s? s? expose_meth: :b endswith s i? i? expose_meth: :s expandtabs i? Index: Lib/test/test_unicode.py =================================================================== --- Lib/test/test_unicode.py (revision 3142) +++ Lib/test/test_unicode.py (working copy) @@ -485,6 +485,10 @@ verify('%i%s %*.*s' % (10, 3, 5,3,u'abc',) == u'103 abc') print 'done.' +print 'Testing builtin str()...', +verify(str(u"") == "") +verify(isinstance(str(u""), str)) + print 'Testing builtin unicode()...', # unicode(obj) tests (this maps to PyObject_Unicode() at C level) @@ -584,9 +588,8 @@ # UTF-8 specific encoding tests: verify(u''.encode('utf-8') == '') verify(u'\u20ac'.encode('utf-8') == '\xe2\x82\xac') -#XXX: ? -if not sys.platform.startswith('java'): - verify(u'\ud800\udc02'.encode('utf-8') == '\xf0\x90\x80\x82') +verify(u'\ud800\udc02'.encode('utf-8') == '\xf0\x90\x80\x82') +verify(isinstance(u'\ud800\udc02'.encode('utf-8'), str)) verify(u'\ud84d\udc56'.encode('utf-8') == '\xf0\xa3\x91\x96') #XXX: ? if not sys.platform.startswith('java'): @@ -655,15 +658,14 @@ verify(unicode('Andr\202 x','ascii','ignore') == u"Andr x") verify(unicode('Andr\202 x','ascii','replace') == u'Andr\uFFFD x') -# XXX: ? -if not sys.platform.startswith('java'): - verify("\\N{foo}xx".decode("unicode-escape", "ignore") == u"xx") - try: - "\\".decode("unicode-escape") - except ValueError: - pass - else: - raise TestFailed, '"\\".decode("unicode-escape") should fail' +verify("\\N{foo}xx".decode("unicode-escape", "ignore") == u"xx") +verify(isinstance("\\N{foo}xx".decode("unicode-escape", "ignore"), unicode)) +try: + "\\".decode("unicode-escape") +except ValueError: + pass +else: + raise TestFailed, '"\\".decode("unicode-escape") should fail' verify(u'hello'.encode('ascii') == 'hello') # XXX: Jython does not support utf-7 yet.