[Twisted-Python] subclassing twisted.web?
Hi, I'm playing around with some REST ideas[1], and I want to use this approach to build a web-forum-like[2] app for one of my busy content sites. I want to use a standalone, Python-based http server for this app, so I've been looking at the simple http servers in the Python lib, Zope's Z3, Medusa, and twisted.web. For various reasons[3], I'd like to try twisted.web first, but I have a few qestions -- (1) Is there a 'servlet' or other programming model to use with twisted.web? If so, is there any example code? How can I get started? In other words, how are people building Web apps with twisted.web? (2) I'm also playing around with the idea of 'ad hoc http servers', i.e., lightweight servers that do one thing and one thing well, which gets integrated into an existing site using something like Apache's mod_rewrite and mod_proxy. So if I wanted to build a specialized twisted.web that only did one thing, is there a class I can subclass or methods I can override? In other words, I want to specialize the bit(s) of twisted.web which map REQUEST.URI to a local entity; and I want to do so for particular HTTP methods (specifically, GET, POST, DELETE) and return the appropriate non-implemented HTTP response for everything else (i.e., 404 for non-existent URIs and <whatever> for the other HTTP methods). I looked at the twisted.web source briefly, but nothing leapt out at me, alas. Thanks, Kendall Clark Footnotes: [1] http://internet.conveyor.com/RESTwiki/moin.cgi [2] Yes, I looked at twisted.forum long enough to know that I can't use it; this forum app has to be fairly specialized to fit into an existing site. [3] If for no other reason, Z3 doesn't seem to have been busted out of Zope yet (as has ZODB, yay!), and I don't have the time or energy to work on that just to use it cleanly. Plus, I'm looking for reasons to use twisted.
On Mon, 2002-02-11 at 14:09, Kendall Clark wrote:
Hi,
I'm playing around with some REST ideas[1], and I want to use this approach to build a web-forum-like[2] app for one of my busy content sites. I want to use a standalone, Python-based http server for this app, so I've been looking at the simple http servers in the Python lib, Zope's Z3, Medusa, and twisted.web.
For various reasons[3], I'd like to try twisted.web first, but I have a few qestions --
(1) Is there a 'servlet' or other programming model to use with twisted.web? If so, is there any example code? How can I get started?
There are two levels of abstraction for web apps once you get past the low-level stuff: Resources, and WebWidgets, which are built on Resources. Resources are a 1:1 mapping with Requests (ie, a web request causes a single Resource to render itself). WebWidgets are more fine-grained - you can have multiple Widgets on a Page, etc. WebWidgets is the recommended tool for writing most web apps, and Resources are mainly a framework thing.
In other words, how are people building Web apps with twisted.web?
Widgets.
(2) I'm also playing around with the idea of 'ad hoc http servers', i.e., lightweight servers that do one thing and one thing well, which gets integrated into an existing site using something like Apache's mod_rewrite and mod_proxy.
So if I wanted to build a specialized twisted.web that only did one thing, is there a class I can subclass or methods I can override?
If you want, you can subclass twisted.protocols.http.HTTP directly, but I'm not sure if this would be the best way to go for you or not. I'd need to know more about what you're doing. twisted.web.server.Site subclasses the base HTTP class to add some more functionality, like "Request" objects etc, maybe take a look at that too. But like I said before, most most apps, you probably want to use WebWidgets. If you think that WebWidgets is too high-level and server.Site is too low-level, take a look at Resources.
In other words, I want to specialize the bit(s) of twisted.web which map REQUEST.URI to a local entity; and I want to do so for particular HTTP methods (specifically, GET, POST, DELETE) and return the appropriate non-implemented HTTP response for everything else (i.e., 404 for non-existent URIs and <whatever> for the other HTTP methods).
Yeah, take a look at twisted.protocols.http.HTTP and twisted.web.server.Site Any more questions, feel free to respond or ask me on IRC. -- Chris Armstrong << radix@twistedmatrix.com >> http://twistedmatrix.com/users/carmstro.twistd/
if you are building a forum-type application, I'd be interested in talking about why you think twisted.forum is inappropriate. it was intended that it could be used within an existing site, but that extensibility may not be apparent (and i know, it has no documentation). Maybe we could explore ways to make it useful to you - and more useful to other people moving forward. The database interaction layer is extremely separate from the presentation layer - it was intended that different presentation formats could access the same forum database with the web interface being just the first. -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of Kendall Clark Sent: Monday, February 11, 2002 1:09 PM To: twisted-python Subject: [Twisted-Python] subclassing twisted.web? Hi, I'm playing around with some REST ideas[1], and I want to use this approach to build a web-forum-like[2] app for one of my busy content sites. I want to use a standalone, Python-based http server for this app, so I've been looking at the simple http servers in the Python lib, Zope's Z3, Medusa, and twisted.web. For various reasons[3], I'd like to try twisted.web first, but I have a few qestions -- (1) Is there a 'servlet' or other programming model to use with twisted.web? If so, is there any example code? How can I get started? In other words, how are people building Web apps with twisted.web? (2) I'm also playing around with the idea of 'ad hoc http servers', i.e., lightweight servers that do one thing and one thing well, which gets integrated into an existing site using something like Apache's mod_rewrite and mod_proxy. So if I wanted to build a specialized twisted.web that only did one thing, is there a class I can subclass or methods I can override? In other words, I want to specialize the bit(s) of twisted.web which map REQUEST.URI to a local entity; and I want to do so for particular HTTP methods (specifically, GET, POST, DELETE) and return the appropriate non-implemented HTTP response for everything else (i.e., 404 for non-existent URIs and <whatever> for the other HTTP methods). I looked at the twisted.web source briefly, but nothing leapt out at me, alas. Thanks, Kendall Clark Footnotes: [1] http://internet.conveyor.com/RESTwiki/moin.cgi [2] Yes, I looked at twisted.forum long enough to know that I can't use it; this forum app has to be fairly specialized to fit into an existing site. [3] If for no other reason, Z3 doesn't seem to have been busted out of Zope yet (as has ZODB, yay!), and I don't have the time or energy to work on that just to use it cleanly. Plus, I'm looking for reasons to use twisted. _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
One thing of note is that if you install 0.15.0 via 'python setup.py install', it doesn't install either forum or metrics. Maybe he just didn't see it? -bob On Monday, February 11, 2002, at 09:34 PM, Sean Riley wrote:
if you are building a forum-type application, I'd be interested in talking about why you think twisted.forum is inappropriate. it was intended that it could be used within an existing site, but that extensibility may not be apparent (and i know, it has no documentation).
Maybe we could explore ways to make it useful to you - and more useful to other people moving forward.
The database interaction layer is extremely separate from the presentation layer - it was intended that different presentation formats could access the same forum database with the web interface being just the first.
-----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of Kendall Clark Sent: Monday, February 11, 2002 1:09 PM To: twisted-python Subject: [Twisted-Python] subclassing twisted.web?
Hi,
I'm playing around with some REST ideas[1], and I want to use this approach to build a web-forum-like[2] app for one of my busy content sites. I want to use a standalone, Python-based http server for this app, so I've been looking at the simple http servers in the Python lib, Zope's Z3, Medusa, and twisted.web.
For various reasons[3], I'd like to try twisted.web first, but I have a few qestions --
(1) Is there a 'servlet' or other programming model to use with twisted.web? If so, is there any example code? How can I get started?
In other words, how are people building Web apps with twisted.web?
(2) I'm also playing around with the idea of 'ad hoc http servers', i.e., lightweight servers that do one thing and one thing well, which gets integrated into an existing site using something like Apache's mod_rewrite and mod_proxy.
So if I wanted to build a specialized twisted.web that only did one thing, is there a class I can subclass or methods I can override?
In other words, I want to specialize the bit(s) of twisted.web which map REQUEST.URI to a local entity; and I want to do so for particular HTTP methods (specifically, GET, POST, DELETE) and return the appropriate non-implemented HTTP response for everything else (i.e., 404 for non-existent URIs and <whatever> for the other HTTP methods).
I looked at the twisted.web source briefly, but nothing leapt out at me, alas.
Thanks, Kendall Clark
Footnotes: [1] http://internet.conveyor.com/RESTwiki/moin.cgi
[2] Yes, I looked at twisted.forum long enough to know that I can't use it; this forum app has to be fairly specialized to fit into an existing site.
[3] If for no other reason, Z3 doesn't seem to have been busted out of Zope yet (as has ZODB, yay!), and I don't have the time or energy to work on that just to use it cleanly. Plus, I'm looking for reasons to use twisted.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Mon, Feb 11, 2002 at 09:43:16PM -0500, Bob Ippolito muttered something about:
One thing of note is that if you install 0.15.0 via 'python setup.py install', it doesn't install either forum or metrics.
Maybe he just didn't see it?
No, I did. As I said:
[2] Yes, I looked at twisted.forum long enough to know that I can't use it; this forum app has to be fairly specialized to fit into an existing site.
Best, Kendall Clark
On Mon, Feb 11, 2002 at 08:34:01PM -0600, Sean Riley muttered something about:
if you are building a forum-type application, I'd be interested in talking about why you think twisted.forum is inappropriate. it was intended that it could be used within an existing site, but that extensibility may not be apparent (and i know, it has no documentation).
Don't take what I said as a criticism; it's not. It won't work for what I need but that's a function of my idiosyncratic needs, not the quality of twisted.forum. Further, as I said, I'm *also* experimenting with the REST (and ad hoc httpd server) ideas, so that I want to build the app out of GET, POST, DELETE, and HEAD HTTP methods. (In other words, I asked a pointed question because I know what I want to do, but I don't know how to do it with Twisted.) But I may steal some ideas from the way you deal with data storage. Thanks. Kendall Clark
participants (4)
-
Bob Ippolito -
Christopher Armstrong -
Kendall Clark -
Sean Riley