[Twisted-Python] Allow static.Data to be at the root

Andrew Bennetts andrew-twisted at puzzling.org
Sat Jun 21 11:18:51 EDT 2003

On Sat, Jun 21, 2003 at 01:21:30PM +0200, Matthias Urlichs wrote:
> Hi, Moshe Zadka wrote:
> > On Tue, 13 May 2003, "Matthias Urlichs" <smurf at smurf.noris.de> wrote:
> > 
> >> Here's a small patch to allow a twisted.web.static.Data element at the
> >> root of your web space.
> > 
> > This detracts functionality, not enhances it.
> > If you really want it, it's better to have a 
> > 
> > root = resource.Resource()
> > root.putChild('', static.Data('text/plain', 'hello world'))
> ... but it's OK to do essentially the same thing to t.w.static.File?
>   CVS: 2003-06-20 07:09:12
>   Make static.File used as a root resource work as expected when serving a file.
> IMHO: Please do either both, or neither.

I agree; I made this change to static.File because it worked fine as a root
resource when serving a directory, but not when serving a single file[1],
which seemed inconsistent to me.  As Matthias points out, static.Data should
be consistent with static.File (which of course should be consistent with

If someone more familiar with Twisted Web wants to undo that change because
I've misunderstood the way things are meant to work, I won't mind.  In that
case, though, I'd like to see static.File used as root resource to serve a
directory fail, or at least raise a deprecation warning.  I volunteer to
update the using-twistedweb howto to mention this restriction if this is the
way we go.


[1] Yes, I realise a web server that only serves a single file isn't very
    interesting.  This happened when a colleague at work tried to demostrate
    Twisted Web to another colleague; this behaviour was surprised them (and
    me, although I'm hardly a Twisted Web expert).  A use-case does spring
    to mind, though: a "Sorry, the site is temporarily unavailable due to
    planned maintenance" message that lives on-disk for easy editing -- when
    the maintenance is done, the root resource could be replaced with the
    real site again without restarting the server...

More information about the Twisted-Python mailing list