From: <cg...@us...> - 2007-04-17 06:35:15
|
Revision: 3156 http://svn.sourceforge.net/jython/?rev=3156&view=rev Author: cgroves Date: 2007-04-16 23:35:13 -0700 (Mon, 16 Apr 2007) Log Message: ----------- applied patch #1681774 from pjenvey to fix str.decode and unicode.encode Modified Paths: -------------- trunk/jython/Lib/test/test_unicode.py trunk/jython/NEWS trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/templates/str.expose trunk/jython/src/templates/unicode.expose Modified: trunk/jython/Lib/test/test_unicode.py =================================================================== --- trunk/jython/Lib/test/test_unicode.py 2007-04-17 05:41:53 UTC (rev 3155) +++ trunk/jython/Lib/test/test_unicode.py 2007-04-17 06:35:13 UTC (rev 3156) @@ -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. Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2007-04-17 05:41:53 UTC (rev 3155) +++ trunk/jython/NEWS 2007-04-17 06:35:13 UTC (rev 3156) @@ -24,6 +24,8 @@ - [ 1619040 ] dict.fromkeys() should take iterable - [ 1658647 ] type(x) calls x.__class__.__init__ - [ 1699556 ] SAXException descends from Java's Exception instead of Python's + Patches applied + - [ 1681774 ] str.decode, unicode.encode and str(u'') fixes Jython 2.2 beta1 New features Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-04-17 05:41:53 UTC (rev 3155) +++ trunk/jython/src/org/python/core/PyString.java 2007-04-17 06:35:13 UTC (rev 3156) @@ -465,7 +465,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) { @@ -482,7 +482,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) { @@ -497,7 +497,7 @@ } public PyObject __call__() { - return new PyString(((PyString)self).str_decode()); + return new PyUnicode(((PyString)self).str_decode()); } } Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2007-04-17 05:41:53 UTC (rev 3155) +++ trunk/jython/src/org/python/core/PyUnicode.java 2007-04-17 06:35:13 UTC (rev 3156) @@ -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()); } } @@ -1491,6 +1491,10 @@ return str___unicode__(); } + public PyString __str__() { + return unicode___str__(); + } + public PyString unicode___str__() { return new PyString(toString()); } Modified: trunk/jython/src/templates/str.expose =================================================================== --- trunk/jython/src/templates/str.expose 2007-04-17 05:41:53 UTC (rev 3155) +++ trunk/jython/src/templates/str.expose 2007-04-17 06:35:13 UTC (rev 3156) @@ -22,7 +22,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? Modified: trunk/jython/src/templates/unicode.expose =================================================================== --- trunk/jython/src/templates/unicode.expose 2007-04-17 05:41:53 UTC (rev 3155) +++ trunk/jython/src/templates/unicode.expose 2007-04-17 06:35:13 UTC (rev 3156) @@ -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? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |