Hello,
I'm having trouble returning an instance of a StaticFile from a function.
When I do this, the instance gets cast as a string and all that is returned
to the browser is:
(This is only visible upon viewing the source, and this is all that is in
the resulting page source. No actual error is raised)
An example that yields the above result for me:
_q_exports = ["test"]
def test(req):
path = "/images/some_photo.gif"
graphic = StaticFile(path, mime_type="image/gif")
return graphic
My theory is that this is happening in the set_body function in
quixote.http_response if it doesn't recognize StaticFile as an instance of a
Stream object.
def set_body(self, body):
"""set_body(body : any)
Sets the return body equal to the argument "body". Also updates the
"Content-length" header if the length is of the body is known. If
the "Content-type" header has not yet been set, it is set to
"text/html".
"""
if isinstance(body, Stream):
self.body = body
if body.length is not None:
self.set_header('content-length', body.length)
else:
self.body = str(body)
self.set_header('content-length', len(self.body))
if not self.headers.has_key('content-type'):
self.set_header('content-type', 'text/html; charset=iso-8859-1')
>>> from quixote.util import StaticFile
>>> s = StaticFile("/tmp/temp.txt")
>>> from quixote.http_response import Stream
>>> if isinstance(s, Stream):
.... print "IT IS!"
....
>>> if isinstance(s, StaticFile):
.... print "IT IS!"
....
IT IS!
>>> str(s)
''
This only happens as a return value of a function. I can use StaticFiles in
the way described in doc/static-files.txt. This does work when the
StaticFile is assigned to a variable and _q_exports returns the variable,
but not when StaticFile is the return value of a function.
I think this is a similar problem that was mentioned in this thread, but the
proposed solution of setting "COMPRESS_PAGES = 0" did not fix the problem
for me.
http://mail.mems-exchange.org/pipermail/quixote-users/2004-January/002431.html
I am using quixote with Apache 1.3 and SCGI 1.2a2, but I think this is
happening further up the processing chain.
Any ideas? TIA!
-Charles.