[Twisted-Python] Getting Stories Straight (RPYs)

Moshe Zadka m at moshez.org
Tue Jun 24 06:39:52 EDT 2003


On Tue, 24 Jun 2003, Andrew Bennetts <andrew-twisted at puzzling.org> wrote:

> Just to elaborate a little on what Moshe said, notice what function the RPY
> in Moshe's example is serving here: *it's a configuration file*.  It's not a
> place for arbitrary code and logic, it's merely somewhere you configure a
> predefined Resource class.
> 
> [Someone please correct me if I'm wrong!]

Well, in my example, it was a configuration file. It could easily have
been the place of "arbitrary" code:

"""
d = {}
execfile("/etc/myblog.py", d)
from blog import buildBlogResource
resource = buildBlogResource(**d)
"""

And have /etc/myblog.py look like

"""
name="Moshe"
colorScheme="RED"
articles=10
lines=20
"""

The .rpy file, more than a configuration file, is a "place indicator" --
it is a link back from the filesystem (which, in the Twisted.Web view,
is just a particularily ugly resource hierearchy) back into a "nice" resource
hierarchy. It's just that the filesystem is very easy to use for "static"
resources. The RPY file is a *deployment* choice. Deployment often
ties in with configuration: sometimes intimately (as in my original
example) and sometimes not so intimately (like in this example, where
the configuration is in a different file).

You can also do even less trivial things in the RPY:

"""
import ConfigParser
config = ConfigParser.ConfigParser("/etc/myblog.ini")
from blog import buildBlogResource
resource = buildBlogResource(config.get("name"), config.getint("articles"),
                             config.getint("lines"), config.get("colorScheme"))
"""

You can choose whether to put cache() at the top or not, etc. etc.

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