Commits

Joel Rivera  committed 6d86e42

Improvements to a few examples in the tutorial.

- Add as `object` as a base class to the classes.
- Fix indentation.
- Use instance attribute instead of class attribute.

  • Participants
  • Parent commits b907ffb

Comments (0)

Files changed (3)

File sphinx/source/tutorial/basics.rst

     import cherrypy
 
 
-    class HelloWorld:
+    class HelloWorld(object):
         def index(self):
             return "Hello world!"
         index.exposed = True
     import cherrypy
 
 
-    class HelloWorld:    
+    class HelloWorld(object):    
         @cherrypy.expose
         def index(self):
-            host = cherrypy.request.headers('Host')
+            host = cherrypy.request.headers['Host']
             return "You have successfully reached " + host
 
     cherrypy.quickstart(HelloWorld())
     import cherrypy
 
 
-    class HelloWorld:    
+    class HelloWorld(object):    
         def _get_jpeg_data(self):
 	    """This method should return the jpeg data"""
 	    return ""

File sphinx/source/tutorial/dispatching.rst

 
     if __name__ == '__main__':
         root = OnePage()
-	root.foo = foo
+        root.foo = foo
         cherrypy.quickstart(root)
 
 
 
 The following code can be used to handle this URL::
 
-    class Root:
+    class Root(object):
         def doLogin(self, username=None, password=None):
             """Check the username & password"""
         doLogin.exposed = True
 ``http://localhost/blog/2005/01/17``. This URL can be handled by the
 following code::
 
-    class Root:
+    class Root(object):
         def blog(self, year, month, day):
 	    """Deliver the blog post. According to *year* *month* *day*.
 	    """
 down, in case you have multiple methods to expose. For example, we could have
 written the above "blog" example equivalently with a "default" method instead::
 
-    class Blog:
+    class Blog(object):
         def default(self, year, month, day):
             """This method catch the positional arguments 
              *year*,*month*,*day* to delivery the blog content.
         default.exposed = True
 
 
-    class Root:
+    class Root(object):
         pass
 
     root = Root()

File sphinx/source/tutorial/exposing.rst

 Most often, a method on an object is the callable that is to be invoked. In
 this case, one can directly set the exposed attribute::
 
-    class Root:
+    class Root(object):
         def index(self):
 	    """Handle the / URI"""
         index.exposed = True
 
 or use a decorator::
 
-    class Root:
+    class Root(object):
         @cherrypy.expose
         def index(self):
 	    """Handle the / URI"""
 When it is a special method, such as ``__call__``, that is to be invoked,
 the exposed attribute must be set on the class itself::
 
-    class Node:
+    class Node(object):
         exposed = True
         def __call__(self):
             """ """
 	    return "The node content"
 
 
-    class Root:
-        node = Node()
+    class Root(object):
+
+        def __init__(self):
+	    self.node = Node()
 
         @cherrypy.expose       
         def index(self):