Hi all,
I'm developing with Webware for quite a while and I still think that working 
with applets is not as intuitive as it might be. This has in principle 
nothing to do with Webware but with Web development in general.
Now, using Python, gives us a lot of tools that can be used for our advantage.

Instead of using session data (or request data for that matter) in the usual 
way, I'd rather have some magic involved to let me use this data as normal 
servlet attributes. 
Here is an example of what I mean. The "CountVisits" WebKit example looks 
like (lots of code ommitted):
---------------------------------------------------------------------
class CountVisits(ExamplePage):

    def writeContent(self):
        count = self.session().value('count', 0)+1
        self.session().setValue('count', count)
        self.writeln(count)
---------------------------------------------------------------------

I'd rather like to write something like (and the uninitiated really do :-):
--------------------------------------------------------------------
class CountVisits(ExamplePage):

    def writeContent(self):
        self.count  += 1
        self.writeln(self.count)
---------------------------------------------------------------------

Do do so, one could use appropriate __getattr__ and __setattr__  methods for 
the servlet. This full code could now look like this:

-----------------------------------------------------------------------------------------
class CountVisits(ExamplePage):
    _sessionData_ = {'count':0}

    def __getattr__(self,key):
        if key in self._sessionData_.keys():
            try:
                return self.session().value(key)
            except KeyError:
                self.session().setValue(key,self._sessionData_[key])
                return self._sessionData_[key]
        else:
            raise AttributeError,key

    def __setattr__(self,key,value):
        if key in self._sessionData_.keys():
            self.session().setValue(key,value)
        else:
            self.__dict__[key] = value

    def writeContent(self):
        self.count += 1
        self.writeln(self.count)
-------------------------------------------------------------------------------------------

The question now is the following:
Has anybody done something like that already?
What kind of features would you like to see?

I was thinking of providing a similar technique to populate servlet 
attributes with Request values as well.

Thanks for your patience

Stephan


-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to