|
|
11 User(s) Active on Site 233 Wiki Pages Most Recently Modified
Club Resources (edit)
How This Wiki Works
Check them out; they are a great source of technical books at very good prices! If you have shopped at Nerdbooks.com, help them out by reviewing them at ResellerRatings.com. You will need your invoice number to prove you are a real customer, and not just ballot stuffing. |
|||
| Recent Changes Printable View Page History Edit Page | |||
|
Content Last Modified on October 03, 2005, at 04:00 AM CST
The Twisted Web ServiceThe Twisted Web Service consists of a server component that participates in the HyperText Transfer Protocol (HTTP) and a set of supporting components for file delivery, HTML templating, access control, session persistence and so forth. HTTP Server
Site objects:Site objects serve as the glue between a port on which to list for HTTP request, and a Resource object that represents the root component of a URL. They parse the HTTP request and begin the object lookup process. Sites are factory objects. Note that one factory (in this case, a site) can listen on multiple ports with multiple protocols. from twisted.web import server, resource from twisted.internet import reactor <:vspace> class Simple(resource.Resource): isLeaf = True def render_GET(self, request): return "<html>Hello, world!</html>" <:vspace> site = server.Site(Simple()) reactor.listenTCP(8080, site) reactor.run() Resource objects:Resource objects represent one segment or path component of a URL. There is always at least one to represent the URL root. During URL parsing, the getChild method is called on the current Resource to produce the next Resource object. When the leaf Resource is reached, either because there were no more URL segments or a Resource had isLeaf set to True, the leaf Resource is rendered by calling the render method. During the Resource location process, the URL segments which have already been processed and those which have not yet been processed are available in request.prepath and request.postpath. A Resource can know where it is in the URL tree by looking at request.prepath, a list of URL segment strings. A Resource can know which path segments will be processed after it by looking at request.postpath. If the URL ends in a slash, for example "http://example.com/foo/bar/" , the final URL segment will be an empty string. Resources can thus know if they were requested with or without a final slash. from twisted.web.resource import Resource <:vspace> class Hello(Resource): def getChild(self, name, request): if name == '': return self return Resource.getChild(self, name, request) <:vspace> def render_GET(self, request): return """<html>Hello, world! I am located at %r.</html>""" % request.prepath <:vspace> resource = Hello() HTML TemplatingNevow is a next-generation web application templating system, based on the ideas developed in the Twisted Woven package. Its main focus is on separating the HTML template from both the business logic and the display logic, while allowing the programmer to write pure Python code as much as possible. It separates your code into 'data' and 'render' functions, a simplified implementation of traditional MVC. It has various parts which can be used individually or as a whole, integrated web solution:
Documentation on Twisted and Nevow is not always easy to find. Here are some starting places. Nevow Manual(approve sites) Nevow Wiki(approve sites) Nevow Manual omits how to do HTML entities in stan. Jeff says he discovered how to do this:
For instance, to create an HTML ampersand entity, use E.amp. You can use dir(E) to see a list of available entities. Access Control StrategiesUser IdentitiesUser GroupingAccess RightsSession PersistenceSession objects allow for the storage of information across multiple requests. Each individual browser using the system has a unique Session instance. |
|||
| Recent Changes Printable View Page History Edit Page | |||