[Twisted-web] Application variables?

Rilee, Robert Robert.Rilee at dhs.gov
Thu Apr 1 14:01:02 MST 2004

When a client interacts with my program by requesting resources, I feel that these resources should be able to manipulate data stored in my program's memory. For example, my script files (.rpy) follow this pattern:

# a.rpy

import A as X

if __debug__:

resource = X.MyResource()

# A.py

from twisted.web import resource

class MyResource(resource.Resource):
    def render(self, request):
        # generate content
        # shove it in variable, say, my_content
        return my_content

# my_server.py

from twisted.application import internet
from twisted.application import service
from twisted.web import static
from twisted.web import server
from twisted.web import script
from twisted.internet import reactor

application = service.Application('web')

sc = service.IServiceCollection(application)

root = static.File("c:/wwwroot")
root.processors = {'.rpy': script.ResourceScript}
site = server.Site(root)

i = internet.TCPServer(8080, site)

reactor.listenTCP(8080, site)

Okay, so I run my program from the command line as:

$ python my_server.py

Everything seems to work. Now suppose I have b.rpy, c.rpy, d.rpy, etc. (and corresponding modules: B.py, C.py, D.py, etc.). I want all of these resources to be able to share and manipulate the same data (from memory, not disk) between requests. Now that I think about it, the term "application" is vague. In my post, application should be taken to mean a set or collection of web pages (or resourses using twisted's vocabulary), but I guess it can also be taken mean the program, "my_server.py". I appreciate you taking an interest in this.

> -----Original Message-----
> From: Michal Pasternak [mailto:michal at pasternak.w.lub.pl]
> Sent: Thursday, April 01, 2004 2:10 PM
> To: twisted-web at twistedmatrix.com
> Subject: Re: [Twisted-web] Application variables?
> Rilee, Robert [Thu, Apr 01, 2004 at 11:46:17AM -0500]:
> > How does one share "application data" between requested 
> scripts (or should I
> > say resources)?
> And what "application data" is for you?
> -- 
> Michal Pasternak :: http://pasternak.w.lub.pl :: http://winsrc.sf.net
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

More information about the Twisted-web mailing list