Resource routing can't handle empty paths

[email protected]
Newsgroups gmane.comp.python.twisted.bugs
Message-ID <[email protected]>
New submission from jpsimons <None>:

{{{
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().




----------
Type     : defect
Component: web
Keywords : 
Priority : normal
Nosy     : 
----------
http://twistedmatrix.com/trac/ticket/3903
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.