[Twisted-Python] [Twisted.Web] How to access root resource without .rpy file?

Moshe Zadka m at moshez.org
Mon May 12 04:23:07 EDT 2003


On Mon, 12 May 2003, Stuart Hungerford <stuart.hungerford at anu.edu.au> wrote:

> Later I plan to offer URL's at that address like:
> 
>       http://example.org:8080/project/service1
>       http://example.org:8080/project/service2?param=1
<snip>
> I understand that I could create a project.rpy file which creates
> a resource but I need to use the unadorned resource names above
> rather than http://example.org:8080/project/project.rpy

This is why Twisted Web supports ignoring extension. I'm not sure how
you're deploying your server. If you are writing a configuration file
by hand you can do something like:

"""
from twisted.internet import app
from twisted.web import static, server, script

root = static.File("/serve/example")
root.processors = {'.rpy': script.ResourceScript}
root.ignoreExt('.rpy')
application = app.Application('web')
application.listenTCP(8080, server.Site(root)
"""

If you use mktap,
% mktap web --path=/serve/example --ignore-ext=.rpy --port=8080
should work.

Of course, in the first example, you could use explicit putChild:

"""
from twisted.internet import app
from twisted.web import static, server, script
import myCode

root = static.File("/serve/example")
root.putChild('project', myCode.ResourceIntendedForProject())
application = app.Application('web')
application.listenTCP(8080, server.Site(root)
"""

Since you've given no further data, it is hard to guess which of those
option best applies to you. I wish to further mention that if you use
Debian, the twisted-web can give you some more options, depending on your
security concern. For example, merely dropping in /etc/twisted-web/local.d
a file called "99addproject.py" with contents

"""
import myCode
default.putChild('project', myCode.ResourceIntendedForProject())
"""

would work.

-- 
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/




More information about the Twisted-Python mailing list