Re: [Zope] external method and forms
At last I find and change everything.Now it looks like this: --MY DTML DOCUMENT- KULLANICI ADI SIFRE SIFRE YENIDEN MY EXTERNAL PYTHON METHOD-- import crypt import MySQLdb def formParams(self,name,sifre,sifret): conn = MySQLdb.connect(host="localhost", user = "", passwd = "", db = "xxxzzz") cursor = conn.cursor() self.name=name self.sifre=sifre self.sifret=sifret if sifre == sifret: cryp = crypt.crypt(sifre,'mysecret') cursor.execute("""update mytable set PASS_WORD=%s where USERNAME=%s""",(cryp,name)) return "BASARI ILE DEGISTIRILDI" else: return "Sifreler uyusmadi.Tekrar deneyiniz." cursor=conn.close() On Mon, Jan 7, 2013 at 11:16 PM, Mike Cullerton wrote: > It looks like you missed some quotes. > > this line > cryp = crypt.crypt(sifre,'mysecret') > > should probably be > cryp = crypt.crypt('sifre','mysecret') > > Mike > > On Jan 7, 2013, at 1:33 PM, murat bilal wrote: > > Hi, > > I try to make a simple paswd recovery page for my site.Username and > password stored in mysql db.My DTML document is: > > Şifre değiştirme sayfasına hoşgeldiniz > > KULLANICI ADI: > ŞİFRE: > ŞİFRE TEKRAR: name="sifret:ignore_empty"> > > > > > and my external python method is as follows: > > import crypt > import MySQLdb > conn = MySQLdb.connect(host="localhost", >user = "r", >passwd = "", >db = "") > cursor = conn.cursor() > #return context.responseMessage() > def deg(self): > > cryp = crypt.crypt(sifre,'mysecret') > if request.form["sifre"] == request.form["sifret"]: > cursor.execute("""update mytable set PASS_WORD=%s where > USERNAME=%s""",(cryp,name)) > print "SUCCESS" > else: > print "please try again!" > cursor=conn.close() > But when i tested from DTML Document I got this error > > *Error Type: NameError* > *Error Value: global name 'sifre' is not defined* > > Can anybody help me? > > Regards > > MuratB > > > > ___ > Zope maillist - Zope@zope.org > https://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > https://mail.zope.org/mailman/listinfo/zope-announce > https://mail.zope.org/mailman/listinfo/zope-dev ) > > > ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] external method and forms
Hi, I try to make a simple paswd recovery page for my site.Username and password stored in mysql db.My DTML document is: Şifre değiştirme sayfasına hoşgeldiniz KULLANICI ADI: ŞİFRE: ŞİFRE TEKRAR: and my external python method is as follows: import crypt import MySQLdb conn = MySQLdb.connect(host="localhost", user = "r", passwd = "", db = "") cursor = conn.cursor() #return context.responseMessage() def deg(self): cryp = crypt.crypt(sifre,'mysecret') if request.form["sifre"] == request.form["sifret"]: cursor.execute("""update mytable set PASS_WORD=%s where USERNAME=%s""",(cryp,name)) print "SUCCESS" else: print "please try again!" cursor=conn.close() But when i tested from DTML Document I got this error *Error Type: NameError* *Error Value: global name 'sifre' is not defined* Can anybody help me? Regards MuratB ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Garry Saddington wrote: > Chris Withers wrote: > >> Garry Saddington wrote: >> >>> Because I want the backup to be done manually, >>> >> That doesn't seem like such a hot idea. Something that's easilly >> forgotten. >> Thanks, I've sorted it. Turns out that pg_dump was being run by SYSTEM and not by the Zope effective user as I thought. Changed the command to include -U scholarpack and all works fine. Thanks for help. Regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Chris Withers wrote: > Garry Saddington wrote: >> Because I want the backup to be done manually, > > That doesn't seem like such a hot idea. Something that's easilly > forgotten. Yes I know. It will be a utility function that will be extra to the normal cron way to back up. This works perfectly on Linux and I have found the method useful to quickly get a copy of the data to use at home off line. However, I need to get it working on windows. Regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Garry Saddington wrote: > Because I want the backup to be done manually, That doesn't seem like such a hot idea. Something that's easilly forgotten. Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Chris Withers wrote: > Garry Saddington wrote: > >> I have the following external method to back up a postgres database, >> using the following software versions. >> > > Why on earth would you not just do this in a cron job?! > > Chris > > Because I want the backup to be done manually, through the web from anywhere. Regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Garry Saddington wrote: > I have the following external method to back up a postgres database, > using the following software versions. Why on earth would you not just do this in a cron job?! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
> > > > Zope is running as user scholarpack who is an administrator on win > server 2008. > / > usar scholarpack have rights to access postgres? are you see the logs from postgres? new conecctions? or logs from zope? ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] external method
I have the following external method to back up a postgres database, using the following software versions. Zope Version (Zope 2.9.0, python 2.4.2, win32) Python Version 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] System Platform win32 Zope is running as user scholarpack who is an administrator on win server 2008. / import subprocess def backup(): try: p=subprocess.Popen("c:/scholarpack/postgres/bin/pg_dump scholarpack",shell=True,stdout=subprocess.PIPE) data=p.communicate()[0] f=open('c:/scholarpack/ancillary/scholarpack.sql','w') w=f.write(data) f.close() except OSError: print "There was a problem opening the file for writing" /When I run this through Zope I get an empty file. There are no errors reported. However, if I use the same python that is running zope in an interactive shell and run these commands then it works as expected. Can anyone spot what I am obviously missing? Regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
If you absolutely have to, look at Paramiko a python ssh/sftp library which is easy to use but as mentioned already there are critical security issues. with paramiko you don't have to directly edit the files but within an ssh connection run the commands needed that actually make the changes. You may have to put in time.sleep(x) commands to give the response time to come back, where x is an integer. Thomas On Monday 07 April 2008 03:45, vaibhav pol wrote: > hi, > > I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl > support . I wrote a Perl module which edit files the file access permission > is only to root and i want to invoking the module as onther user . by > some way i want to invoke the perl interpreter as root for my user. > and i also want to know how the zope call external method. > > please > help me!! -- Thomas McMillan Grant Bennett Appalachian State University Operations & Systems AnalystP O Box 32026 University Library Boone, North Carolina 28608 (828) 262 6587 "... using OpenOffice.org, and save them back to disk automatically, in MS Word format. They surf the Web, check e-mail, do instant messsaging, view YouTube videos, visit their Facebook pages, learn touch-typing skills and lots more. Our public library has been offering these Linux public stations for the past three years." - Phil Shapiro Linux Journal January 2008 Library Systems Help Desk: https://www.library.appstate.edu/help/ ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
On Apr 7, 2008, at 12:18 , Chris Withers wrote: Jens Vagelpohl wrote: - doing Perl methods or external methods in Zope has been deprecated years and years ago. You will have a hard time finding anyone to support that. I'm guessing you mean perl external methods rather than all external methods in general? ;-) I mean the Perl Methods and Perl External Methods that were part of the old Zope-Perl package from eons ago. jens ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
Jens Vagelpohl wrote: - doing Perl methods or external methods in Zope has been deprecated years and years ago. You will have a hard time finding anyone to support that. I'm guessing you mean perl external methods rather than all external methods in general? ;-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
On Apr 7, 2008, at 11:23 , vaibhav pol wrote: Thanks alot but i am not using command but i using perl function to modify the passwd and shadow file. in my module that's why i want to invoke that module as root There's a few things seriously wrong with your plan: - you want to create a way to manipulate a system's password/shadow files through the web by a web application. That's insane to begin with. Just don't do it. Have you ever thought about the security implications? - doing Perl methods or external methods in Zope has been deprecated years and years ago. You will have a hard time finding anyone to support that. jens ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
Thanks alot but i am not using command but i using perl function to modify the passwd and shadow file. in my module that's why i want to invoke that module as root On Mon, Apr 7, 2008 at 1:19 PM, Andreas Jung <[EMAIL PROTECTED]> wrote: > > > --On 7. April 2008 13:15:04 +0530 vaibhav pol <[EMAIL PROTECTED]> > wrote: > > hi, > > > > I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl > > support . I wrote a Perl module which edit files the file access > > permission is only to root and i want to invoking the module as onther > > user . by some way i want to invoke the perl interpreter as root for my > > user. > > and i also want to know how the zope call external method. > > > > This has also little to do with Zope. You could use 'sudo' for > starting other command within an other user context. > > -aj ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
--On 7. April 2008 13:15:04 +0530 vaibhav pol <[EMAIL PROTECTED]> wrote: hi, I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl support . I wrote a Perl module which edit files the file access permission is only to root and i want to invoking the module as onther user . by some way i want to invoke the perl interpreter as root for my user. and i also want to know how the zope call external method. This has also little to do with Zope. You could use 'sudo' for starting other command within an other user context. -aj pgpetMO2p6UEv.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method in Zope
hi, I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl support . I wrote a Perl module which edit files the file access permission is only to root and i want to invoking the module as onther user . by some way i want to invoke the perl interpreter as root for my user. and i also want to know how the zope call external method. please help me!! ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Alan wrote at 2007-2-13 13:10 +: >if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) > >where myPath should be '[Zope installation folder]/instance/import'. >So my question now is: is there a variable inside Zope which can >returns the 'import' path? Formerly, the "ExternalMethod" documentation suggested to put such modules into "/Shared//...". Nowadays (since Zope 2.7, I think), "/lib/python" is a better place (with any structure you would like to use). This folder is put on "PYTHONPATH" automatically. No need to fiddle with it (I have already searched hours for problems caused by runtime "sys.path" manipulations). -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Well, I did it: from App.config import getConfiguration extPath = getConfiguration().instancehome+'/Extensions' if sys.path.count(extPath) == 0: sys.path.insert(0, extPath) And it worked for what I wanted. On 13/02/07, Alan <[EMAIL PROTECTED]> wrote: On 13/02/07, Andreas Jung <[EMAIL PROTECTED]> wrote: > What's the sense of this code? sys.path is usually *never* empty. > You should really look at the Python docs and learn where Python is looking > by default for modules. Is is perfectly documented -> python.org -> > documentation. > > In addition you would like to check for the existence of an item in > sys.path using > > if myPath in sys.path: Dear Andreas and Jonathan, first a mistake: I want to access 'Extensions' folder as you mentioned Jonathan, not 'import'. Andreas, I've done that, I can see several path there like .../instance/Products/Sprout/src, .../lib/python/Zope2/Startup etc., but none for .../instance/Extensions. I was hoping that I could get the path where 'Extensions' is because I work with several zope installations in several platforms and I would like to make my module independent of a variable inside its code that should be manually adjusted for every situation. And yes, I am aware about adding the path only once (that's why there's a 'if') and then I avoid recursive insertions. Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Dear Andreas and Jonathan, first a mistake: I want to access 'Extensions' folder as you mentioned Jonathan, not 'import'. Andreas, I've done that, I can see several path there like .../instance/Products/Sprout/src, .../lib/python/Zope2/Startup etc., but none for .../instance/Extensions. I was hoping that I could get the path where 'Extensions' is because I work with several zope installations in several platforms and I would like to make my module independent of a variable inside its code that should be manually adjusted for every situation. And yes, I am aware about adding the path only once (that's why there's a 'if') and then I avoid recursive insertions. Cheers, Alan On 13/02/07, Jonathan <[EMAIL PROTECTED]> wrote: - Original Message - From: "Alan" <[EMAIL PROTECTED]> To: "Andreas Jung" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, February 13, 2007 8:10 AM Subject: Re: [Zope] External Method importing modules > Thanks Andreas, I am trying with: > > if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) > > where myPath should be '[Zope installation folder]/instance/import'. > So my question now is: is there a variable inside Zope which can > returns the 'import' path? You can easily check what's in your sys.path by having your external method return it. Typically, the Extensions directory (where your external methods live) are not in the default path and need to be added to sys.path.(warning: be careful on how you do this or everytime your external method gets called it will add to the sys.path and will eventually cause you grief!). Jonathan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
- Original Message - From: "Alan" <[EMAIL PROTECTED]> To: "Andreas Jung" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, February 13, 2007 8:10 AM Subject: Re: [Zope] External Method importing modules Thanks Andreas, I am trying with: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) where myPath should be '[Zope installation folder]/instance/import'. So my question now is: is there a variable inside Zope which can returns the 'import' path? You can easily check what's in your sys.path by having your external method return it. Typically, the Extensions directory (where your external methods live) are not in the default path and need to be added to sys.path.(warning: be careful on how you do this or everytime your external method gets called it will add to the sys.path and will eventually cause you grief!). Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
--On 13. Februar 2007 13:10:17 + Alan <[EMAIL PROTECTED]> wrote: Thanks Andreas, I am trying with: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) What's the sense of this code? sys.path is usually *never* empty. You should really look at the Python docs and learn where Python is looking by default for modules. Is is perfectly documented -> python.org -> documentation. In addition you would like to check for the existence of an item in sys.path using if myPath in sys.path: -aj pgp96jJNlbS0E.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Thanks Andreas, I am trying with: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) where myPath should be '[Zope installation folder]/instance/import'. So my question now is: is there a variable inside Zope which can returns the 'import' path? Many thanks in advance. Cheers, Alan On 13/02/07, Andreas Jung <[EMAIL PROTECTED]> wrote: --On 13. Februar 2007 12:53:25 + Alan <[EMAIL PROTECTED]> wrote: > Dear List, > > I have an external method and now I developed I new module in a > separated file and then I am trying to make my external method to > import it but I am failing here. Where should place my module file in > order to be found by my external method? > I tried to place it in the same folder of my external method, but no > success. Since the module must be importable, it must be available in some location as defined through sys.path or $PYTHONPATH. Check the Python docs for additional info on that topic. -aj -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
--On 13. Februar 2007 12:53:25 + Alan <[EMAIL PROTECTED]> wrote: Dear List, I have an external method and now I developed I new module in a separated file and then I am trying to make my external method to import it but I am failing here. Where should place my module file in order to be found by my external method? I tried to place it in the same folder of my external method, but no success. Since the module must be importable, it must be available in some location as defined through sys.path or $PYTHONPATH. Check the Python docs for additional info on that topic. -aj pgpQcuB0jgR9M.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method importing modules
Dear List, I have an external method and now I developed I new module in a separated file and then I am trying to make my external method to import it but I am failing here. Where should place my module file in order to be found by my external method? I tried to place it in the same folder of my external method, but no success. Any help would be very appreciated. Many thanks in advance. Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method unable to run Java jar executable using os.system()
--On 12. Februar 2007 07:34:09 -0800 Ridzwan Aminuddin <[EMAIL PROTECTED]> wrote: java -jar /var/lib/zope2.8/instance/plone-site/Extensions/test.jar it works perfectly But using the external method given above just gives me a blank output. I've also tried popen2: from popen2 import popen2 outputTGT, inputTGT = popen2(command) print outputTGT.readline() and still the jar is simply skipped and not executed. You should see error messages on the console. Ensure you are running Zope in the foreground (zopectl fg). -aj pgpnJqWSVyfcU.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method unable to run Java jar executable using os.system()
Hi, I'm trying to run an external method that has a line that runs an os.system command to execute a Java .jar executable that simply outputs a text file as well as prints out a string. I've saved the python script as well as the Java .jar executable in my Extensions folder: /var/lib/zope2.8/instance/plone-site/Extensions/ Here is my Python script: def runYahooSearch2(self): import os homedir = os.getcwd() # on my machine homedir is /var/lib/zope2.8/instance/plone-site command = "java -jar "+ homedir + "/Extensions/test.jar" whatisread = os.popen(command).read() print whatisread This external method is triggered in my DTML code. I've created other external methods before so i know i've done it right.. but the os.system() command for java -jar just doesn't seem to work. I've tried to use other commands such as: os.popen("ls") and it works perfectly Its just this java -jar which does not execute at all... I know it doesn't execute at all cos it doesn't output a file or print the string. If i manually type out into the terminal : java -jar /var/lib/zope2.8/instance/plone-site/Extensions/test.jar it works perfectly But using the external method given above just gives me a blank output. I've also tried popen2: from popen2 import popen2 outputTGT, inputTGT = popen2(command) print outputTGT.readline() and still the jar is simply skipped and not executed. Does anyone know whats the cause and cure for this problem?... Or anynone knows any other method i can use instead of os.popen os.popen2 and os.system to run this command line statement?... or any way i can catch the exception which is being thrown when the java -jar is attempting to run ( if there is any in the firt place) ? Anything would be highly appreciated!... Kinda in a fix right now!... Thanks in advance! Cheers Wan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method and XML-PRC (Maybe a bug)
Hi, Iam trying to use Zope as an App server (basically to provide an XML-RPC interface) for a certain application . I have a function called addFile in the External Method. def ext_addfile(self): ob=self.Files ob.manage_addFile("hello","hello") I created an external method call ext_addFile() Now I write my client using xml-rpc lib s=xmlrpclib.Server("") s.ext_addFile() And this adds a file to my directory. This freaked me out. Because i was anonymous user and this shdnt happen. The next thing i did was create a python script of the same structure and called it addFile() ob=context.Files ob.manage_addFile("hello","hello") Now I run my client xml-rpc program s=xmlrpclib.Server("") s.addFile() and its fiving me unauthorized as expected. So basically i dont know why is this happening. Is this due to some permission problems i have on the directory or External Methods, or something which iam totally missing. -- Phani Kumar Arava Grad Student 1560 Worthington Street Department Of Computer ScienceColumbus Ohio 43201 2015 Neil Avenue Ohio State University Columbus Ohio-43210 Contact: (614)-286-2618 URL : www.cse.ohio-state.edu/~arava/ mailto: [EMAIL PROTECTED],[EMAIL PROTECTED], [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method cPickle Import Module Error
Sean W. Duffy wrote at 2006-12-27 19:44 -0600: > ... >I have upgraded from Zope 2.8.5 to 2.9.4. This currently works in the >2.8.5 instance but not in the 2.9.4. > >I have a Module Progress in /usr/lib/python2.4/site-packages/Progress >containing 4 files: > >__init__.py __init__.pyc Progress.py Progress.pyc > >Both instances have calls to neuro.py which includes: > >from Progress import Progress > >The External Method in both instances looks good. I even updated the >External Method by clicking the Save Changes button without >error in the new 294 instance. > >But when I access it from the dtml-method it goes boom: > >Traceback (innermost last): > > Module ZPublisher.Publish, line 115, in publish > Module ZPublisher.mapply, line 88, in mapply > Module ZPublisher.Publish, line 41, in call_object > Module Products.ExternalMethod.ExternalMethod, line 134, in manage_edit > Module Products.ExternalMethod.ExternalMethod, line 141, in getFunction > Module App.Extensions, line 148, in getObject > - __traceback_info__: ('/var/lib/hip_294_251/Extensions/neuro.py', >'neuro') > Module /var/lib/hip_294_251/Extensions/neuro.py, line 299, in ? > Module /var/lib/hip_294_251/Extensions/neuro.py, line 9, in GetProgress >ImportError: No module named Progress > >But Progress is in: /usr/lib/python2.4/site-packages/Progress ! > >If I just start python at the command line I can import Progress w/o >error. I'm guessing that it has something to do with how >cPickle is sandboxed by Zope, but I just don't get it. It does not look like a Zope (version) issue: The "import" in an "External Method" is a pure Python "import" -- without any restrictions or additional magic. Therefore, if "sys.path" is still correct inside the "External Method", all modules/packages reachable by "sys.path" should be importable. I would check "sys.path". -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method cPickle Import Module Error
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - --On 27. Dezember 2006 19:44:24 -0600 "Sean W. Duffy" <[EMAIL PROTECTED]> wrote: > Hi, > > I have upgraded from Zope 2.8.5 to 2.9.4. This currently works in the > 2.8.5 instance but not in the 2.9.4. > > I have a Module Progress in /usr/lib/python2.4/site-packages/Progress > containing 4 files: > > __init__.py __init__.pyc Progress.py Progress.pyc > > Both instances have calls to neuro.py which includes: > > from Progress import Progress > > The External Method in both instances looks good. I even updated the > External Method by clicking the Save Changes button without > error in the new 294 instance. > > But when I access it from the dtml-method it goes boom: > > Traceback (innermost last): > Module ZPublisher.Publish, line 115, in publish > Module ZPublisher.mapply, line 88, in mapply > Module ZPublisher.Publish, line 41, in call_object > Module Products.ExternalMethod.ExternalMethod, line 134, in manage_edit > Module Products.ExternalMethod.ExternalMethod, line 141, in getFunction > Module App.Extensions, line 148, in getObject > - __traceback_info__: ('/var/lib/hip_294_251/Extensions/neuro.py', > 'neuro') > Module /var/lib/hip_294_251/Extensions/neuro.py, line 299, in ? > Module /var/lib/hip_294_251/Extensions/neuro.py, line 9, in GetProgress > ImportError: No module named Progress > > But Progress is in: /usr/lib/python2.4/site-packages/Progress ! > > If I just start python at the command line I can import Progress w/o > error. I'm guessing that it has something to do with how > cPickle is sandboxed by Zope, but I just don't get it. > > I don't see any indication for a cPickle issue. *Trible* check that your Zope instance use the system Python installationl. Check your file permissions, check sys.path, check your $PYTHONPATH. - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) iD8DBQFFk3KQCJIWIbr9KYwRAlcKAKDL0t0qSQFkau++QkcCFXzxVHNbxgCggpG3 ySS1E+jhamd0mLwC+fnvhlM= =ZveC -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method cPickle Import Module Error
Hi, I have upgraded from Zope 2.8.5 to 2.9.4. This currently works in the 2.8.5 instance but not in the 2.9.4. I have a Module Progress in /usr/lib/python2.4/site-packages/Progress containing 4 files: __init__.py __init__.pyc Progress.py Progress.pyc Both instances have calls to neuro.py which includes: from Progress import Progress The External Method in both instances looks good. I even updated the External Method by clicking the Save Changes button without error in the new 294 instance. But when I access it from the dtml-method it goes boom: Traceback (innermost last): Module ZPublisher.Publish, line 115, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module Products.ExternalMethod.ExternalMethod, line 134, in manage_edit Module Products.ExternalMethod.ExternalMethod, line 141, in getFunction Module App.Extensions, line 148, in getObject - __traceback_info__: ('/var/lib/hip_294_251/Extensions/neuro.py', 'neuro') Module /var/lib/hip_294_251/Extensions/neuro.py, line 299, in ? Module /var/lib/hip_294_251/Extensions/neuro.py, line 9, in GetProgress ImportError: No module named Progress But Progress is in: /usr/lib/python2.4/site-packages/Progress ! If I just start python at the command line I can import Progress w/o error. I'm guessing that it has something to do with how cPickle is sandboxed by Zope, but I just don't get it. Any guidance sincerely appreciated, Sean Debug information: # Zope version: (Zope 2.9.4-final, python 2.4.3, linux2) # Python version: 2.4.3 (#1, Jun 13 2006, 16:41:18) [GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] # System Platform: linux2 # SOFTWARE_HOME: /var/lib/zope294/lib/python # INSTANCE_HOME: /var/lib/hip_294_251 # CLIENT_HOME: /var/lib/hip_294_251/var # Process ID: 2507 (-1256522832) # Running for: 19 min 17 sec # sys.path: /var/lib/hip_294_251/lib/python /var/lib/hip_294_251/lib/python /var/lib/zope294/lib/python/Zope2/Startup /var/lib/hip_294_251/Products/ATContentTypes/thirdparty /var/lib/zope294/lib/python /usr/lib/python24.zip /usr/lib/python2.4 /usr/lib/python2.4/plat-linux2 /usr/lib/python2.4/lib-tk /usr/lib/python2.4/lib-dynload /usr/lib/python2.4/site-packages /usr/lib/python2.4/site-packages/Numeric /usr/lib/python2.4/site-packages/PIL /usr/lib/python2.4/site-packages/gtk-2.0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method, not escaping < and >
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - --On 21. Dezember 2006 20:32:39 +0100 Mihamina Rakotomandimby <[EMAIL PROTECTED]> wrote: > Hi, > I have an external method that fetches some web content (POP messages) > then format an HTML output to make it easy to display. > the Id of the external method is "mm". So as I said, it returns HTML > content, with HTML tags and "<"s and ">"s. > I directly call that external method from a ZPT this way: > > foo > > the problem is the ">" and "<" returned by "mm" are all transformed to > < and >. How to avoid that? > Look at the 'structure' directive of ZPT *hint* - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) iD8DBQFFiuLZCJIWIbr9KYwRArATAJ9fW0UckZO5GFz30JWkddYv3h8GcwCfastX kc/+w1d6DMHK7pVgS3b08SY= =ojz9 -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] external method, not escaping < and >
Hi, I have an external method that fetches some web content (POP messages) then format an HTML output to make it easy to display. the Id of the external method is "mm". So as I said, it returns HTML content, with HTML tags and "<"s and ">"s. I directly call that external method from a ZPT this way: foo the problem is the ">" and "<" returned by "mm" are all transformed to < and >. How to avoid that? Thank you. ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
--On 2. November 2006 09:08:13 -0600 Edward Pollard <[EMAIL PROTECTED]> wrote: On 11/2/06 6:52 AM, "Maciej Wisniowski" <[EMAIL PROTECTED]> wrote: To install ZopeProfiler product you have to copy it to Products/ folder of your zope instance, restart your Zope and go to ControlPanel in ZMI. You should see new link there: Zope Profiler. When you want to start profiling you hit Enable, do your things and then hit Disable and watch results. I was aware the built-in profiling existed but I've never found it very easy to work with. However, when I installed ZopeProfiler it complained the built-in profiling was enabled, which was news to me. The profiler is *never* enabled by default. *You* must have enabled it somehow :-) -aj pgpBSz9T4322u.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
+---[ Edward Pollard ]-- | | I was aware the built-in profiling existed but I've never found it very easy | to work with. However, when I installed ZopeProfiler it complained the | built-in profiling was enabled, which was news to me. | | I turned it off and my problem dissolved. | | And then I called our server team and gave them a stern talking to. :-) And can you sell off 3/4 of your hardware now too? d8) -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
On 11/2/06 6:52 AM, "Maciej Wisniowski" <[EMAIL PROTECTED]> wrote: > To install ZopeProfiler product you have to copy it to Products/ folder > of your zope instance, restart your Zope and go to ControlPanel in ZMI. > You should see new link there: Zope Profiler. When you want to start > profiling you hit Enable, do your things and then hit Disable and watch > results. I was aware the built-in profiling existed but I've never found it very easy to work with. However, when I installed ZopeProfiler it complained the built-in profiling was enabled, which was news to me. I turned it off and my problem dissolved. And then I called our server team and gave them a stern talking to. :-) --- Edward J. Pollard, B.Sc Webmaster, University of Lethbridge Ext. 1828 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
ZopeProfiler seems to come with no instructions to install. Can you advise? I haven't installed it for years, but i seem to remember that it installed just like a normal product (ie. install in the Products directory, restart zope, it shows up automagically - in linux that is, i don't do windows). Wasn't there a README when you unpacked the tarball? Maybe someone else on the list has more recent experience... AFAIK profiling is integrated into Zope right now. Take a look at zope.conf and you'll find proper section. Although I'm not sure how it works. I've used ZopeProfiler product. To install ZopeProfiler product you have to copy it to Products/ folder of your zope instance, restart your Zope and go to ControlPanel in ZMI. You should see new link there: Zope Profiler. When you want to start profiling you hit Enable, do your things and then hit Disable and watch results. -- Maciej Wisniowski ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
- Original Message - From: "Edward Pollard" <[EMAIL PROTECTED]> To: "Jonathan" <[EMAIL PROTECTED]> Sent: Wednesday, November 01, 2006 5:21 PM Subject: Re: [Zope] External Method = Slow; Shell Script = Fast Hi Jon, ZopeProfiler seems to come with no instructions to install. Can you advise? Ed I haven't installed it for years, but i seem to remember that it installed just like a normal product (ie. install in the Products directory, restart zope, it shows up automagically - in linux that is, i don't do windows). Wasn't there a README when you unpacked the tarball? Maybe someone else on the list has more recent experience... Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
- Original Message - From: "Edward Pollard" <[EMAIL PROTECTED]> To: Sent: Wednesday, November 01, 2006 5:58 PM Subject: [Zope] External Method = Slow; Shell Script = Fast Hello, I've got an external method that does some pretty complicated stuff. Basically it takes two XML files - one defines constraints, the other variables - and the script finds a solution using the variables that satisfies the constraints. At the command line (or executed via an external method that calls a shell script) execution is 2 seconds. As an external method execution is 15-20 seconds with the same input. Can anyone offer tips or strategies to improve performance? It would be obnoxious to have to encode objects for passing to a shell script. You should use something like ZopeProfiler or CallProfiler to find out where the time is being spent. Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method = Slow; Shell Script = Fast
Hello, I've got an external method that does some pretty complicated stuff. Basically it takes two XML files - one defines constraints, the other variables - and the script finds a solution using the variables that satisfies the constraints. At the command line (or executed via an external method that calls a shell script) execution is 2 seconds. As an external method execution is 15-20 seconds with the same input. Can anyone offer tips or strategies to improve performance? It would be obnoxious to have to encode objects for passing to a shell script. --- Edward J. Pollard, B.Sc Webmaster, University of Lethbridge Ext. 1828 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
garry saddington wrote at 2006-10-18 18:13 +0100: > ... >import psycopg, string, re, subprocess >def scholarpack_xml_transform(source): >f=open('/opt/scholarpack/ancillary/source.xml','w') >f.write(source) >f.close The line above looks buggy: missing "()". > ... >do=curs.execute(transformed1) >do The line above looks doubtfull: no effect >conn.commit() >conn.close > >I get a programming error thrown from the conn.commit() line and the >method fails. Almost surely, "postgres" does not like the command your have generated. It is quite picky with binary data... -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
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 :) > ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
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 http://www.slinkp.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
+---[ garry saddington ]-- | On Thu, 2006-10-19 at 03:18 +1000, Andrew Milton wrote: | > +---[ garry saddington ]-- | > | 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: | > | > [snip] | > | > | Can anyone point me in the correct direction? | > | > Text encoding? | The same files are used both times. The error log is not very helpful | here but I enclose it for completeness. | regards | garry I'd add some debugging into the pyana.py file, at the point where it's raising the exception. -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
On Thu, 2006-10-19 at 03:18 +1000, Andrew Milton wrote: > +---[ garry saddington ]-- > | 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: > > [snip] > > | Can anyone point me in the correct direction? > > Text encoding? The same files are used both times. The error log is not very helpful here but I enclose it for completeness. regards garry Log Undo Ownership Security Site Error Log Site Error Log at /error_log Exception traceback Time 2006/10/18 18:42:33.586 GMT+1 User Name (User Id) scholarpack (scholarpack) Request URL http://localhost/scholarpack/admin/interoperability/upload/addCTF Exception Type ProgrammingError Exception Value Traceback (innermost last): * Module ZPublisher.Publish, line 113, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 40, in call_object * Module Shared.DC.Scripts.Bindings, line 311, in __call__ * Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec * Module Products.PythonScripts.PythonScript, line 323, in _exec * Module None, line 11, in addCTF Line 11 * Module OFS.DTMLMethod, line 144, in __call__ URL: http://localhost/scholarpack/admin/interoperability/upload/result/manage_main Physical Path:/scholarpack/admin/interoperability/upload/result * Module DocumentTemplate.DT_String, line 476, in __call__ * Module Shared.DC.Scripts.Bindings, line 325, in __render_with_namespace__ * Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec * Module Products.PythonScripts.PythonScript, line 323, in _exec * Module None, line 2, in test_html Line 2 * Module Products.ExternalMethod.ExternalMethod, line 225, in __call__ __traceback_info__: (('\n\n\n \n U925540006009\n Abara\n Tonna\n 1989-07-17\n F\n \n Abara\n Tona\n 12\n BAFR\n O\n \n \n F\n ENG\n \n \n false\n false\n C\n \n \n \n H61 Road 42\n Victoria Garden City\n Box 72675\n Victoria Island\n Lagos\n Nigeria\n \n \n \n \n Mr & Mrs\n Abara\n FAM\n true\n \n true\n \n \n \n H\n 014618466\n \n \n H\n 0208 5750766\n \n \n \n RMMS\n 1\n true\n true\n Mr & Mrs Abara\n \n \n \n \n RMMS\n C\n \n n/s\n ENG\n \n \n \n \n U92554000501A\n Abdullah\n Safaris\n 1995-07-08\n M\n \n Abdullah\n Safaris\n 7\n MOTH\n T\n \n \n F\n ENG\n \n \n false\n false\n C\n \n \n \n 43 St Margarets Avenue\n \n \n Skegness\n Lincolnshire\n PE25 2LX\n England\n \n \n \n \n Mrs\n Lilley\n PAM\n true\n \n true\n \n \n \n H\n 01754 760193\n \n \n H\n 07783 538592\n \n \n \n RMMS\n 1\n true\n true\n Mrs Lilley\n \n \n \n \n \n KS3\n \n ENG\n 2006\n ENG\n 47\n SUB\n I\n NS\n 0\n \n \n \n \n RMMS\n C\n \n n/s\n ENG\n \n \n \n\n\n',), {}, None) * Module /opt/scholarpack/instances/scholarpack/Extensions/pyana.py, line 18, in scholarpack_xml_transform ProgrammingError: Display traceback as text REQUEST form submit ' Add ' id 'ctfxml' file '\n\n\n \n U925540006009\n Abara\n Tonna\n 1989-07-17\n F\n \n Abara\n Tona\n 12\n BAFR\n O\n \n \n F\n ENG\n \n \n false\n false\n C\n \n \n \n H61 Road 42\n Victoria Garden City\n Box 72675\n Victoria Island\n Lagos\n Nigeria\n \n \n \n \n Mr & Mrs\n Abara\n FAM\n true\n \n true\n \n \n \n H\n 014618466\n \n \n H\n 0208 5750766\n \n \n \n RMMS\n 1\n true\n true\n Mr & Mrs Abara\n \n \n \n \n RMMS\n C\n \n n/s\n ENG\n \n \n \n \n U92554000501A\n Abdullah\n Safaris\n 1995-07-08\n M\n \n Abdullah\n Safaris\n 7\n MOTH\n T\n \n \n F\n ENG\n \n \n false\n false\n C\n \n \n \n 43 St Margarets Avenue\n \n \n Skegness\n Lincolnshire\n PE25 2LX\n England\n \n \n \n \n Mrs\n Lilley\n PAM\n true\n \n true\n \n \n \n H\n 01754 760193\n \n \n H\n 07783 538592\n \n \n \n RMMS\n 1\n true\n true\n Mrs Lilley\n \n \n \n \n \n KS3\n \n ENG\n 2006\n ENG\n 47\n SUB\n I\n NS\n 0\n \n \n \n \n RMMS\n C\n \n n/s\n ENG\n \n \n \n\n\n' cookies dtpref_rows '20' dtpref_cols '100%' tree-s 'eJzTyCkw5NLIKT
Re: [Zope] external method strangeness
+---[ garry saddington ]-- | 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: [snip] | Can anyone point me in the correct direction? Text encoding? Would probably be a lot easier if you told us the error message in full that you get. -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] external method strangeness
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 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Pascal Peregrina wrote: Of course, for stuff like starting some processing at a given time in the Zope instance, crontab can be great... Cron firing off Stepper jobs at a ZEO storage server has worked well for me in quite a few projects :-) Well, there is also this interesting on-going thread about TimerService/ZopeScheduler :)) What thread? I just see some flame-baiting monkey complaining that he's too stupid to understand what people are telling him ;-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Well the complete story was: "We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea." And later on: "crontab is really a bad idea. We quitted that." And in that case (using crontab to restart Zope every night), I think it was a bad idea. Of course, for stuff like starting some processing at a given time in the Zope instance, crontab can be great... Well, there is also this interesting on-going thread about TimerService/ZopeScheduler :)) Pascal > De : Jens Vagelpohl <[EMAIL PROTECTED]> > Date : Thu, 5 Oct 2006 08:03:53 -0400 > À : zope Mailing List > Objet : Re: [Zope] external method: importing and updating method > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > On 5 Oct 2006, at 05:24, Alan wrote: > >> Hi List, >> >> crontab is really a bad idea. We quitted that. > > Might make sense to back up blanket nonsensical statements like that > with some hard facts. > > jens > > > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.1 (Darwin) > > iD8DBQFFJPSqRAx5nvEhZLIRAkKWAJ45fYr4khMmREaF89vfFJEGvo2v3gCfSe8g > bXYxESSH8t4mi4nFmVWY67A= > =wI9T > -END PGP SIGNATURE- > ___ > Zope maillist - Zope@zope.org > http://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope-dev ) ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ** ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 5 Oct 2006, at 05:24, Alan wrote: Hi List, crontab is really a bad idea. We quitted that. Might make sense to back up blanket nonsensical statements like that with some hard facts. jens -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (Darwin) iD8DBQFFJPSqRAx5nvEhZLIRAkKWAJ45fYr4khMmREaF89vfFJEGvo2v3gCfSe8g bXYxESSH8t4mi4nFmVWY67A= =wI9T -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
--On 5. Oktober 2006 10:24:31 +0100 Alan <[EMAIL PROTECTED]> wrote: Hi List, crontab is really a bad idea. We quitted that. Why is using crontab a bad idea? It's the most common and most reliable solution to run scripts in Zope periodically. -aj pgpHnQfkHcCKi.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
Hi List, crontab is really a bad idea. We quitted that. Thanks for your commentaries. Alan On 05/10/06, Chris Withers <[EMAIL PROTECTED]> wrote: Alan wrote: > Thanks for help. I did what suggested below. We also set a crontab to > restart the zope server every night, Why?! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Alan wrote: Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, Why?! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
On 10/4/06, Alan <[EMAIL PROTECTED]> wrote: Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. Isn't it better to just restart the server when you have updated the software? Modules loaded from External methods are not different from any other Zope software in that sense. -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/ ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
- Original Message - From: "Alan" <[EMAIL PROTECTED]> To: "Jonathan" <[EMAIL PROTECTED]> Cc: "Dieter Maurer" <[EMAIL PROTECTED]>; Sent: Wednesday, October 04, 2006 6:12 AM Subject: Re: Re: [Zope] external method: importing and updating method Hi Folks, Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. What you are trying to accomplish/resolve by restarting zope everynight? I can't think of any real downside to doing it, but it shouldn't be necessary - we once had a production server that ran for over 13 months, continuously, without ever being restarted! (now that's a stable platform!) Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
Hi Folks, Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. Cheers, Alan On 03/10/06, Jonathan <[EMAIL PROTECTED]> wrote: - Original Message - From: "Dieter Maurer" <[EMAIL PROTECTED]> To: "Alan" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, October 03, 2006 2:06 PM Subject: Re: [Zope] external method: importing and updating method > Alan wrote at 2006-10-2 18:48 +0100: >>In my external method I have something like this: >>... >>sys.path.insert(0, CCPNPYTHON) > > This is not a good idea! > > The source of an "External Method" can be read arbitrarily often -- > and each time, you extend "sys.path"... We get around this 'evergrowing' path problem by (if there is a problem with this solution let me know!): import sys SOMEPATH = '/some/path/goes/here' if SOMEPATH not in sys.path: sys.path.append(SOMEPATH) Jonathan -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
- Original Message - From: "Dieter Maurer" <[EMAIL PROTECTED]> To: "Alan" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, October 03, 2006 2:06 PM Subject: Re: [Zope] external method: importing and updating method Alan wrote at 2006-10-2 18:48 +0100: In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) This is not a good idea! The source of an "External Method" can be read arbitrarily often -- and each time, you extend "sys.path"... We get around this 'evergrowing' path problem by (if there is a problem with this solution let me know!): import sys SOMEPATH = '/some/path/goes/here' if SOMEPATH not in sys.path: sys.path.append(SOMEPATH) Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Alan wrote at 2006-10-2 18:48 +0100: >In my external method I have something like this: >... >sys.path.insert(0, CCPNPYTHON) This is not a good idea! The source of an "External Method" can be read arbitrarily often -- and each time, you extend "sys.path"... The "imp" module allows you to import modules without the need to modify "path". > ... >the problem I am facing now it that if I update my memops stuff (which >is found in CCPNPYTHON path) it seems not to be being updated in Zope, >because Zope is still using the old version. (If I run outside Zope, >the code works). That's typical Python behaviour: Python does not recognize at runtime when a module source has changed. It provides however a builtin "reload" which you can use to explicitely reload a module. Be warned the "reload" is dangerous. Funny effects can happen. As someone else suggested, restarting Zope is the safest way (although not the fasted one). -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
- Original Message - From: "Alan" <[EMAIL PROTECTED]> To: Sent: Monday, October 02, 2006 1:48 PM Subject: [Zope] external method: importing and updating method Hi List! In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) from memops.general.Io import loadXmlProjectFile ... the problem I am facing now it that if I update my memops stuff (which is found in CCPNPYTHON path) it seems not to be being updated in Zope, because Zope is still using the old version. (If I run outside Zope, the code works). I have encountered this problem before, and the quick-fix was to restart Zope (from the ZMI - Control Panel). hth Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] external method: importing and updating method
Hi List! In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) from memops.general.Io import loadXmlProjectFile ... the problem I am facing now it that if I update my memops stuff (which is found in CCPNPYTHON path) it seems not to be being updated in Zope, because Zope is still using the old version. (If I run outside Zope, the code works). And yes, I saved the external method in Zope FS. So, what else may I be missing? Many thanks in advance. Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method with import tarfile
Alan wrote: > Hi there! > > I managed to find the problem and the solution. > > First, I've forgot to mention that in my script, oname is an uploaded file. > I just inserted a f.close() and voilá! > > def upload_external(self,file,REQUEST): > import os,tarfile > ... > f=open(oname,"wb") > f.write(file.read()) > f.close() > ... > tar = tarfile.open(oname,"r:gz") > for itar in tar: > tar.extract(itar.name,jobdir) > return "Done" > Err. why not tar=tarfile.open(fileobj=file) ? Why bother with potentially name clashing files in filesystem? Regards Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method with import tarfile
Hi there! I managed to find the problem and the solution. First, I've forgot to mention that in my script, oname is an uploaded file. I just inserted a f.close() and voilá! def upload_external(self,file,REQUEST): import os,tarfile ... f=open(oname,"wb") f.write(file.read()) f.close() ... tar = tarfile.open(oname,"r:gz") for itar in tar: tar.extract(itar.name,jobdir) return "Done" Cheers, Alan On 18/07/06, Alan <[EMAIL PROTECTED]> wrote: Thanks for your reply. Yes, my script works and my file are not broken. I am using mac osx tiger 10.4.7, zope 2.9.3 and python 2.4.2. Cheers, Alan On 18/07/06, Andreas Jung <[EMAIL PROTECTED]> wrote: > > > --On 18. Juli 2006 16:12:18 +0100 Alan <[EMAIL PROTECTED]> wrote: > > > > Error Type: IOError > > Error Value: CRC check failed > > > > > > This is unlikely a Zope issue. Either your tar file is broken or the > tarfile module is broken. Check if your code runs without Zope as a > simple PythonScript..there is nothing about Zope involved in your issue. > > -aj > > -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method with import tarfile
--On 18. Juli 2006 16:12:18 +0100 Alan <[EMAIL PROTECTED]> wrote: Error Type: IOError Error Value: CRC check failed This is unlikely a Zope issue. Either your tar file is broken or the tarfile module is broken. Check if your code runs without Zope as a simple PythonScript..there is nothing about Zope involved in your issue. -aj pgp0ncqn4RhT4.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] external method with import tarfile
Hi! I am trying to run a external python script. Now I am facing a problem that occurs only when I run the script via Zope. ... import os,tarfile ... tar = tarfile.open(oname,"r:gz") for itar in tar: tar.extract(itar.name,jobdir) gives me: Site Error An error was encountered while publishing this resource. Error Type: IOError Error Value: CRC check failed If I comment the for loop my scripts finish well, but then it does not uncompress the file. Please, any help would very appreciated. Many thanks in advance, Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28<< ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
> When I've needed to do simple stuff with this is the past, I just > manipulate mailmain by send email from Zope to mailman's admin interface... > Pipes seem easier to me. Responses from the command line scripts seem much easier to use for confirmation. And there are things you can do easily from the cli interface that you either can't do through email, are difficult to do through email, or possibly I just don't know how to do through email. > > And yeah, tempfile would work, although, I have to > > admit I really don't see the point of it when you are only storing one > > file. I am probably missing some usecase or good programming practice > > here, but it seems like it saves you a single line for the delete in > > return for an extra module import. > > What happens when two users do something that creates one of these temp > files at exactly the same time? ;-) > Yah, you and Tres Seaver (OL) both made this point, and thanks for saving me from having much wailing and gnashing of teeth over my dimness once this actually went live. Thanks for the help, J.P. Withers ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers wrote: Because I need to feed the file to Mailman for evil purposes of my own (well, fairly mundane purposes of allowing my zope app to manipulate mailman list memberships, really) that the prototype mailman adapter I found doesn't meet. When I've needed to do simple stuff with this is the past, I just manipulate mailmain by send email from Zope to mailman's admin interface... And yeah, tempfile would work, although, I have to admit I really don't see the point of it when you are only storing one file. I am probably missing some usecase or good programming practice here, but it seems like it saves you a single line for the delete in return for an extra module import. What happens when two users do something that creates one of these temp files at exactly the same time? ;-) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
On Thu, 2005-09-29 at 00:20, Chris Withers wrote: > eep, another one, hope we're not related ;-) > When I saw your posts on newsgroups years ago, I almost gave up python programming altogether Chris, thinking that any given field of endeavor needs only one Withers, but decided to go ahead and chance it. > > Can anyone tell me what the default working directory for an external > > method is? > > You can't rely on it being anything. If you're working with files, you > need to be very careful... > > > Further, I need this to create a file temporarily in Extensions. > > Why? Because I need to feed the file to Mailman for evil purposes of my own (well, fairly mundane purposes of allowing my zope app to manipulate mailman list memberships, really) that the prototype mailman adapter I found doesn't meet. And yeah, tempfile would work, although, I have to admit I really don't see the point of it when you are only storing one file. I am probably missing some usecase or good programming practice here, but it seems like it saves you a single line for the delete in return for an extra module import. Peter Bengtsson gave me the solution in just using the INSTANCE_HOME variable directly, which is bound in external scripts. That beat the daylights out of the solution that had come up wjth the help of some folks on ICQ of using self.Control_Panel.getINSTANCE_HOME(). And Deiter is right and it is dim to put the temporary file in Extensions and it will be put in var instead. Not sure what I was thinking there. John Withers > > > I would prefer not to have to hardwire the location of Extension into the > > code, since that would make the script non-portable to other instances > > easily. > > > > Any advice on this would be appreciated. > > I'd suggest looking at python's tempfile module... > > Chris ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers wrote at 2005-9-28 15:43 -0700: > ... >I have an external method that at this point is made up of nothing but >os.getcwd() and lives in my Extensions directory. When it is run, it >reports the working directory as being one of my Products directories. Some products are broken (they change the current working directory). Apparently, you have one of them installed. In general, it is a bad idea to change the current working directory in a multi-threaded application (such as Zope). An External Method does not have a specific working directory "when it is run". Because Zope must not modify the working directory, it cannot let it follow the "run of an External Method". The current working directory remains what it was. On a system with well behaving products, the current working directory remains the "INSTANCE_HOME". > ... >Further, I need this to create a file temporarily in Extensions. >I would prefer not to have to hardwire the location of Extension into the >code, since that would make the script non-portable to other instances easily. The "Extensions" directory is a bad place for temporary files... -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers wrote: eep, another one, hope we're not related ;-) Can anyone tell me what the default working directory for an external method is? You can't rely on it being anything. If you're working with files, you need to be very careful... Further, I need this to create a file temporarily in Extensions. Why? I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. I'd suggest looking at python's tempfile module... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers, a) Is your os.getcwd() (in /Extensions) called from a Product (in /Products?) Otherwise I have not idea b) Regarding temporary files .. I've used stuff like ... import tempfile tmpFile2 = tempfile.mktemp() theFile=open( tmpFile2,'rb') result = theFile.read() theFile.close() os.remove(tmpFile2) I think this may depreciated but do a google on "python tempfile" and you can use the updated modules if they apply to your issue. David jwithers wrote: Folks, I have an external method that at this point is made up of nothing but os.getcwd() and lives in my Extensions directory. When it is run, it reports the working directory as being one of my Products directories. Can anyone tell me what the default working directory for an external method is? Further, I need this to create a file temporarily in Extensions. I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. J. P. Withers ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
Products?? That is odd. I thought it was the var/ directory or at least the zope instance home directory. From the External method you should have access to INSTANCE_HOME and SOFTWARE_HOME. Try if these are what you want. I doubt that you'll find your Extensions/ dir in any of them so you might have do something like: import os return os.path.join(INSTANCE_HOME, 'Extensions') 2005/9/28, jwithers <[EMAIL PROTECTED]>: > Folks, > > I have an external method that at this point is made up of nothing but > os.getcwd() and lives in my Extensions directory. When it is run, it > reports the working directory as being one of my Products directories. > > Can anyone tell me what the default working directory for an external > method is? > > Further, I need this to create a file temporarily in Extensions. > I would prefer not to have to hardwire the location of Extension into the > code, since that would make the script non-portable to other instances easily. > > Any advice on this would be appreciated. > > J. P. Withers > > ___ > Zope maillist - Zope@zope.org > http://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope-dev ) > -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method Working Directory?
Folks, I have an external method that at this point is made up of nothing but os.getcwd() and lives in my Extensions directory. When it is run, it reports the working directory as being one of my Products directories. Can anyone tell me what the default working directory for an external method is? Further, I need this to create a file temporarily in Extensions. I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. J. P. Withers ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method file generation Vs MSIE
Hi All, I have an external method that generates files - zip, pdf and xls. I would like the browser to present a file open/save dialog box and, depending on what the user clicks, open or save the file. Also, I want to be able to set the file name. Sounds simple enough and with most browsers setting the Content-type appropriately and the Content-Disposition to "attachment; filename="whatever"' works. I have not been able to get Internet Explorer to work properly though. Has anyone got this working? If so, how? Here is a full run down of the problem... I believe Internet Explorer uses a combination of the following to decide what to do with a file: o The Content-Type header. o The Content-Disposition header's value. o The Content-Disposition header's filename attribute's extension. o The extension of the external method. o The first part (200 bytes?) of the file contents. o The phase of the moon. (well, perhaps not, but it's starting to feel like it.) It then does one of the following: o Displays the file inline in the browser. o Displays the file open/save dialog. Clicking the save button saves the file. Clicking the open button launches the application that is associated with the file type IE has assumed the file to be but that application gives a file not found error. o Displays the file open/save dialog. Clicking on open or save displays another file open/save dialog. Clicking the save button again saves the file. Clicking the open button again launches the application that is associated with the file type IE has assumed the file to be but that application gives a file not found error. The filename of the file saved or the suggested filename when saving a file being viewed inline is sometimes the filename attribute in the content-disposition header and sometimes "external_method?query=string.ext". I have tried various combinations of the following: o Setting the Content-Type header to the file type, application/octet-stream, application/x-force-download, etc o Not setting the Content-Type header. o Setting the Content-Disposition header to inline, attachment and download with and without a filename attribute. o Not setting the Content-Disposition header. o Naming the external method filename.ext where ext is zip, pdf or xls as appropriate. o Hard coding the settings in the external method and not using a query string. Despite all this I have completely failed to get MSIE to behave in a sane manner and would greatly appreciate any advice anyone has on the matter. With thanks, Calisp ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method and security
Marty Stitt wrote: > Is it up to me to write my own security code when using an external > method? Basically, yes. You can protect access to the "stub" within the ZODB using the Security tab, but the body of the external method has free reign. Shane ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] external method and security
Hello, I've written an external method that I call through xml-rpc. It lets me create files on the server from a stand-alone client application that runs on the workstation of my users. In testing it recently, I discovered that it will let me write files to secured folders within my Zope system, even though I'm not yet using the patch to xmlrpclib.py that supports authentication! I'm running Zope 2.2.5 under redhat 7.0. The external method is included below. Any clues would be appreciated. Thanks in advance Is it up to me to write my own security code when using an external method? -- import tempfile import OFS.content_types import OFS.FindSupport import string def EWSyncAdd(self, PARMS): """ Create a new DTMLDocument, Image, or File object """ try: filename = PARMS['filename'] except: return "missing parm: filename" try: timestamp = PARMS['timestamp'] except: return "missing parm: timestamp" try: contents = PARMS['contents'].data except: return "missing parm: contents" try: title = PARMS['title'] except: return "missing parm: title" truepathspec = fixRPCPath(self.REQUEST) folderObject = self.REQUEST.resolve_url(truepathspec) filespec = truepathspec + '/' + filename itemObject = None if filename in folderObject.objectIds(): return "object already exists" type, enc=OFS.content_types.guess_content_type(filename, contents) if type in ('text/html', 'text/xml', 'text/plain'): # Create a DTMLDocument object folderObject.manage_addDocument(filename, title) itemObject = self.REQUEST.resolve_url(filespec) itemObject.manage_edit(contents, title) elif type[:6]=='image/': # Create an Image object f = tempfile.TemporaryFile() f.write(contents) f.seek(0) folderObject.manage_addImage(filename, f, title=title) f.close() itemObject = self.REQUEST.resolve_url(filespec) else: # Create a File object f = tempfile.TemporaryFile() f.write(contents) f.seek(0) folderObject.manage_addFile(filename, f, title=title) f.close() itemObject = self.REQUEST.resolve_url(filespec) if itemObject.getProperty('EWTimeStamp') is None: itemObject.manage_addProperty('EWTimeStamp', timestamp, 'string') else: itemObject.manage_changeProperties(None, EWTimeStamp=timestamp) return "OK" def fixRPCPath(req): pathsegs = string.split(req['PATH_INFO'], '/') if pathsegs[1] == 'RPC2': del pathsegs[1] del pathsegs[-1] return 'http://' + req['HTTP_HOST'] + string.join(pathsegs, '/') -- Martin Stitt Chief Software Engineer Esker, Inc. email: [EMAIL PROTECTED] phone: (608) 273-6000 x331 fax: (608) 273-8227 web: http://www.esker.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method
Kini Natekar writes: >How can I pass parameters to an External Method? I > know of one way to do this, is to use dtml-var tag. Is > there any other way? Anywhere, you can use 'expr=""'. This means almost all DTML tags: call, var, in, with, let (without 'expr='!) ... Example: Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method
If you are talking about dtml you can pass them in the dtml-call tag -- Andy McKay, Developer. ActiveState. - Original Message - From: "Kini Natekar" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, November 21, 2000 2:12 AM Subject: [Zope] External Method > > Hi, > >How can I pass parameters to an External Method? I > know of one way to do this, is to use dtml-var tag. Is > there any other way? > > Thanks, > Kini. > > __ > Do You Yahoo!? > Yahoo! Shopping - Thousands of Stores. Millions of Products. > http://shopping.yahoo.com/ > > ___ > Zope maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope-dev ) > ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method
Hi, How can I pass parameters to an External Method? I know of one way to do this, is to use dtml-var tag. Is there any other way? Thanks, Kini. __ Do You Yahoo!? Yahoo! Shopping - Thousands of Stores. Millions of Products. http://shopping.yahoo.com/ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method import error (ImportError)...
Eric writes: > To summarize: How do I import modules in an External Method's .py file? I remember, I read this in some "External Method" related documentation. You do *NOT* place such modules inside the folder "Extensions" but put them somewhere else reachable by "PYTHONPATH". The documentation suggests that you create a subpackage inside "Shared", say "Extensions", and place there your module (don't forget "__init__.py" in the subfolder representing the subpackage), say "". Then, in your external method, you would use: from Shared.Extensions import Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method database connection
Also, you could always import the specific module for your database, and create a db connection, then execute() and fetch() directly. Although, if you are putting this in an external method, it would be wiser to use your existing ZSQL methods ;] Knight [EMAIL PROTECTED] On Fri, 6 Oct 2000, knight wrote: > > > How do I get a zope database connection from an enternal method? > > You can access your db using your existing ZSQL Methods by calling them > from the namespace passed in, specifically self. > > Example: > > def myextmethod(self): > mfl_id = 3 > results = self.sqlCountUsers(mfl_id=mfl_id) > for result in results: > print result[0], result[3] > > > > Keep in mind that a list is returned, not a dictionary. > > Knight > [EMAIL PROTECTED] > > > > ___ > Zope maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope-dev ) > > ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method database connection
> How do I get a zope database connection from an enternal method? You can access your db using your existing ZSQL Methods by calling them from the namespace passed in, specifically self. Example: def myextmethod(self): mfl_id = 3 results = self.sqlCountUsers(mfl_id=mfl_id) for result in results: print result[0], result[3] Keep in mind that a list is returned, not a dictionary. Knight [EMAIL PROTECTED] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] external method database connection
Hi ya Another newbe question sorry. How do I get a zope database connection from an enternal method? Thanks Mark ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] external method import error (ImportError)...
Hi, To summarize: How do I import modules in an External Method's .py file? I have an external method that points to a .py file that has an import statement at the top. The import statement loads another module of mine (CProject.py). I've placed both files (pwToxml.py and CProject.py) in the Zope/Extensions directory. When I try to create an external method on the pTox.py file with the following parameters: ID = pTox Function Name = pTox Python Module File = pwToxml I get the following error: Error Type: ImportError Error Value: No module named CProject Traceback (innermost last): File /usr/local/Zope/lib/python/ZPublisher/Publish.py, line 222, in publish_module File /usr/local/Zope/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/Zope/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook File /usr/local/Zope/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/Zope/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: manage_addExternalMethod) File /usr/local/Zope/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: manage_addExternalMethod) File /usr/local/Zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 130, in manage_addExternalMethod File /usr/local/Zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 178, in __init__ (Object: pTox) File /usr/local/Zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 201, in manage_edit (Object: pTox) File /usr/local/Zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 210, in getFunction (Object: pTox) File /usr/local/Zope/lib/python/App/Extensions.py, line 217, in getObject (Info: ('/usr/local/Zope/Extensions/pwToxml.py', 'pwToxml')) File /usr/local/Zope/Extensions/pwToxml.py, line 1, in ? ImportError: (see above) I checked the sys.path for my Python installation and placed the CProject.py file there, but I still get the same error. Here's the top of my pwToxml.py file: import CProject, string def pTox(self, REQUEST): """Function to map pw to CProject Objects""" P=CProject.CProject() dictData = REQUEST.form.items() strTemp = "" strError = "Error Retrieving Dictionary Value" ...etc... Thanks for any help you can provide. ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External method and stdout
Andreas Pauley wrote: > > For some reason you have to "return" everything that should be available > to zope. You can return a sequence and loop through it with DTML or you > can build a variable with everything you want to display and then return > the variable. > > I have no idea why this is so, and why you can't just the print > statement as an equivalent to . > > There is probably elegant ways of replacing DTML with external methods > or Python Methods, I was just unable to find documentation and examples > on it until now. Can anyone help with this? > > Regards, > Andreas. there are a couple of ways. first zope's publishing objects. if your publishing a dtml method object than the semantics of it require that values be inserted into the template/page thats being returned to the user. you can also publish an external method or a python module directly(indeed Zope is just a published python module). but sticking to zope external methods, an example, if you had def myhello_world(self, REQUEST): page = " welcome to %s corner of my hello world "%self.getParentNode().id and just browse directly to the external method. its important to keep in mind that stdout isn't connected to the client. the client is connected to medusa/ZServer, which gives a channel to ZPublisher to publish data that will be returned to the client. this mainly applies to fs code, i'm not totally sure about the semantics of web python methods. i know this probably goes a bit further down the rabbit hole than you might be interested in going. if you want to know some more of the details. check out the medusa docs at http://www.nightmare.com/medusa and the ZPublisher docs under the Documentation Sec. of Zope.org. These are dated but they give a understanding of the interaction between medusa's asynch interfaces and zope. and of course the source code. you could also use document templates directly from python def new_world_order(self, REQUEST): from DocumentTemplate import HTML my_sites = [('My homepage','http://homepage'), ('my favorite bookstore','http://amazon.com') , ... etc] page_to_return = """ """ return HTML(my_sites)(sites=my_sites) or evaluate a dtml file on the file system using HTMLFILE see the DocumentTemplate directory for source and more examples D.Templates also give you a pretty good separation of app. logic and presentation. Doing straight python insertion in a page is not the Zope Way. if you're interested in this type of thing, you might want to check out some other python projects like mod_snake (apache), pywx.sourceforge.net (aolserver), or webware. I'll think you find the benefits of doing it through DTML offer you a lot more benefits in terms on maintainbility and site management. Cheers Kapil > > Sven Hohage wrote: > > > > Hallo, > > that's the problem: > > I've made an external method which is working with lists and should > > return the result to Zope. The python code is working very well, but > > is sending everything to sys.stdout( I'm using the > > print-statement).How do I convince Zope to print the result on the > > html-page. > >Thanks. > > -- > In a world without fences, who needs gates? > > ___ > Zope maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External method and stdout
For some reason you have to "return" everything that should be available to zope. You can return a sequence and loop through it with DTML or you can build a variable with everything you want to display and then return the variable. I have no idea why this is so, and why you can't just the print statement as an equivalent to . There is probably elegant ways of replacing DTML with external methods or Python Methods, I was just unable to find documentation and examples on it until now. Can anyone help with this? Regards, Andreas. > Sven Hohage wrote: > > Hallo, > that's the problem: > I've made an external method which is working with lists and should > return the result to Zope. The python code is working very well, but > is sending everything to sys.stdout( I'm using the > print-statement).How do I convince Zope to print the result on the > html-page. >Thanks. -- In a world without fences, who needs gates? ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External method and stdout
Sven Hohage wrote: > >Part 1.1Type: Plain Text (text/plain) >Encoding: quoted-printable why are you printing in the external method?? if you want zope to print it to html than you need to return the result of your external method back to zope so it can deliver the result as part of the rendered page. you might also want to check out web python methods ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] External method and stdout
Hallo, that's the problem: I've made an external method which is working with lists and should return the result to Zope. The python code is working very well, but is sending everything to sys.stdout( I'm using the print-statement).How do I convince Zope to print the result on the html-page. Thanks.
Re: [Zope] External Method not accepting CGI module
Kelvin Cheong writes: > import cgi > > form = cgi.FieldStorage() This gives you an empty "FieldStorage" > > fileitem = form["userTABPIX1"] In it, "userTABPIX1" is unknown. > > fname = tempfile.mktemp() > fp=open(fname,'w') > fp.write(fileitem.file.read()) > fp.close() Give your external method either the first argument "self" or an argument "REQUEST". In the first case, you can use "REQUEST=self.REQUEST" to get the REQUEST object. In the second case, you use REQUEST directly. "REQUEST.form" contains the form variables of the REQUEST. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method not accepting CGI module
Dear All, I have this python module for uploading an image from a client to the server (which would be subsequently inserted into a MySQL database, which is still on the midst of being resolved). I''m trying to import this into Zope as an External MEthod. It's contents are as follows : import cgi form = cgi.FieldStorage() fileitem = form["userTABPIX1"] fname = tempfile.mktemp() fp=open(fname,'w') fp.write(fileitem.file.read()) fp.close() However, Zope generates this error : Zope has encountered an error while publishing this resource. Error Type : KeyError Error Value: userTABPIX1 Apparently, this piece of code is supposed to work. I grabbed it off the mailing list, and I've compared with the python references and tutorials. Is it because it's not meant to be used as an External MEthod? If so, can anybody suggest a way for me to upload files from the client to the server which will subsequently be inserted into a mySQL db? I posted another message in the archive earlier on which describes my previous attempts in inserting an image into the mySQL database from a form. Thanx, k.c. VCN - The Leader In Corporate Communication Solutions Visit our website at http://www.vcn.com.my. or http://www.vcnlinux.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Difficulties
Dieter Maurer wrote: > > > That should work. > > What KeyError do you get? > The error message's head should tell you what key has not been > found. The traceback at the foot (especially the last line) > tells you where the KeyError occured. After I posted, I did some more wild, random, send-up-a-prayer hacking and I think I discovered the problem. It appears that the name of the external method and the name of the module file must be the same. At least, I changed the name of the file to genhash.py and things worked. It could be that the file was called md5.py, and since there is a Python module called md5, the interpreter may have been getting confused. I don't know which. Can any one shed some light on that? Thanks for your help, Dieter! -- Jason Lee |Maybe it's good that I can't afford anti-psychotic [EMAIL PROTECTED]|medication. It frees me up to plan the assassination Programmer/Analyst |of Deputy Dawg. -- The Onion ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Difficulties
Jason Lee writes: > ... external method access ... > > This says, "call the method (for its side effects) but discard any return value". > This produces nothing. I think I read somewhere that dtml-call returns no data, > so that might explain it. I could be wrong. You are right. > That should work. What KeyError do you get? The error message's head should tell you what key has not been found. The traceback at the foot (especially the last line) tells you where the KeyError occured. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] External Method Difficulties
For background purposes, I need to write a python module that will generate an MD5 hash of a given string, and return the base 64 representation of that hash. The problem I am facing is getting my stub to work from my DTML document. What I have write now is a stub that takes no arguments and returns "Hello, World". When I click Try It from the management screen, it works fine, but I can't seem to make it work from the DTML doc. This is what Iv'e tried (I'm still pretty new so I'm making wild guesses :) This produces nothing. I think I read somewhere that dtml-call returns no data, so that might explain it. I could be wrong. This produces a KeyError. It seems like I've tried a couple of other manglings, but what they were escapes me for the moment. I'm not passing a parameter right now, cuz I wanted to simplify things once I found out it wasn't going to work like I expected it to. What am I doing wrong? Is there a better place to start than this list? I have the content manager's guide and the dtml reference, but I can't find anything helpful. The ID for the external method is md5 in case that helps. Thanks a lot! -- Jason Lee - Programmer/Analyst The Fox and the Grapes: I'm not sure what the point is here. The moral is "It is easy to despise what you cannot get," but from experience I can tell you it's easy to despise what you do get as well, especially in terms of cable channels. -- The Brunching Shuttlecocks ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )