-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatible with static_file in bottlepy #37
Comments
So it sounds that your file object does not match the PyFile_check :-(. Which release of Fapws are you using ? |
I'm using the newest fapws3. It's compiled with python2.7-dev and the python version I'm using is also 2.7 |
I'm not a bottle's expert, neither user, but what I see in the bottle code is that:
Thus Fapws's complaints is logic. Concerning your initial comment ... return a file object must work. |
Thank you. I'll find some time to test why returning a file object didn't work. Maybe bottle's @ did something. An additional question to ask: Does HTTPResponse object conform to WSGI? |
Bottle unpacks HTTPResponse objects in Bottle._cast(). The result should be one of the following four options:
All four should be WSGI conform. |
Actually, because fapws3 does not implement Perhaps that helps. |
I've the feeling that both Fapws and bottle use the name "static file", but If I read the Bootle code, I see that static_file return an HTTPResponse In fact, Fapws treats objects responding "true" to the following: PyList_Check, Could we not get an intermediary object building the bridge between both (copy/past from http://www.python.org/dev/peps/pep-0333/) On Sat, Nov 9, 2013 at 10:50 PM, Marcel Hellkamp
|
As mentioned by @defnull, bottle will cast the HTTPResponse's body in _cast(). Since fapws3 doesn't define a wsgi.file_wrapper, the cast ends up as a WSGIFileWrapper object. This is not a file object, according to PyFile_Check (which is to be expected), but it does not pass the iterator check either, which is more surprising (since that seems to be the point of the WSGIFileWrapper class). As far as I can see, bottle's WSGIFileWrapper implements container iteration (iter() returns an iterator), whereas PyIter_Check checks for an actual iterator object. I found 2 workarounds:
(i.e. implement the necessary methods to be recognized as an iterator object) or 2:
(i.e. use the iterator object returned by iter). I'm not sure if any of these are that nice. Making fapws recognize and use a generator as well as an iterator would be nice, but I couldn't find out how. |
fapws3 will print the below line when I'm using static_file() in bottlepy
wsgi output of is neither a list, neither a fileobject, neither an iterable object!!!!!
Demo code can be found here: http://bottlepy.org/docs/dev/tutorial.html#routing-static-files
btw, return a static_file("index.html", root = ".").output which is a file object also fails. Even return an open("index.html") fails. Only return open("index.html").readlines() works.
p.s. Thank you for putting my name on the contributor list
The text was updated successfully, but these errors were encountered: