External Methods ->syntax + file access = how ?
Trying to get PIL [Python Imaging Library. http://www.pythonware.com/products/pil/ ] and other modules to work via Zope External Methods. But so far getting hung up on some simple understanding about Python and Zope. Searched archives, but I could find the answer. When testing outside of Zope, from python shell such as Idle, everything works OK. But inside Zope I keep getting file, URL, or resources not found - error messages, whenever I try to open an image into my python code. Seems like it's either blocked by security checks and/or I am making newbie path mistakes. I've tried a lot of variations with setting paths, experimenting with os.chdir(), and checking the files visible to my code using os.listdir(os.getcwd()). I can import the PIL modules and see the files I want to open in the 'Extensions' folder, but can't open them. At present, all the PIL files are in the 'Extensions' folder, but I understand from the ZCMG that I could also put them in 'Shared'. The ZCMG says that I can create a folder in 'Shared' with company or personal name and then this will be automatically referenced by zope. What is not clear to me what name, why and what do I ave to do to tell zope about the folder name I have created there.? Most of PIL is just python and suffices to parse the image headers, but for image processing, PIL uses a platform-specific library (ie: _imaging.dll on Win32). Where should this go on a ZopeSite? And what is my path needs to import PIL. minimal external method for testing : #pil_test.py import os, sys import Image def pil_test(self): infile = 'animage.jpg' im = Image.open(infile) return im.size, im.format, im.mode won't work: errors as above. ..So I tried opening a simple text text file in 'Extensions' and that failed. Is this illegal?? How do I use python external method to 'open' any file.? Do I have to import htmllib or somesuch and use that to point at my ZopeSite or elsewhere? I've already tested this with loading and displaying local and remote HMTL pages in open. fun,very cool. What syntax will directly load Zope 'Image' objects into Python external methods. The zope error messages reference line 110 of Image.py and line 716 of ImageFile.py So far I 've come up with 4 possibles: 1. The namespace of Zope 'Image' is getting confused by imported PIL 'Image' 2. What I am doing is illegal 3. I am in wrong path 4. Dumb newbie typos I am very keen to get this working, so that we can get on with creating a set of nice Zope image processing methods. These can allow much friendlier end-user uploading of images with automatic linked indexes, thumbnailing, sending e-mail to user groups of images, image compositing etc. Thanks in advance for any tips - Jason Cunliffe ------------------------------------------------- Jason Cunliffe <jasonic@nomadicsltd.com> NOMADICS.STUDIO(Design Director) Geo-Digital Arts and Technology Le Vieux Moulin, Route de Mons 83440 SEILLANS, FRANCE Tel: +33 (0)4 94.76.98.72 Fax: +33 (0)4 94.76.97.77
Jason, Have you made PIL into a package? PIL and Zope both have objects called Image/ImageFile so when you import Image for instance, do you really know which one is being imported. There was some discussion a while back about this. There is a PIL friendly poll product at the old zope site (http://www.zope.org:8080/Download/Contrib/poll.tgz) that explains what you have to do to get them both working together. HTH Phil phil@WigWamWeb.net -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Jason Cunliffe Sent: Friday, October 29, 1999 11:58 AM To: zope@zope.org Subject: [Zope] External Methods ->syntax + file access = how ? Trying to get PIL [Python Imaging Library. http://www.pythonware.com/products/pil/ ] and other modules to work via Zope External Methods. But so far getting hung up on some simple understanding about Python and Zope. Searched archives, but I could find the answer. When testing outside of Zope, from python shell such as Idle, everything works OK. But inside Zope I keep getting file, URL, or resources not found - error messages, whenever I try to open an image into my python code. Seems like it's either blocked by security checks and/or I am making newbie path mistakes. I've tried a lot of variations with setting paths, experimenting with os.chdir(), and checking the files visible to my code using os.listdir(os.getcwd()). I can import the PIL modules and see the files I want to open in the 'Extensions' folder, but can't open them. At present, all the PIL files are in the 'Extensions' folder, but I understand from the ZCMG that I could also put them in 'Shared'. The ZCMG says that I can create a folder in 'Shared' with company or personal name and then this will be automatically referenced by zope. What is not clear to me what name, why and what do I ave to do to tell zope about the folder name I have created there.? Most of PIL is just python and suffices to parse the image headers, but for image processing, PIL uses a platform-specific library (ie: _imaging.dll on Win32). Where should this go on a ZopeSite? And what is my path needs to import PIL. minimal external method for testing : #pil_test.py import os, sys import Image def pil_test(self): infile = 'animage.jpg' im = Image.open(infile) return im.size, im.format, im.mode won't work: errors as above. ..So I tried opening a simple text text file in 'Extensions' and that failed. Is this illegal?? How do I use python external method to 'open' any file.? Do I have to import htmllib or somesuch and use that to point at my ZopeSite or elsewhere? I've already tested this with loading and displaying local and remote HMTL pages in open. fun,very cool. What syntax will directly load Zope 'Image' objects into Python external methods. The zope error messages reference line 110 of Image.py and line 716 of ImageFile.py So far I 've come up with 4 possibles: 1. The namespace of Zope 'Image' is getting confused by imported PIL 'Image' 2. What I am doing is illegal 3. I am in wrong path 4. Dumb newbie typos I am very keen to get this working, so that we can get on with creating a set of nice Zope image processing methods. These can allow much friendlier end-user uploading of images with automatic linked indexes, thumbnailing, sending e-mail to user groups of images, image compositing etc. Thanks in advance for any tips - Jason Cunliffe ------------------------------------------------- Jason Cunliffe <jasonic@nomadicsltd.com> NOMADICS.STUDIO(Design Director) Geo-Digital Arts and Technology Le Vieux Moulin, Route de Mons 83440 SEILLANS, FRANCE Tel: +33 (0)4 94.76.98.72 Fax: +33 (0)4 94.76.97.77 _______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope (Related lists - please, no cross posts or HTML encoding! To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
(also see Phil Harris' post) <snip>
At present, all the PIL files are in the 'Extensions' folder, but I understand from the ZCMG that I could also put them in 'Shared'. The ZCMG says that I can create a folder in 'Shared' with company or personal name and then this will be automatically referenced by zope. What is not clear to me what name, why and what do I ave to do to tell zope about the folder name I have created there.?
The Extension folder is meant for external methods, which can do all sorts of python things and call any conceivable python package. However, for security reasons external methods are not treated as modules in the python sense. I even believe it is not legal to place your extension python code inside the Extension directory. In other words "PIL" should be somewhere outside your Extensions directory. A good place to put packages is in a subdirectory of the lib/python/Shared directory. Don't forget to include a __init__.py (may even be empty) in each of the subdirectories (see regular python documentation on www.python.org for this). Moreover, PIL has a nameclash problem with Zope and should be made in to a package (the Poll product suggests to put this in sitehome, but I did not get this to work. It worked in the Shared directory, though). <snip> good luck Rik
Great. Thanks to all who answered.. 1. Poll Product
There is a PIL friendly poll product at the old zope site (<http://www.zope.org:8080/Download/Contrib/poll.tgz>http://www.zope.org:8 080/Download/Contrib/poll.tgz) that explains what you have to do to get them both working together.
Very helpful, as it mentions the namespace conflict in the README confirmed by Rik Hoekstra. Not quite working yet, but I am sure this is the main problem. It recommends installing PIL in 'site-packages' directory. Is this an older setup, now replaced by the 'Shared' directory? Or is there a difference between Win32 and Linux Zope installations? 2. 'Extensions'
The Extension folder is meant for external methods, which can do all sorts of python things and call any conceivable python package. However, for security reasons external methods are not treated as modules in the python sense. I even believe it is not legal to place your extension python code inside the Extension directory. [..snip]
OK. so if I understand correctly: A. Python Modules go in 'Shared' with __init__.py at each sublevel there. B. Python scripts to be used as 'External Methods' by Zope go in 'Extensions'. Q1: If these python scripts want to "open" other files in the system (MIDI, Text, Image, whatever) What do they need to do? What is legal/illegal from Zope? ie: Where can these files live? Q2: To create a nice linked list of External Methods. What is the syntax for 'External Methods' similar to <dtml-in objectValues(['Folder', 'Image'])> 'ExternalMethods' or'External Methods' don't work... Is there a complete list anywhere of objectValues() and objectItems() parameters? Thanks - Jason ------------------------------------------------- Jason Cunliffe <jasonic@nomadicsltd.com> NOMADICS.STUDIO(Design Director) Geo-Digital Arts and Technology Le Vieux Moulin, Route de Mons 83440 SEILLANS, FRANCE Tel: +33 (0)4 94.76.98.72 Fax: +33 (0)4 94.76.97.77
participants (3)
-
Jason Cunliffe -
Phil Harris -
Rik Hoekstra