quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gregory (Grisha) Trubetskoy" <gri...@apache.org>
Subject Re: [mod_python] Filter chaining bug
Date Tue, 17 Sep 2002 03:47:23 GMT

OK, I figured out the context-length issue now too. In order to make it
work, you need to get the latest from CVS, and edit your filter to look
like this (### indicates new/change):

from mod_python import apache

def outputfilter(filter):
    filter.write("---BEGIN---\n")
    count = 1
    while 1:
        line = filter.readline()
        if not line:
            break
        filter.write("%d: %s" % (count, line))
        count += 1
    filter.write("---END---\n")

    if line is None:     ###
        filter.close()   ###

    return apache.OK     ###

The idea is that a filter needs to watch out for an EOS bucket. A read
operation will return None to indicate an EOS (in all other cases it
returns an empty string). At this point you must close() the filter.
(close() simply appends an EOS)

Grisha

On Mon, 16 Sep 2002, Gregory (Grisha) Trubetskoy wrote:

>
> [Moved this from mod_python to python-dev - for those of you reading this
> out of context - this is a mod_include tag (stuff about spain) passing
> output to a python filter which adds BEGIN, END and linecount.]
>
> I think I got this one fixed, for the most part. There was a problem with
> thread locks that made it freeze and some other stuff. However, when you
> do include->python filter chain, you get this:
>
> Date: Mon, 16 Sep 2002 22:32:35 GMT
> Server: Apache/2.0.40 (Unix) mod_python/3.0.0-BETA Python/2.2.1
> Accept-Ranges: bytes
> content-length: 22
> Keep-Alive: timeout=15, max=100
> Connection: Keep-Alive
> Content-Type: text/plain
>
> ---BEGIN---
> ---END---
> ---BEGIN---
> 1: The rain in Spain
> 2: falls mainly
> 3: on the plain.
> ---END---
> ---BEGIN---
> 1:
> ---END---
>
> (Obviously, the Content-length is broken, that's why I said "for the most
> part")
>
> But it illustrates an interesting point about filters - they have no way
> of knowing when they're called. Mod_include apparently passes a bucket
> with everything prior to a tag, then the output of tag itself, then
> everything after. So you get three invocations of the filter.
>
> P.S. Also, there was a bug in the filter code - it MUST return a status
> code, e.g. apache.OK.
>
> Grisha
>
> On Thu, 12 Sep 2002, Gary Benson wrote:
>
> > Hi,
> >
> > I've been playing around with chaining PythonOutputFilters and run into
> > a dead end.  It seems that mod_python can be the first filter in a chain
> > quite nicely but it can't be a subsequent filter and it's not obvious
> > why (to me, anyway).
> >
> > The attached tarball contains a fragment of httpd.conf that sets up
> > filters from mod_python and mod_include in some directory.  Everything
> > works except
> >
> >   data.flt.flt -- two mod_python filters chained, the second segfaults
> >   data.shtml.flt -- mod_include outputting into mod_python, mod_python
> >     segfaults
> >
> > Is anyone else is able to reproduce this and/or does anyone know what is
> > wrong here?
> >
> > Cheers,
> > Gary
> >
> > [ gbenson@redhat.com ][ GnuPG 85A8F78B ][ http://inauspicious.org/ ]
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python@modpython.org
> > http://www.modpython.org/mailman/listinfo/mod_python
> >
>


Mime
View raw message