[mod_python] changing publisher `content' before sent to client

Jaime Wyant programmer.py at gmail.com
Tue Jan 16 12:56:24 EST 2007

Actually, I need to perform string manipulation on *everything* that gets
handled by publisher.  I don't want to manually edit each function that the
handler exposes.

FWIW, I'm doing this because I would like to have two versions of my website


These sites are identical, except for the domain name well and the database
they use.

But the problem is, I decided to do this a bit late in the game.  And I
didn't have enough foresight *not to* hardcode real.mysite.com.  So I have
real.mysite.com sprinkled throughout various python modules.  Yeah the right
thing to do would be to `fix' everything site wide, but i'm in a pinch (and
lazy :p), so I simply want to change all instances of real.mysite.com to


On 1/16/07, Jorey Bump <list at joreybump.com> wrote:
> Jaime Wyant wrote:
> > Hi all.  I was not sure of a good subject, but I think this is close.
> > Here is what I want to do:
> >
> > * Use publisher handler.
> > * "Grab" data before it is sent to the client, perform some `string
> > substitution' , send modified string / data onto the client.
> >
> > I made a copy of publisher.py and now use a modified version which
> > performs the necessary string changes before doing req.write.  But, I
> > can't help but think that there is a cleaner way to do this.  Is there a
> > `better' way?
> Ordinary python string replacement is available in the returned result:
> def index()
>      body = """
> <html>
> <head>
> <title>%s</title>
> </head>
> <body>
> %s
> </body>
> </html>
> """
>      title = "This is the Title"
>      content = "<p>This is the content</p>"
>      return body % (title, content)
> Or did you have something else in mind?

"Government does not solve problems; it subsidizes them."
Ronald Reagan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20070116/8ac3d2fb/attachment.html

More information about the Mod_python mailing list