On Tue, 2003-02-18 at 10:44, Kevin Dahlhausen wrote:

> I've been giving some thought to the problem of Middlekit objects in
> sessions and wanted to get some feedback.  Two ways to 

> Other thoughts?

Hi Kevin,

In response to your question, I've documented my approach on the Wiki at
http://webware.colorstudy.net/twiki/bin/view/Webware/MiddleKitAndWebKit

My solution to this problem is to implement an alternate encoder/decoder
for WebKit.SessionStore which recognizes Middle objects, and simply
pickles a reference to each object (similar to your approach #1, but
without having proxy objects). When reading in sessions from disk, the
decoder finds the references and fetches the full Middle objects from
the store.

This is transparent to user code -- you can simply put the Middle
objects in the session, and it works.

Two assumptions: 
1. you have a single global store for your application (because the
decoder must fetch the object from the store)

2. you are only putting objects in the session which have been added to
the store (i.e. their serial numbers are > zero).

I _do_ have a way of putting non-saved objects in sessions, but it's
pretty hackish (it's worked for me so far, but it may have some
gotchas).  Basically, I add the following code to
MiddleKit/Run/MiddleObject.py.  

    # Enables pickling of MiddleObjects which haven't been added
    # to the store
    def __getstate__(self):
        return self.allAttrs(includeUnderscoresInKeys=0)

    def __setstate__(self, attrs):
        self.__init__()
        for key, value in attrs.items():
            setMethodName = 'set' + key[0].upper() + key[1:]
            setter = getattr(self.__class__, setMethodName, '_' + key)
            if isinstance(setter, StringType):
                setattr(self, setter, value)
            else:
                # a method
                setter(self, value)


Hope this helps,

-- 
Jason D. Hildebrand
[EMAIL PROTECTED]



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