Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Warning: Cannot modify header information - headers already sent by (output started at /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php:564) in /var/hostings/98tau0417/dfwpython.org/pmwiki/pmwiki.php on line 1075
The Dallas Ft. Worth Pythoneers | TwistedNotes / WebService
SearchWiki:
  11 User(s) Active on Site
  233 Wiki Pages

Most Recently Modified

Club Resources (edit)

How This Wiki Works

Meeting space complements of:
Computer books
            and technical books at discount prices
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 Service

The 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

  • HTTP Channel objects
  • HTTP Request object
  • Site object
  • Resource objects

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 Templating

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

  • XHTML templates?: contain no programming logic, only nodes tagged with nevow attributes
  • data/render methods: simplified MVC
  • stan: An s-expression-like syntax for expressing xml in pure python
  • formless: For describing the types of objects which may be passed to methods of your classes, validating and coercing string input from either web or command-line sources, and calling your methods automatically once validation passes
  • formless.webform: For rendering web forms based on formless type descriptions, accepting form posts and passing them to formless validators, and rendering error forms in the event validation fails
  • livepage: Cross-browser JavaScript? glue for sending client side events to the server and server side events to the client after the page has loaded, without causing the entire page to refresh

Documentation on Twisted and Nevow is not always easy to find. Here are some starting places.

Nevow

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:

from nevow import entities as E

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 Strategies

User Identities

User Grouping

Access Rights


Session Persistence

Session 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