[Twisted-Python] Allow static.Data to be at the root
![](https://secure.gravatar.com/avatar/6f6f30040a0a4dbb6032ea4acdffbd6b.jpg?s=120&d=mm&r=g)
Here's a small patch to allow a twisted.web.static.Data element at the root of your web space. diff -Nru a/twisted/web/static.py b/twisted/web/static.py --- a/twisted/web/static.py Tue May 13 10:22:32 2003 +++ b/twisted/web/static.py Tue May 13 10:22:32 2003 @@ -59,6 +59,12 @@ request.setHeader("content-length", len(self.data)) return '' return self.data + + def getChild(self,path,request): + """Return myself if I am the root.""" + if path == '' and request.path == "/": + return self + return resource.Resource.getChild(self,path,request) def addSlash(request): host = request.getHeader("host") -- Matthias Urlichs | {M:U} IT Consulting @ m-u-it.de | smurf@smurf.noris.de Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de -- "I believe in eight of the ten commandments; and I believe in going to church every Sunday unless there's a game on." [Steve Martin]
![](https://secure.gravatar.com/avatar/3477a9de290ec6d77129af504faa1c0b.jpg?s=120&d=mm&r=g)
On Tue, 13 May 2003, "Matthias Urlichs" <smurf@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')) -- Moshe Zadka -- http://moshez.org/ Buffy: I don't like you hanging out with someone that... short. Riley: Yeah, a lot of young people nowadays are experimenting with shortness. Agile Programming Language -- http://www.python.org/
![](https://secure.gravatar.com/avatar/6f6f30040a0a4dbb6032ea4acdffbd6b.jpg?s=120&d=mm&r=g)
Hi, Moshe Zadka wrote:
... 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. -- Matthias Urlichs | {M:U} IT Design @ m-u-it.de | smurf@smurf.noris.de Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de -- The State of California has no business subsidizing intellectual curiosity. -- Ronald Reagan
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Sat, Jun 21, 2003 at 01:21:30PM +0200, Matthias Urlichs wrote:
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 itself!). 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. -Andrew. [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...
![](https://secure.gravatar.com/avatar/3477a9de290ec6d77129af504faa1c0b.jpg?s=120&d=mm&r=g)
On Tue, 13 May 2003, "Matthias Urlichs" <smurf@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')) -- Moshe Zadka -- http://moshez.org/ Buffy: I don't like you hanging out with someone that... short. Riley: Yeah, a lot of young people nowadays are experimenting with shortness. Agile Programming Language -- http://www.python.org/
![](https://secure.gravatar.com/avatar/6f6f30040a0a4dbb6032ea4acdffbd6b.jpg?s=120&d=mm&r=g)
Hi, Moshe Zadka wrote:
... 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. -- Matthias Urlichs | {M:U} IT Design @ m-u-it.de | smurf@smurf.noris.de Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de -- The State of California has no business subsidizing intellectual curiosity. -- Ronald Reagan
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Sat, Jun 21, 2003 at 01:21:30PM +0200, Matthias Urlichs wrote:
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 itself!). 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. -Andrew. [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...
participants (3)
-
Andrew Bennetts
-
Matthias Urlichs
-
Moshe Zadka