[Commits] python.it commit r203 - twisted/trunk/contrib/nevow/doc/txt

commit a svn.python.it commit a svn.python.it
Sab 29 Lug 2006 13:32:28 CEST


Author: manlio
Date: Sat Jul 29 13:32:11 2006
New Revision: 203

Added:
   twisted/trunk/contrib/nevow/doc/txt/nevow-authentication.txt   (contents, props changed)
   twisted/trunk/contrib/nevow/doc/txt/nevow-context.txt   (contents, props changed)
   twisted/trunk/contrib/nevow/doc/txt/nevow-rendering-base.txt   (contents, props changed)
Modified:
   twisted/trunk/contrib/nevow/doc/txt/nevow-deployment.txt
Log:
ancora aggiunte, correzioni e segnaposto

Added: twisted/trunk/contrib/nevow/doc/txt/nevow-authentication.txt
==============================================================================
--- (empty file)
+++ twisted/trunk/contrib/nevow/doc/txt/nevow-authentication.txt	Sat Jul 29 13:32:11 2006
@@ -0,0 +1,5 @@
+How to authenticate users
+=========================
+
+XXX TODO
+

Added: twisted/trunk/contrib/nevow/doc/txt/nevow-context.txt
==============================================================================
--- (empty file)
+++ twisted/trunk/contrib/nevow/doc/txt/nevow-context.txt	Sat Jul 29 13:32:11 2006
@@ -0,0 +1,8 @@
+What about context?
+===================
+
+XXX TODO 
+
+Explain what is deprecated and what is going away.
+However document all things since they are needed to understand old
+code or for resolve problems with the actual version of Nevow.

Modified: twisted/trunk/contrib/nevow/doc/txt/nevow-deployment.txt
==============================================================================
--- twisted/trunk/contrib/nevow/doc/txt/nevow-deployment.txt	(original)
+++ twisted/trunk/contrib/nevow/doc/txt/nevow-deployment.txt	Sat Jul 29 13:32:11 2006
@@ -16,6 +16,8 @@
 * `WSGI`_: A more complete and flexible way for deploying on many HTTP servers
 * `Twisted.Web`_: A standalone application server process which includes a built-in HTTP server
 * `Zomne`_: A small CGI which hands off HTTP requests to a long-running application server process, similar to FastCGI or SCGI
+* `Lighttpd`_
+* `Application Layout`_
 
 CGI
 ---
@@ -186,6 +188,47 @@
   /Users/dp/Projects/Nevow:/Users/dp/Projects/helloworld
   ^D
 
+Lighttpd
+========
+
+Usually your site has both static and dynamic content.
+For dynamic content Nevow is the best solution, but for static content
+it can be better to have a fast HTTP server like Lighttp (that, like
+Twisted, is an asynchronous server, written in C).
+
+XXX TODO:
+
+  add some benchmark to show when it is worth to use Lighttp to serve
+  static content.
+
+  There is a tradeof beetwen nevow.static.File performance and
+  mod_proxyy overhead.
+
+ 
+configuration for Lighttpd
+--------------------------
+
+Just copy from http://divmod.org/trac/wiki/DivmodNevow/Deployment/ReverseProxy
+
+
+Application Layout
+==================
+
+How to organize your application?
+
+Example::
+
+  /ProjectName
+  /packagename
+    /static
+      /css
+      /js
+      /images
+    module1.py
+    module2.py
+    ... 
+
+
 Conclusion
 ==========
 

Added: twisted/trunk/contrib/nevow/doc/txt/nevow-rendering-base.txt
==============================================================================
--- (empty file)
+++ twisted/trunk/contrib/nevow/doc/txt/nevow-rendering-base.txt	Sat Jul 29 13:32:11 2006
@@ -0,0 +1,225 @@
+Nevow Object Publishing II
+==========================
+
+Object Rendering Basics
+-----------------------
+
+The Nevow *object traversal* and *object publishing*
+machinery uses only two methods to locate an object suitable for publishing and
+to generate the HTML from it; these methods are described in the interface
+``nevow.inevow.IResource``::
+
+
+  class IResource(compy.Interface):
+      def locateChild(self, ctx, segments):
+          """Locate another object which can be adapted to IResource
+          Return a tuple of resource, path segments
+          """
+
+      def renderHTTP(self, ctx):
+          """Render a request
+          """
+
+``locateChild`` is described in detail in Nevow Object Traversal.
+
+``renderHTTP`` is the base function that is responsible for rendering a
+resource. It simply returns a string of HTML.
+
+Here is a simple example::
+
+  from zope.interface import implements
+
+  class SimpleRoot(object):
+      implements(inevow.IResource)
+
+      def locateChild(self, ctx, segments):
+          return self, ()
+
+      def renderHTTP(self, ctx):
+          return "Hello, world!"
+
+This will produce a response like::
+
+ Transfer-encoding: chunked
+ Date: Tue, 30 May 2006 10:55:33 GMT
+ Content-type: text/html; charset=UTF-8
+ Server: TwistedWeb/2.2.0
+
+ Hello, world!
+
+
+Nevow assume that you return some HTML code from renderHTTP, but of
+course you are not limited to do this.
+
+A request is described in the IRequest interface.
+To obtain an IRequest object from the opaque context object, simply
+do::
+
+  req = IRequest(ctx)
+
+Through this interface you have access to all low level stuff like
+setting cookie, arbitrary headers, and response code.
+
+
+Asynchronous rendering
+----------------------
+
+If you are using Twisted as the base server, it is not required to
+render a resource at once.
+
+You can return a deferred (that fires with a string, of course) from
+renderHTTP.
+
+
+Example::
+    
+ class DB(object):
+    """Simulate a database.
+    """
+
+    def __init__(self, user):
+        self._user = user
+        
+    def getUser(self):
+        deferred = defer.Deferred()
+        reactor.callLater(2, self._getUser, deferred)
+
+        return deferred
+
+    def _getUser(self, deferred):
+        deferred.callback(self._user)
+
+
+ class SimpleRoot(object):
+    implements(inevow.IResource)
+    
+    def locateChild(self, ctx, segments):
+        return self, ()
+      
+    def renderHTTP(self, ctx):
+        req = inevow.IRequest(ctx)
+        
+        req.setHeader("Content-Type", "text/plain")
+        
+        req.write("Hello ")
+        
+        db = DB("Manlio Perillo")
+        
+        return db.getUser()
+
+
+This will produce::
+
+  Transfer-encoding: chunked
+  Date: Tue, 30 May 2006 15:25:18 GMT
+  Content-type: text/plain
+  Server: TwistedWeb/2.2.0
+  
+  Hello Manlio Perillo
+
+
+Note also that we explicitly set the Content-type.
+
+XXX what about Content-Size?
+
+
+rend.Page
+---------
+
+`rend.Page` (and `rend.Fragments`, described in detail later) offers an
+higher layer over an IResource.
+
+Of course this not precludes you to override `renderHTTP`, but make sure
+to call the method from the base class.
+
+`rendPage` offer an hook for executing code before and after `renderHTTP`
+is called; 
+just define a `beforeRender` or `afterRender` in your class::
+
+ class SimpleRoot(rend.Page):
+    docFactory = loaders.xmlstr(
+ """<?xml version="1.0"?>
+ <root xmlns:n="http://nevow.com/ns/nevow/0.1">
+   <hello n:data="hello" n:render="string" />
+ </root>
+ """
+         )
+                                
+    def beforeRender(self, ctx):
+        req = inevow.IRequest(ctx)
+        req.setHeader("Content-Type", "application/application+xml; charset=UTF-8")
+        
+    
+    def data_hello(self, ctx, data):
+        return "Hello Nevow"
+
+
+This will produce::
+ 
+ Transfer-encoding: chunked
+ Date: Tue, 30 May 2006 15:42:41 GMT
+ Content-type: application/application+xml; charset=UTF-8
+ Server: TwistedWeb/2.2.0
+
+ <root>
+   <hello>Hello Nevow</hello>
+ </root>
+
+
+Note that the return value from these two methods is ignored.
+
+
+What about HEAD, PUT, DELETE?
+-----------------------------
+
+For all this method, it is always called renderHTTP.
+You can access the method type by IRequest.method
+
+
+URL handling
+------------
+
+Nevow comes with a module for handling URL in an convenient way.
+The module is `nevow.url`.
+
+Before to describe in detail the URL class, it is worth to document
+*how* URLs are handled by the Nevow rendering machinery::
+
+  class Main(rend.Page):
+      child_child = Children()
+    
+      def renderHTTP(self, ctx):
+          return url.URL.fromContext(ctx).child("child")
+
+
+
+The response from the server is::
+
+  HTTP/1.x 302 Found
+  Transfer-Encoding: chunked
+  Date: Sat, 29 Jul 2006 10:46:54 GMT
+  Content-Type: text/html; charset=UTF-8
+  Location: http://localhost:8080/child
+  Server: TwistedWeb/2.4.0
+
+
+Nevow just redirects to the new url.
+You can do the same in `localeChildren`.
+
+
+XXX TODO:
+  
+  describe all URL methods and how to use them.
+
+
+Macros
+------
+
+A macro is a one-time renderer.
+
+TODO
+
+Fragments
+---------
+
+TODO


Maggiori informazioni sulla lista Commits