[Zope] External methods and images

Tony McDonald tony.mcdonald@ncl.ac.uk
Fri, 7 May 1999 16:49:55 +0100


Hi,
I have an external method that gets an image from a directory (ie the 
image is *not* in the ZODB) and then adds the correct headers to 
display it to the browser.

Trouble is, it don't work.

The code is...
def img(self, RESPONSE, src):
	import os
	img_dir = '/home/nnle/zope/Zope-1.11.0pr1-src/Images'

	img_name=os.path.join(img_dir, src)

	# Determine the ad type
	img_type=image_type(img_name)

	# Open ad file, using 'rb' to open it in binary mode!
	img_file=open(img_name, 'rb')
	img_data=img_file.read()
	img_file.close()

	# Set the content-type of the response
	RESPONSE.setHeader('content-type', img_type)
	return img_data

The DTML that calls it is
<img src='<!--#var expr="img('s1cb_p0000001.gif')"-->'>  (normally 
the image name will not be there - it is got from another external 
method)
and the traceback is

<!--
[snipped]
   File 
/home/nnle/zope/Zope-1.11.0pr1-src/lib/python/DocumentTemplate/DT_Util 
.py, line 315, in eval
     (Object: img('s1cb_p0000001.gif'))
   File &lt;string&gt;, line 0, in ?
   File 
/home/nnle/zope/Zope-1.11.0pr1-src/lib/python/Products/ExternalMethod/ 
ExternalMethod.py, line 248, in __call__
     (Object: img)
     (Info: (('s1cb_p0000001.gif',), {}, None))
   File 
/home/nnle/zope/Zope-1.11.0pr1-src/lib/python/Products/ExternalMethod/ 
ExternalMethod.py, line 236, in __call__
     (Object: img)
     (Info: (('s1cb_p0000001.gif',), {}, None))
TypeError: (see above)

-->

I've tried <img src='<!--#var 
expr="img(src='s1cb_p0000001.gif')"-->'>, and I get
<!--
[snipped]
/home/nnle/zope/Zope-1.11.0pr1-src/lib/python/Products/ExternalMethod/ 
ExternalMethod.py, line 248, in __call__
     (Object: img)
     (Info: ((), {'src': 's1cb_p0000001.gif'}, None))
   File 
/home/nnle/zope/Zope-1.11.0pr1-src/lib/python/Products/ExternalMethod/ 
ExternalMethod.py, line 236, in __call__
     (Object: img)
     (Info: ((), {'src': 's1cb_p0000001.gif'}, None))
TypeError: (see above)

-->

anyone got any ideas? This is driving me batty.

TIA
Tone
------
Dr Tony McDonald,  FMCC, Networked Learning Environments Project
The Medical School, Newcastle University Tel: +44 191 222 5888
Fingerprint: 3450 876D FA41 B926 D3DD  F8C3 F2D0 C3B9 8B38 18A2