[Zope] external method strangeness
garry saddington
garry at schoolteachers.co.uk
Thu Oct 19 02:50:17 EDT 2006
On Wed, 2006-10-18 at 15:07 -0400, Paul Winkler wrote:
> 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.
There is no chance of this as it is a one-off populate the db exercise.
> 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)
Thank you I've never heard of this, I'll give it a try. I was using
4suite but it started to misbehave in the way that I wanted to use it.
regards
Garry
>
> but again, this doesn't address your immediate problem :)
>
More information about the Zope
mailing list