[Zope] external method strangeness

Paul Winkler pw_lists at slinkp.com
Wed Oct 18 15:07:22 EDT 2006

On Wed, Oct 18, 2006 at 06:13:38PM +0100, garry saddington wrote:
> Can anyone explain what is happening here. I am using Saxon to transform
> an xml file(source) using a stylesheet(style) the result is then written
> to Postgres. The contents of source are uploaded in Zope and passed to
> the external method as a string. When I run this external method:
> import psycopg, string, re, subprocess
> def scholarpack_xml_transform(source):
>     f=open('/opt/scholarpack/ancillary/source.xml','w')
>     f.write(source) 

I have no idea what's causing your problem, but this raises
red flags for me: if two people upload sources at the same time,
you'll have problems here. If you really really must read/write
files on the filesystem, either use locks or use python's
tempfile module.

>     f.close
>     source= '/opt/scholarpack/ancillary/source.xml'
>     style='/opt/scholarpack/ancillary/style.xml'
>     source1=source.replace(''','`')
>     source2=source1.replace('NLPGaddress','BS7666address')
>     p=re.compile("\'")
>     source3=p.sub( '`' , source2)
>     r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/')

Are you just using saxon for xslt processing?  If so, IMO using an
external process for that is severe overkill.  Get lxml and try
something like this:

    from lxml import etree
    style = etree.XSLT(etree.parse(some_file_object))
    transformed = style.apply(source_data)

but again, this doesn't address your immediate problem :)


Paul Winkler

More information about the Zope mailing list