[Zope] HTML post processing in Zope
Jaroslav Lukesh
lukesh at seznam.cz
Tue May 24 12:57:35 EDT 2005
Dne čtvrtek, 5. května 2005 04:58 Cyrille Bonnet <cyrille at 3months.com> napsal(a):
> Hi all,
>
> I am trying to perform a post-processing on all HTTP responses, before
> they get sent to the browsers. I am using Zope 2.7.3 nad Plone 2.0.5.
>
> I had a look at the ZServer class: it seems to be the right place, but I
> don't understand all the code there and I am afraid to break something :-(
>
> Am I on the right tracks there? Could someone with great Zope knowledge
> be kind enough to point out which method I should change? (I want to
> change the HTML content, not the headers).
I have unitws product (from somebody else) which does modifications
on the resulted html code. It is able to do any
modifications, I was modify them to do wml compliant
national characters and more.
You call it simple with
<dtml-unitws>
your content here
</dtml-unitws>
Place this file __init__.py into "unitws" folder of your Products:
# cat /var/zope/lib/python/Products/unitws/__init__.py
from string import split, strip, join, find
import DocumentTemplate.DT_Util
from DocumentTemplate.DT_String import String
class UnitWhitespaceTag:
"""
Removes redundant whitespace (not very conservatively)
"""
name='unitws'
blockContinuations=()
def __init__(self, blocks):
tname, args, section = blocks[0]
args = DocumentTemplate.DT_Util.parse_params(args)
self.blocks = section.blocks
def render(self,md):
a = []
for line in split(DocumentTemplate.DT_Util.render_blocks(self.blocks, md),'\n'):
line = strip(line)
if line:
b = []
for word in split(line,' '):
if word!='':
b.append(strip(word))
a.append(join(b,' '))
return join(a,'\n')
__call__=render
String.commands['unitws']=UnitWhitespaceTag
--
Jaroslav Lukesh
-----------------------------------------------------------
This e-mail can not contain any viruses because I use Linux
More information about the Zope
mailing list