I like this idea in general.

I don't like reassigning the str function.

So I guess the best approach is one of the other two.  The key here is not
to slow things down.  This function is called ALOT, and can have a dramatic
effect on performance.  I want to avoid adding any extra overhead.  I guess
calling str() invloves one dictionary lookup.  Keep this in mind as you
ponder the best way to do this.  We don't want to go too far in this
direction.  The default should add no (or almost no) additional overhead.
The user should know that if they choose to customize this, it might slow
things down.

As far as which approach is best, out of the two options you proposed, I
think they would both work the same way.  If we add a directive, it would
just do some assignment in the __init__ method anyway.

Jay

> -----Original Message-----
> From: Geoffrey Talvola [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 13, 2002 11:12 AM
> To: Webware_Devel (E-mail)
> Subject: [Webware-devel] Hook in PSP for converting to string?
> 
> 
> 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
> 


----------------------------------------------------------------------------

This e-mail and any attachments may be confidential or legally privileged.
If you received this message in error or are not the intended recipient, you
should destroy the e-mail message and any attachments or copies, and you are
prohibited from retaining, distributing, disclosing or using any information
contained herein.  Please inform us of the erroneous delivery by return
e-mail. 

Thank you for your cooperation.

----------------------------------------------------------------------------



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

Reply via email to