[mod_python] mod_python with 4Suite tools

Heikki Halonen heha at iki.fi
Tue Dec 3 16:13:00 EST 2002


I'm having hard time trying to make 4Suite tools co-operate with
mod_python (or vice versa). I'm using Python 2.2.2, Apache 2.0.43,
mod_python 3.0.1 and newest 4Suite development version. My system is
Debian unstable. python2.2-xml package is not installed.

The test program is in the end of this mail, the xml files used can be
found at http://www.heha.iki.fi/~heha/poll_dev/quiz2html.xsl and
http://www.heha.iki.fi/~heha/poll_dev/polls/quiz_1.xml. Test program works
perfectly when run from the command line. When requested by mod_python,
however, it 'obfuscates' the XML document. Characters used in marking
print out fine but everything else is some random binary data. I figured
out that it probably has something to do with encoding and added the
following lines to sitecustomize.py, as somebody advised in some distantly
similar problem:

u'hello'.encode( 'UTF-8' )
u'hello'.encode( 'iso8859-1' )

This did not help, whatsoever. I have no clue anymore where the problem
could be or how it could be corrected. Any suggestions? The same kind of
code works fine in mod_python 2.7.8 running in Apache 1.3.26 with Python
2.1 and 4Suite version 0.11.1.


import sys, os, string

from Ft.Lib import Uri
from Ft.Xml.Xslt import XmlWriter, Processor, OutputParameters
from Ft.Xml import Domlette, InputSource

def processXML():
    mypath = '/home/heha/public_html/poll_dev/'
    pollfile = mypath+'polls/quiz_1.xml'
    pollxsl = mypath+'quiz2html.xsl'

    debugfile = open( mypath+'poll.log', 'w' )
    processor = Processor.Processor()
    node = Domlette.NonvalidatingReader.parseUri( pollfile )
    Domlette.Print( node, debugfile, encoding='iso8859-1' )
    stylesheet = InputSource.DefaultFactory.fromUri( pollxsl )
    processor.appendStylesheet( stylesheet )

    processed_node = processor.runNode( node, Uri.OsPathToUri(
        pollfile, 1) )

    debugfile.write( processed_node )

    return processed_node

    #print writer.getResult()

if __name__ == "__main__":
    print processXML()
    from mod_python import apache

    def handler( req ):
        req.write( processXML() )
        return apache.OK

     Heikki Halonen # heha at iki.fi # iki.fi/heha # +358 40 828 9972
            "The easy way ain't hard enough and the hard way
                     is such a lonely lonely path"

More information about the Mod_python mailing list