diff -r a933f6ad00f6 jython/src/org/python/core/PyString.java --- a/jython/src/org/python/core/PyString.java Thu Sep 20 19:23:50 2007 -0400 +++ b/jython/src/org/python/core/PyString.java Fri Sep 21 21:12:52 2007 -0400 @@ -3655,6 +3655,7 @@ final class StringFormatter int precision; int argIndex; PyObject args; + boolean unicodeCoercion; final char pop() { try { @@ -3673,8 +3675,13 @@ final class StringFormatter } public StringFormatter(String format) { + this(format, false); + } + + public StringFormatter(String format, boolean unicodeCoercion) { index = 0; this.format = format; + this.unicodeCoercion = unicodeCoercion; buffer = new StringBuffer(format.length()+100); } @@ -3977,7 +3985,10 @@ final class StringFormatter case 'r': fill = ' '; if (c == 's') - string = arg.__str__().toString(); + if (unicodeCoercion) + string = arg.__unicode__().toString(); + else + string = arg.__str__().toString(); else string = arg.__repr__().toString(); if (precision >= 0 && string.length() > precision) { diff -r a933f6ad00f6 jython/src/org/python/core/PyUnicode.java --- a/jython/src/org/python/core/PyUnicode.java Thu Sep 20 19:23:50 2007 -0400 +++ b/jython/src/org/python/core/PyUnicode.java Fri Sep 21 21:12:52 2007 -0400 @@ -110,6 +110,25 @@ public class PyUnicode extends PyString } dict.__setitem__("__rmul__",new PyMethodDescr("__rmul__",PyUnicode.class,1,1,new exposed___rmul__(null,null))); + class exposed___mod__ extends PyBuiltinMethodNarrow { + + exposed___mod__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___mod__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyUnicode)self).unicode___mod__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__mod__",new PyMethodDescr("__mod__",PyUnicode.class,1,1,new exposed___mod__(null,null))); class exposed___getitem__ extends PyBuiltinMethodNarrow { exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { @@ -1514,8 +1533,13 @@ public class PyUnicode extends PyString return new PyUnicode(str); } - public PyObject __mod__(PyObject other) { - return str___mod__(other).__unicode__(); + public PyUnicode __mod__(PyObject other) { + return unicode___mod__(other).__unicode__(); + } + + public PyObject unicode___mod__(PyObject other){ + StringFormatter fmt = new StringFormatter(string, true); + return fmt.format(other); } final PyUnicode unicode___unicode__() { diff -r a933f6ad00f6 jython/src/templates/unicode.expose --- a/jython/src/templates/unicode.expose Thu Sep 20 19:23:50 2007 -0400 +++ b/jython/src/templates/unicode.expose Fri Sep 21 21:12:52 2007 -0400 @@ -5,7 +5,7 @@ expose_index_getitem: seq_> expose_index_getitem: seq_> expose_meth: seq_> __getslice__ ooo? # -expose_binary: __ne__ __eq__ __add__ __mul__ __rmul__ +expose_binary: __ne__ __eq__ __add__ __mul__ __rmul__ __mod__ expose_meth: :b __contains__ o expose_meth: :i __len__ expose_meth: __str__