Thank you Jason! That was it. (doh! late nights.... )
For anyone else who runs into that down the road, when calling the
StaticFile instance it needs the request object... (funny considering todays
thread on the topic). So this works:
def test(req):
path = "/images/some_photo.gif"
graphic = StaticFile(path, mime_type="image/gif")
return graphic(req) # Call the StaticFile instance, and return THAT.
Thanks again...
-Charles.
----- Original Message -----
From: "Jason Sibre"
To: "Charles Brandt" ;
Sent: Friday, November 05, 2004 7:39 AM
Subject: RE: [Quixote-users] StaticFile cast as str in function return
> Hiya,
>
> StaticFile is intended to be called. That's what happens when you use it
as
> described in the docs. During traversal, something will return a
StaticFile
> instance, and then the publisher calls the StaticFile. (That's what
happens
> in the case where it's assigned to a variable, and _q_exports mentions
that
> variable.)
>
>
> Try this:
> def test(req):
> path = "/images/some_photo.gif"
> graphic = StaticFile(path, mime_type="image/gif")
> return graphic() # Call the StaticFile instance, and return THAT.
>
>
> Hope that helps,
> Jason
>
>
> > -----Original Message-----
> > From: quixote-users-bounces@mems-exchange.org
> > [mailto:quixote-users-bounces@mems-exchange.org]On Behalf Of Charles
> > Brandt
> > Sent: Friday, November 05, 2004 2:11 AM
> > To: quixote-users@mems-exchange.org
> > Subject: [Quixote-users] StaticFile cast as str in function return
> >
> >
> > 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.
>
>
> _______________________________________________
> Quixote-users mailing list
> Quixote-users@mems-exchange.org
> http://mail.mems-exchange.org/mailman/listinfo/quixote-users
>
>