Matt Feifarek wrote:
> | If you're within awake() and you need to skip the respond() but you
still
> | want sleep() to be called, you can just call it yourself:
> 
> Well, sure, but you can do the same thing in response() ;-)

True.  In response() it would always be safe to call
self.sleep(self.transaction()) since awake() has run to completion.

> 
> I'm not trying to be annoying, or anything, but consistency 
> seems like a
> good idea for something like this.

Well, I actually was aiming for safety in that sleep() will often be written
so that it requires awake() to have been run to completion.  For example:

class SitePage(Page):
        def awake(self, trans):
                Page.awake(self, trans)
                if someCondition():
                        self.endResponse()
                else:
                        # do some stuff here

class MyPage(SitePage):
        def awake(self, trans):
                SitePage.awake(self, trans)
                self._somevar = somevalue()

        def sleep(self, trans):
                del self._somevar
                SitePage.sleep(self, trans)

See the problem?  If SitePage.awake() calls endResponse() then it's not safe
for the framework to automatically call sleep().  It _is_ safe to call
Page.sleep() right before endResponse() because that will only cause the
part that was successfully awakened to be put to sleep.

On the other hand, it's always safe to call sleep() during respond() because
you know for certain that awake() has run to completion.  That's why I made
it happen automatically.

> 
> Of course, if sleep is trying to close something that never 
> gets opened, one
> will get "bad things". What happens if sleep is never called 
> when awake()
> was? Do sessions and all of that get taken care of allright?

I'm not sure.  In general you're "supposed" to call sleep() for every
awake() that was called.  That's why I suggested explicitly calling
Page.sleep(self, trans) before endResponse() if you do it during awake().
In practice I'm not sure if it matters or not.

I do see your point about consistency though.  Another safe possibility
would be to have endResponse() _never_ trigger a call to sleep().  You'd
always have to invoke the appropriate method yourself.  In respond() that
would be self.sleep(trans), and in awake() it would be BaseClass.sleep(self,
trans).

Any other opinions?  This code is brand new, so now's the best time to get
it right :-)


- Geoff


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to