--- src/org/python/modules/_codecs.java Sat Aug 11 11:47:13 MSD 2007 +++ src/org/python/modules/_codecs.java Sat Aug 11 11:47:13 MSD 2007 @@ -44,6 +44,13 @@ }); } + private static PyTuple decode_tuple_ascii(String s, int len) { + return new PyTuple(new PyObject[] { + new PyString(s), + Py.newInteger(len) + }); + } + private static PyTuple encode_tuple(String s, int len) { return new PyTuple(new PyObject[] { Py.java2py(s), @@ -100,7 +107,7 @@ } public static PyTuple escape_decode(String str, String errors) { - return decode_tuple(PyString.decode_UnicodeEscape(str, + return decode_tuple_ascii(PyString.decode_UnicodeEscape(str, 0, str.length(), errors, --- src/org/python/core/codecs.java Sat Aug 11 11:47:14 MSD 2007 +++ src/org/python/core/codecs.java Sat Aug 11 11:47:14 MSD 2007 @@ -130,7 +130,7 @@ - public static String decode(PyString v, String encoding, + public static PyObject decode(PyString v, String encoding, String errors) { if (encoding == null) { @@ -145,8 +145,8 @@ /* Shortcut for ascii encoding */ if (encoding.equals("ascii")) { - return PyUnicode_DecodeASCII(v.toString(), - v.__len__(), errors); + return new PyUnicode(PyUnicode_DecodeASCII(v.toString(), + v.__len__(), errors)); } /* Decode via the codec registry */ @@ -162,7 +162,7 @@ throw Py.TypeError("decoder must return a tuple " + "(object,integer)"); } - return result.__getitem__(0).toString(); + return result.__getitem__(0); } --- src/templates/unicode.expose Sat Aug 11 11:47:15 MSD 2007 +++ src/templates/unicode.expose Sat Aug 11 11:47:15 MSD 2007 @@ -20,7 +20,7 @@ expose_meth: :u capitalize expose_meth: :u center i expose_meth: :i count s i? i? -expose_meth: :u decode s? s? +expose_meth: decode s? s? expose_meth: :s encode s? s? expose_meth: :b endswith s i? i? expose_meth: :u expandtabs i? --- src/org/python/core/PyUnicode.java Sat Aug 11 11:47:16 MSD 2007 +++ src/org/python/core/PyUnicode.java Sat Aug 11 11:47:16 MSD 2007 @@ -360,7 +360,7 @@ public PyObject __call__(PyObject arg0,PyObject arg1) { try { - return new PyUnicode(((PyUnicode)self).unicode_decode(arg0.asString(0),arg1.asString(1))); + return((PyUnicode)self).unicode_decode(arg0.asString(0),arg1.asString(1)); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -377,7 +377,7 @@ public PyObject __call__(PyObject arg0) { try { - return new PyUnicode(((PyUnicode)self).unicode_decode(arg0.asString(0))); + return((PyUnicode)self).unicode_decode(arg0.asString(0)); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -392,7 +392,7 @@ } public PyObject __call__() { - return new PyUnicode(((PyUnicode)self).unicode_decode()); + return((PyUnicode)self).unicode_decode(); } } @@ -1482,7 +1482,7 @@ return new PyUnicode( (String)S.__tojava__(String.class) ); } if (S instanceof PyString) { - return new PyUnicode(codecs.decode((PyString)S, encoding, errors)); + return new PyUnicode(codecs.decode((PyString)S, encoding, errors).toString()); } return S.__unicode__(); } else { @@ -1815,15 +1815,15 @@ return str_encode(encoding, errors); } - final String unicode_decode() { + final PyObject unicode_decode() { return str_decode(); } - final String unicode_decode(String encoding) { + final PyObject unicode_decode(String encoding) { return str_decode(encoding); } - final String unicode_decode(String encoding, String errors) { + final PyObject unicode_decode(String encoding, String errors) { return str_decode(encoding, errors); } --- src/org/python/core/PyString.java Sat Aug 11 11:47:17 MSD 2007 +++ src/org/python/core/PyString.java Sat Aug 11 11:47:17 MSD 2007 @@ -449,7 +449,7 @@ public PyObject __call__(PyObject arg0,PyObject arg1) { try { - return new PyUnicode(((PyString)self).str_decode(arg0.asString(0),arg1.asString(1))); + return((PyString)self).str_decode(arg0.asString(0),arg1.asString(1)); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -466,7 +466,7 @@ public PyObject __call__(PyObject arg0) { try { - return new PyUnicode(((PyString)self).str_decode(arg0.asString(0))); + return((PyString)self).str_decode(arg0.asString(0)); } catch (PyObject.ConversionException e) { String msg; switch (e.index) { @@ -481,7 +481,7 @@ } public PyObject __call__() { - return new PyUnicode(((PyString)self).str_decode()); + return((PyString)self).str_decode(); } } @@ -3571,27 +3571,27 @@ return codecs.encode(this, encoding, errors); } - public String decode() { + public PyObject decode() { return str_decode(); } - final String str_decode() { + final PyObject str_decode() { return str_decode(null, null); // xxx } - public String decode(String encoding) { + public PyObject decode(String encoding) { return str_decode(encoding); } - final String str_decode(String encoding) { + final PyObject str_decode(String encoding) { return str_decode(encoding, null); } - public String decode(String encoding, String errors) { + public PyObject decode(String encoding, String errors) { return str_decode(encoding, errors); } - final String str_decode(String encoding, String errors) { + final PyObject str_decode(String encoding, String errors) { return codecs.decode(this, encoding, errors); } --- src/templates/str.expose Sat Aug 11 11:47:18 MSD 2007 +++ src/templates/str.expose Sat Aug 11 11:47:18 MSD 2007 @@ -21,7 +21,7 @@ expose_meth: :s capitalize expose_meth: :s center i expose_meth: :i count s i? i? -expose_meth: :u decode s? s? +expose_meth: decode s? s? expose_meth: :s encode s? s? expose_meth: :b endswith s i? i? expose_meth: :s expandtabs i?