[Zope] external method strangeness
garry saddington
garry at schoolteachers.co.uk
Wed Oct 18 13:13:38 EDT 2006
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)
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/')
r.wait()
transformed = r.stdout.read()
transformed1=transformed.replace(',)',')')
conn = psycopg.connect("dbname=scholarpack user=scholarpack")
curs = conn.cursor()
do=curs.execute(transformed1)
do
conn.commit()
conn.close
I get a programming error thrown from the conn.commit() line and the
method fails. However when I run the following script externally to Zope
after the Zope failure (so that source.xml exists) the DB write is
successful.
#!/opt/scholarpack/python/bin/python
import psycopg, string, re, subprocess
source='source.xml'
style='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/')
r.wait()
transformed = r.stdout.read()
transformed1=transformed.replace(',)',')')
conn = psycopg.connect("dbname=scholarpack user=scholarpack")
curs = conn.cursor()
do=curs.execute(transformed1)
do
conn.commit()
conn.close
Can anyone point me in the correct direction?
regards
garry
More information about the Zope
mailing list