PSP currently converts expression blocks like <%=1234%> into servlet code
like this:

        res.write(str(1234))

It would be convenient to be able to use a custom function instead of "str".
For example, if I wanted all integers to be formatted like "1,234" I could
do that in a custom function.

There are a few ways to do this.  One way is to have PSP use some predefined
method call instead of str():

        res.write(self.htForValue(1234))

and in the base class provide:

        def htForValue(self, value):
                return str(value)

as a default implementation.  You could override it in the PSP itself using
a method directive, or in your own base class.  (Any other suggestions for
the name of the method?)

Another thought is a special PSP directive that lets you specify the string
conversion function or method (which would still default to str()):

        <%@ page formatter="self.htForValue" %>

And a third thought is that you don't actually need to do _anything_ to PSP
to get this to work.  All you need to do is assign to str at the top of your
PSP:

        <%str = self.htForValue%>

but that seems a bit too sneaky and could break if PSP's implementation
changed to not use str() in the future.

Thoughts?


- Geoff

_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to