Re: 2.2 equivalents for transform.expr() and transform.dynamic()?
Philip Semanchuk <[email protected]> Mon, 9 Apr 2007 13:18:24 -0400
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
On Apr 9, 2007, at 12:27 AM, Jonathan Ellis wrote:
> That part of transform is now in the response module. Something like
> this:
>
> [[\
> class MyOut:
> def __init__(self, out):
> self.out = out
> self.writeStatic = out.write
> self.writeExpr = self.write
> def write(self, s):
> self.out.write(Utf8ify(ReplaceHtmlSpecials(s))
>
> response.addFilter(MyOut)
> ]]
>
> Each response filter is passed the stream of the next-lowest filter
> ("out"). At the bottom is a spyceUtil.BufferedOutput.
Thanks. I looked through the response module and I can see how this
works now that you've pointed me to it. I found that I had to add a
dummy flush() method to my class, too, so I ended up with something
like this:
[[\
class MyOut:
def __init__(self, out):
self.out = out
self.writeStatic = out.write
self.writeExpr = self.write
def write(self, s):
self.out.write(Utf8ify(ReplaceHtmlSpecials(s)))
def flush(self):
pass
response.addFilter(MyOut)
]]
However this isn't the equivalent of what I'm doing with the transform
module. The filter above transforms *all* output whereas I only want to
run my functions on dynamic output. I use this in a singleton tag
called ScrubOutput included once near the top of each page. ScrubOutput
ensures that all dynamically generated output is (a) utf-8 encoded and
(b) has its HTML tags converted to entities without altering the static
output. For instance, I would write some Spyce code like this:
<MyTagLib:ScrubOutput />
<p>[[="enter a value i where 0 < i < 42"]]</p>
The function ReplaceHtmlSpecials() in ScrubOutput would ensure that
this would render as:
<p>enter a value i where 0 < i > 42</p>
But simply adding a filter to the response object transforms all
output, so that the paragraph above renders like so:
<p>enter a value i where 0 < i > 42</p>
Not what I was looking for. :-/ Having looked through response.py, I
don't see a way for a filter to implement the kind of granularity that
the transform module offered. I hope I'm overlooking something obvious!
=) Or perhaps there's another way to do what I'm after.
Thanks for all of your help and work on Spyce
Philip
>
> On Sun, 8 Apr 2007 20:02:55 -0400, "Philip Semanchuk"
> <[email protected]> said:
>> Hi Jonathan,
>> In my current 2.0 install I have a taglib that defines functions
>> called
>> Utf8ify() and ReplaceHtmlSpecials() and then passes them to the
>> transform module like so:
>>
>> transform.expr((Utf8ify, ReplaceHtmlSpecials))
>> transform.dynamic((Utf8ify, ReplaceHtmlSpecials))
>>
>>
>> What's the 2.2 equivalent? I've tried this but the functions don't
>> seem
>> to get called, although I don't get an error either:
>>
>> text.expr((Utf8ify, ReplaceHtmlSpecials))
>> text.dynamic((Utf8ify, ReplaceHtmlSpecials))
>>
>>
>> Thanks
>> Philip
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV