How do I return an actual image file from within a Python Script? return context.restrictedTraverse('/LDML/images/ldml.gif') Gives me: <img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" /> But what I actually want to do is return the file itself. Think Python Script as symbolic link. Sorry, must be v. easy but I've been thrashing around on various sites for about an hour now and I'm getting no closer. TIA Simon Forster
Hi, On Tue, 2004-12-14 at 13:28 +0000, Simon Forster wrote:
How do I return an actual image file from within a Python Script?
return context.restrictedTraverse('/LDML/images/ldml.gif')
Gives me:
<img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" />
But what I actually want to do is return the file itself. Think Python Script as symbolic link.
Sorry, must be v. easy but I've been thrashing around on various sites for about an hour now and I'm getting no closer.
return str(context.restrictedTraverse('/LDML/images/ldml.gif')) btw. you dont need to give suffixes to images in Zope :-) Regards Tino
On 14 Dec 2004, at 14:03, Tino Wildenhain wrote:
Hi,
On Tue, 2004-12-14 at 13:28 +0000, Simon Forster wrote:
How do I return an actual image file from within a Python Script?
return context.restrictedTraverse('/LDML/images/ldml.gif')
Gives me:
<img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" />
But what I actually want to do is return the file itself. Think Python Script as symbolic link.
Sorry, must be v. easy but I've been thrashing around on various sites for about an hour now and I'm getting no closer.
return str(context.restrictedTraverse('/LDML/images/ldml.gif'))
btw. you dont need to give suffixes to images in Zope :-)
Regards Tino
Sorry. Obviously didn't make myself clear. return context.restrictedTraverse('/LDML/images/ldml.gif') gives me the string <img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" /> But what I'm after is the actual binary image file. How do I get this? Thanks Simon Forster _____________________________________________________ LDML Ltd, 62 Pall Mall, London, SW1Y 5HZ, UK Tel: +44 (0)870 1999 780 Fax: +44 (0)70 9230 5247 _____________________________________________________
Simon Forster wrote:
return context.restrictedTraverse('/LDML/images/ldml.gif')
gives me the string
<img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" />
But what I'm after is the actual binary image file. How do I get this?
rewrite the line to this:: img=context.restrictedTraverse('/LDML/images/ldml.gif') return img() Michael -- http://zope.org/Members/d2m
Michael Haubenwallner wrote:
Simon Forster wrote:
return context.restrictedTraverse('/LDML/images/ldml.gif')
gives me the string
<img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" />
But what I'm after is the actual binary image file. How do I get this?
rewrite the line to this::
img=context.restrictedTraverse('/LDML/images/ldml.gif') return img()
Michael
Sorry, this is wrong. I have hit the send-key too early. Michael -- http://zope.org/Members/d2m
On Tue, 2004-12-14 at 14:38 +0000, Simon Forster wrote:
On 14 Dec 2004, at 14:03, Tino Wildenhain wrote:
Sorry. Obviously didn't make myself clear.
return context.restrictedTraverse('/LDML/images/ldml.gif')
gives me the string
<img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title="" height="120" width="120" border="0" />
But what I'm after is the actual binary image file. How do I get this?
Sorry, I was with File, since str(zopefileobject) gives you its data. Image is a bit different and renders just the tag on __str__. Image.data then (like in the other posts) but this might be not the most performant way to do it with respect to later versions of zope. But currently, it is. Regards Tino
btw. you dont need to give suffixes to images in Zope :-)
IMHO *not* giving suffixes is confusing and bad. Everyone else on the internet uses extensions, and the fact that Zope can do without them is not a good reason to drop them... jens
On Tue, 2004-12-14 at 15:39 +0100, Jens Vagelpohl wrote:
btw. you dont need to give suffixes to images in Zope :-)
IMHO *not* giving suffixes is confusing and bad. Everyone else on the internet uses extensions, and the fact that Zope can do without them is not a good reason to drop them...
I highly disagree. Filetype is inherent to the file. The suffix is just opaque and a relict of old operanding systems. I personally dont care on "anyone in the internet" because most people there have no clue at all :-) See the many references to index.html on sites. Even Apache can do without (visible) suffixes. Not using suffixes has a lot of advantages in Zope: you dont need to write container['file.suffix'] or getattr(). And you can freely swap filecontents without changing the name all the time. For example if you swap the .gif with a .png or .jpg where appropriate. Regards Tino
I highly disagree. Filetype is inherent to the file. The suffix is just opaque and a relict of old operanding systems. I personally dont care on "anyone in the internet" because most people there have no clue at all :-) See the many references to index.html on sites.
Even Apache can do without (visible) suffixes.
Not using suffixes has a lot of advantages in Zope: you dont need to write container['file.suffix'] or getattr(). And you can freely swap filecontents without changing the name all the time. For example if you swap the .gif with a .png or .jpg where appropriate.
Let's agree to totally disagree. I personally have gone back to using real extensions on all my own stuff as I re-do it. Not only are things more obvious, I'm also helping log analysis tools and search engines that way. I also never saw a situation where it was important that something like an image retain its (extensionless) name across image format changes. Thirdly, code that uses direct attribute access like "context.myfile" gives me the heebie-jeebies :) jens
participants (4)
-
Jens Vagelpohl -
Michael Haubenwallner -
Simon Forster -
Tino Wildenhain