[Twisted-web] Problems with web2.test.test_static.TestFileSaver

James Y Knight foom at fuhm.net
Mon Nov 7 21:52:15 MST 2005

On Nov 7, 2005, at 1:40 AM, Wilfredo Sánchez Vega wrote:
>   web2.test.test_static.TestFileSaver has been failing on my DAV  
> branch.  dreid and I were looking into it at SHDH and were  
> generally baffled by the breakage.
>   I remain baffled, but have managed to figure out that the test  
> isn't breaking due to the addition of code, but by the simple  
> existence of the test modules in my code.  I can reproduce the  
> problem in trunk by doing the following:

First let me apologize for not being around this weekend, I would  
have liked to help out, but I've had a nasty fever and have basically  
been sleeping.

Anyhow, I can solve this mystery for you. It is caused by the reload 
() of twisted.web2.http_headers in twisted/web2/test/__init__.py.  
That causes twisted.web2.http_headers.MimeType to be a new class, but  
the old instances created in static.FileSaver.allowedTypes still  
pointed to the old class. Thus the "File type not allowed" bit.

It is fixed by using twisted.python.rebuild.rebuild() instead, which  
updates said references. Except that rebuild doesn't seem to rebuild  
instances of oldstyle classes. So I updated the classes to be  
newstyle, which they should be anyhow.

The reason for the odd output is that the test case used data 
[data.find(...)+11:data.find(...)]. If find fails, it returns -1. As  
the MimeType passed was not in the allowed set, the file was not  
being saved and the output was not as expected. Fixed that to  
use .index instead so it fails more obviously.


More information about the Twisted-web mailing list