Serving different resource types from the same directory
On dim, 27 nov 2005, at 16:18, oli wrote: I'm trying to serve 2 different kind of resources from the same directory. I can, with no problem, serve one kind or the other but not the two resource types at the same time. Examples abounds on the web on how to serve one kind of resources from subdirectory /foo and another kind from subdirectory /bar. But no example on how to serve different kind of resources from the same directory. Here is how I tried: # [...] PATH = '/var/www/' pt_resource = static.File(PATH) pt_resource.processors = { '.pt' : PTResource } pt_resource.indexNames = [ 'index' + '.pt' ] rst_resource = static.File( PATH ) rst_resource.processors = { '.rst' : RSTResource } rst_resource.indexNames = [ 'index' + '.rst' ] #root = Resource() # I tried this too root = static.File(PATH) root.putChild(PATH, pt_resource) root.putChild(PATH, rst_resource) reactor.listenTCP( 80, server.Site( root ) ) reactor.run( ) # this is the end What's wrong ? What did I forget ? Is it possible ? Thank you. -- Olivier Laurent
On Sun, 27 Nov 2005 18:12:54 +0100, Olivier Laurent <olilau.list.1@gmail.com> wrote:
On dim, 27 nov 2005, at 16:18, oli wrote: I'm trying to serve 2 different kind of resources from the same directory. I can, with no problem, serve one kind or the other but not the two resource types at the same time.
Examples abounds on the web on how to serve one kind of resources from subdirectory /foo and another kind from subdirectory /bar. But no example on how to serve different kind of resources from the same directory.
Here is how I tried:
# [...]
PATH = '/var/www/'
pt_resource = static.File(PATH) pt_resource.processors = { '.pt' : PTResource } pt_resource.indexNames = [ 'index' + '.pt' ]
rst_resource = static.File( PATH ) rst_resource.processors = { '.rst' : RSTResource } rst_resource.indexNames = [ 'index' + '.rst' ]
#root = Resource() # I tried this too root = static.File(PATH)
root.putChild(PATH, pt_resource) root.putChild(PATH, rst_resource)
reactor.listenTCP( 80, server.Site( root ) ) reactor.run( ) # this is the end
What's wrong ? What did I forget ? Is it possible ?
"/var/www/" does not make sense as the first argument to putChild(). Someone would have to request "%2fvar%2fwww%2f" to get anything at that location. Also, you cannot pass the same path to putChild() twice and expect both resources to figure out what to do. Fortunately, you do not appear to need two resources. I think you are looking for something like this: root = static.File(PATH) root.processors = {'.pt': PTResource, '.rst': RSTResource} root.indexNames = ['index.rst', 'index.pt'] reactor.listenTCP(80, server.Site(root)) reactor.run() Jean-Paul
On 11/27/05, Olivier Laurent <olilau.list.1@gmail.com> wrote:
Here is how I tried:
# [...]
PATH = '/var/www/'
pt_resource = static.File(PATH) pt_resource.processors = { '.pt' : PTResource } pt_resource.indexNames = [ 'index' + '.pt' ]
rst_resource = static.File( PATH ) rst_resource.processors = { '.rst' : RSTResource } rst_resource.indexNames = [ 'index' + '.rst' ]
#root = Resource() # I tried this too root = static.File(PATH)
root.putChild(PATH, pt_resource) root.putChild(PATH, rst_resource)
The point of the resource name is to differenciate it from its siblings. If you give the same name to both of course it does not work. Moreover, I don't think '/var/www/' a valid resource name. Either use different "logical" names for each File, or use different processors for a single File. I think you want something like: my_resource = static.File(PATH) my_resource.processors = { '.pt' : PTResource, '.rst' : RSTResource} my_resource.indexNames = [ 'index.pt', 'index.rst' ] root.putChild('foo', my_resource) Eric.
On 27/11/05, Eric Faurot <eric.faurot@gmail.com> wrote:
On 11/27/05, Olivier Laurent <olilau.list.1@gmail.com> wrote:
[...]
The point of the resource name is to differenciate it from its siblings. If you give the same name to both of course it does not work. Moreover, I don't think '/var/www/' a valid resource name. Either use different "logical" names for each File, or use different processors for a single File.
I think you want something like:
my_resource = static.File(PATH) my_resource.processors = { '.pt' : PTResource, '.rst' : RSTResource}
That's it. One resource with several processors. Thank you very much. -- Olivier Laurent
participants (3)
-
Eric Faurot
-
Jean-Paul Calderone
-
Olivier Laurent