[mod_python] mod_python / memcahced for on-the-fly renderingoflatex in html

Graham Dumpleton grahamd at dscpl.com.au
Mon Apr 10 06:01:43 EDT 2006

On 10/04/2006, at 4:54 PM, Jay wrote:

> One quick question about content-length...
> On Sun, Apr 09, 2006 at 09:14:53PM -0400, Graham Dumpleton wrote:
>> Graham Dumpleton wrote ..
>>> 	<Location /your/directory>
>>> 		PythonPath ['/var/www/python/htmlatex']+sys.path
>>> 		PythonDebug Off
>>> 		PythonOutputFilter htmlatex HTMLATEX
>>> 		AddOutputFilter HTMLATEX;CONTENT_LENGTH .htmlx
>>> 	</Location>
>>> and you will get correct amended content length header added back  
>>> in.
>>> This works because you buffer up data and write it in one go.  
>>> Thus the
>>> CONTENT_LENGTH output filter is able to recalculate content length
>>> for you.
>> Using the "CONTENT_LENGTH" output filter should work though.
> OK, CONTENT_LENGTH works great for htmlx files.  Now what I'd like  
> to do
> is just have the output filter handle all html files by doing
> 	AddOutputFilter HTMLATEX;CONTENT_LENGTH .html
> It works peachy keen for html files that, hah, contain equations.
> Normal HTML files provide erratic content-length headers and stall
> the browser out.  My first thought was to store the original content
> length and if a filter.req didn't have any equations, to restore it
> manually.  Then I remembered the "well, we tried it and it didn't  
> work"
> comments from the debianUK site.  (I'll stil give it a whirl later,
> though).

I don't quite understand why req.set_content_length() wouldn't work as
long as it is called before the first call of filter.write(). After  
all, the
CONTENT_LENGTH filter works by doing the same thing. I would
highly recommend though that you upgrade to mod_python 3.2.8
if you are still using 3.1.2 as mentioned in your README.

I would be interested to hear what happens when you log to the Apache
log file the content length before calling main() and compare that to
that produced by CONTENT_LENGTH filter for same file.

If there are no embedded equations and it comes up with different
values, then something is definitely amiss.

Don't forget though that your code has:

     if not equations:
         output = StringIO(soup.prettify())
         output = output.getvalue()
         return output.strip()

That is, when no equations you are stripping white space from ends, so
make sure you take length at correct point.

> Any suggestions?  Does the *order* of the AddOutputFilter arguments  
> make
> a difference?  Is HTMLATEX;CONTENT_LENGTH different from
> CONTENT_LENGTH;HTMLATEX? (My guess is that it is different, but one  
> can
> never tell).

Yes, order is very important. Data will pass through filters in order  

Please let us know what you work out.


More information about the Mod_python mailing list