Ticket #3903 (closed defect: invalid)
Resource routing can't handle empty paths
| Reported by: | jpsimons | Owned by: | jknight |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | web | Keywords: | |
| Cc: | Branch: | ||
| Author: | Launchpad Bug: |
Description
class HelloWorld(resource.Resource):
def render_GET(self, request):
return "<html>Hello World</html>"
site = server.Site(HelloWorld())
This simple example just doesn't work, it returns "Resource not found" if you go to localhost:8080. You can work around it by setting isLeaf = True, but then no subdirectories show up. The fix is this, in twisted/web/server.py, on line 147:
- self.postpath = map(unquote, string.split(self.path[1:], '/')) + self.postpath = [] + if len(self.path[1:]): + self.postpath = map(unquote, string.split(self.path[1:], '/'))
Because in Python, "".split("/") returns [""] instead of [] like one might expect. You'd want the empty array in this case so web.resource.getChildForRequest() will do the right thing and just return the original resource instead of falling back to getChild().
Change History
Note: See
TracTickets for help on using
tickets.
