[mod_python] Re: [4suite] 4Suite Reliance on ENVIRONMENT & global variables

Mongryong Mongryong at sympatico.ca
Tue Jan 21 20:48:59 EST 2003


Ok, here's an update.  I've tested things out with a variety of
environment scenarios:

Computer - RedHat 8, PIII, 256mb, > 60Gb

Scenario#1 - Works fine
Apache httpd Server 1.3.27
Python 2.2.2
mod_python 2.7.8
4Suite 0.11.1
PyXML 0.6.6

Scenario#2 - Works fine
Apache httpd Server 2.0.44
Python 2.2.2
mod_python 3.0.2 (CVS)
4Suite 0.11.1
PyXML 0.6.6

Scenario#3 - Fails (encoding problem??)
Apache httpd Server 1.3.27
Python 2.2.2
mod_python 2.7.8
4Suite 0.12a CVS latest
PyXML 0.8.x

Scenario#4 - Fails (encoding problem??)
Apache httpd Server 2.0.44
Python 2.2.2
mod_python 3.0.2 (CVS)
4Suite 0.12a CVS latest
PyXML 0.8.x

Scenario#5 - Fails (encoding problem??)
Apache httpd Server 2.1.0 CVS latest
Python 2.2.2
mod_python 3.0.2 CVS latest
4Suite 0.12a CVS latest
PyXML 0.8.x

Scenario#5 - Fails (encoding problem??)
Apache httpd Server 2.1.0 CVS latest
Python 2.3a CVS latest
mod_python 3.0.2 (CVS)
4Suite 0.12a CVS latest
PyXML 0.8.x

Summary of combinations that produced no 'encoding' problem:
Apache 1.3.27 to 2.1 CVS latest
mod_python 3.0.2 CVS latest
Python 2.2.2  
4Suite 0.11.1 
PyXML 0.6.6

To me, the encoding problem appears to have something to do with 4Suite
0.12.x or PyXML 0.8.x or a combination of the two.  

It would be nice to be able to test if the encoding problem appears in
another 'embedded python' app or module.  This would help strengthen the
case against 4Suite/PyXml.  My guess is that the encoding problem is not
unique to mod_python.

On Tue, 2003-01-21 at 01:19, Mongryong wrote:
> Ok, I've modified my simple test script so that it can be easily started
> from a shell (python main.py) as well as working with mod_python.
> 
> Again, here's the url to my server where you can view the mod_python
> result: http://rezquest.cjb.net/bin/main
> 
> So, now the test outputs the XML source as just a string and as dom node
> from NonvalidatingReader.
> 
> You should clearly see the difference between the standalone and
> mod_python results.
> 
> On Tue, 2003-01-21 at 00:23, Michael Olson wrote:
> > 
> > > The strange thing is that if I directly output the XML source without
> > > doing any XSLT processing, the XML source appears correctly.  Somewhere
> > > along the line where the strings are being passed from the python
> > > libraries to the 4Suite libraries (by Py_ParseArgs..???), the strings
> > > are being 'miscommunicated'.
> > >
> > 
> > By "output the XML source" do you mean just print it out (or fetch it 
> > from the file system) ro do you mean parse it into DOM, and print it 
> > out?
> > 
> > If not the later, can you try that instead of XSLT to see if this works.
> > 
> > Thanks
> > Mike
> > 
> > > Now, it might be a Python2.2.2 issue since libxml2/libxslt from the
> > > gnome project are having similar problems as well.
> > >
> > > In 4Suite, do the apps embedd the python interpretor or do the apps
> > > start purely from a python environment?
> > >
> > > It might be good to check to see whether this problem still occurs 
> > > other
> > > 'python embedded' application (ie. uses Py_NewInterpretor from C). I
> > > forget, does the command-line version of python dynamically link to the
> > > python libraries?  If so, I wonder if the command-line version of 
> > > python
> > > is doing anything special or different when it links up and initializes
> > > the python libraries.
> > >
> > > I'm reposting this message on to the Python mailing list to see if
> > > anybody there can help give us a clue.
> > >
> > > P.S Has there been any changes in Python2.2.3+ that might possibly fix
> > > this problem?
> > >
> > > On Mon, 2003-01-20 at 22:28, Uche Ogbuji wrote:
> > >> On Mon, 2003-01-20 at 14:52, Mongryong wrote:
> > >>> Hi,
> > >>>
> > >>> I'm having trouble getting the latest 4Suite XML/XSLT tools to work 
> > >>> the
> > >>> way I want in mod_python and I know I'm not the first one to 
> > >>> experience
> > >>> "out-of-the-box" success.
> > >>>
> > >>> I've determined that it's an encoding issue.   Now, with a 
> > >>> stand-alone
> > >>> script or CGI script under Apache, 4XSLT works fine.  But under
> > >>> mod_python (which doesn't have access to ENVIRONMENT variables), 
> > >>> 4XSLT
> > >>> library decodes the XML source file in a total different encoding.  
> > >>> XSL
> > >>> templates (ie. <xsl:template name="blah">) are never executed because
> > >>> the XML tag is never recognized by the XSL processor.  Hence, you 
> > >>> get an
> > >>> empty output.
> > >>>
> > >>> I've check the default system encoding codec and it returns 'ascii' 
> > >>> (ie.
> > >>> sys.getdefaultencoding).  Now, it could be that the python library
> > >>> relies on some ENVIRONMENT variable for its configuration.
> > >>>
> > >>> Anybody have any ideas what 'parameters' might not be initialized
> > >>> properly under a non-CGI or non-shell environment such as mod_python?
> > >>> Or, is there a parameter that one can set to change the XML input
> > >>> decoding?
> > >>
> > >> I don't think there is any environment variable that could affect 
> > >> this.
> > >>
> > >> However, there have been a lot of fixes recently, including to some
> > >> endianness bugs.  Do you mind trying again with latest 4Suite CVS and
> > >> telling us if it helps?  Either wait till tomorrow's snapshot, or 
> > >> check
> > >> out current CVS HEAD directly
> > >>
> > >> http://4suite.org/docs/4SuiteCVS.xml
> > >>
> > >> If it doesn't help, I hope you'll be able to help us work with you to
> > >> find a solution for mod_python users.
> > >>
> > >> -- 
> > >> Uche Ogbuji                                    Fourthought, Inc.
> > >> http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
> > >> Python Generators + DOM - 
> > >> http://www.xml.com/pub/a/2003/01/08/py-xml.html
> > >> 4Suite Repository Features - 
> > >> https://www6.software.ibm.com/reg/devworks/dw-x4suite5-i/
> > >> XML class warfare - http://www.adtmag.com/article.asp?id=6965
> > >> MusicBrainz  metadata - 
> > >> http://www-106.ibm.com/developerworks/xml/library/x-think14.html
> > >>
> > >
> > > <main.py>
> > Mike Olson                                Principal Consultant
> > mike.olson at fourthought.com                +1 303 583 9900 x 102
> > Fourthought, Inc.                         http://Fourthought.com
> > PO Box 270590,                            http://4Suite.org
> > Louisville, CO 80027-5009, USA
> > XML strategy, XML tools, knowledge management
> > 
> > _______________________________________________
> > 4suite mailing list
> > 4suite at lists.fourthought.com
> > http://lists.fourthought.com/mailman/listinfo/4suite
> 
> ----
> 

> #!/usr/local/bin/python
> 
> import sys
> import locale
> 
> #The identity transform: duplicates the input to output
> TRANSFORM = """<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> <xsl:template match="@*|node()">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()"/>
>   </xsl:copy>
> </xsl:template>
> 
> </xsl:stylesheet>
> """
> 
> SOURCE = """<spam id="eggs">I don't like spam</spam>"""
> 
> #The processor class is the core of the XSLT API
> import Ft
> from Ft.Xml.Xslt import Processor
> from Ft.Xml import InputSource
> 
> from xml.dom import Node
> from Ft.Xml.Domlette import Print, PrettyPrint
> from Ft.Xml.Domlette import NonvalidatingReader
> 
> #from mod_python import apache
> 
> from StringIO import StringIO
> 
> def test(req):
>     # TEST 1
>     req.write ( "Here's the result of just printing the string SOURCE\n" )
>     req.write ( SOURCE )
>     req.write ( "\n\n" )
> 
>     # TEST 2
>     buf = StringIO()
>     transform = InputSource.DefaultFactory.fromString(TRANSFORM, "http://spam.com/identity.xslt")
>     source = InputSource.DefaultFactory.fromString(SOURCE, "http://spam.com/doc.xml")
>     dom = NonvalidatingReader.parse ( source )   
> 
>     PrettyPrint (dom, buf)
>     
>     req.write ( "Here's the result of printing from the SOURCE dom tree (Domlette)\n" )
>     req.write ( buf.getvalue() )
>     req.write ( "\n\n" )
> 
>     buf.close ()
> 
>     # TEST 3
>     req.write("Here's the result of the XSLT processing\n")
>     processor = Processor.Processor()
>     processor.appendStylesheet(transform)
>     result = processor.runNode(dom, "http://spam.com/doc.xml")
>     
>     req.write( result + "\n\n" )
> 
>     # LOCALE STUFF
>     req.write("Ft.DEFAULT_ENCODING = " + Ft.DEFAULT_ENCODING + "\n")
>     req.write("sys.getdefaultencoding = " + sys.getdefaultencoding() + "\n")
>     req.write("local.getdefaultlocale()[1] = " + locale.getdefaultlocale()[1] + "\n\n")
> 
> def handler(req):    
> 
>     req.content_type = "text/plain"   
>     test(req)
>     
>     return 0
> 
> 
> if __name__ == "__main__":
>     test(sys.stdout)





More information about the Mod_python mailing list