[albatross-users] examples and ctx

Dave Cole djc at object-craft.com.au
Tue Mar 26 21:38:15 EST 2002


> I noticed that in the examples in the manual the first few show in
> the code where ctx is created as an object. For example in simple5
> we have : ctx = SimpleContext('.')
> 
> After we initiate the session app we don't see this again. Instead
> we see this:
> if __name__ == '__main__':
>     app = App()
>     app.run(Request())
> 
> Is this because the ctx object is initiated by the run() method in
> the backround mixin classes as described (I think) in the manual
> starting at 4.1?

When you use an Albatross application object it creates an execution
context on your behalf as part of the application run() method.
Ignoring the exception handling, the run() method looks like this:

    ctx = self.create_context()
    ctx.set_request(req)
    self.load_session(ctx)
    self.load_page(ctx)
    if self.validate_request(ctx):
        self.merge_request(ctx)
        self.process_request(ctx)
    self.display_response(ctx)
    self.save_session(ctx)

So the first stage of the run() method creates an execution context
and attaches the browser request to it.  If you look at the
implementation of the create_context() method of the application class
you will see the familiar call to the execution context constructor.

For example the ModularSessionApp application class creates a
SessionAppContext execution context whereas the SimpleApp application
class creates a SimpleAppContext execution context.

> I am trying to get this straight in my head because the popview app
> doesn't seem to behave as expected and I am trying to ensure I have
> the theory down.  The ctx object just appears but if I understand
> correctly it is created by the app.run(Request()) call correct?

Yes.

Once you have determined which application and execution context you
are using you can use the inheritance diagrams in chapter 8 to see
where each of the methods are implemented.  The diagrams are UML.  A
class points to the class(es) from which it inherits behaviour.

The diagrams are arranged to match the order of inheritance in Python.
Superclasses are drawn above the classes which inherit from them.
When a class uses multiple inheritance, the superclasses are drawn in
the same left to right sequence as the inheritance in Python.  This
means that you scan the diagram bottom to top, left to right to find
which implementation of a method will be used.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list