Differences between revisions 1 and 2
Revision 1 as of 2003-07-05 08:58:45
Size: 2755
Editor: lon-cache2-1
Comment:
Revision 2 as of 2003-07-05 09:02:13
Size: 2830
Editor: lon-cache2-1
Comment:
Deletions are marked like this. Additions are marked like this.
Line 57: Line 57:
            if klass != AppBase:             if klass != KwInitBase:
Line 62: Line 62:
http://www.object-craft.com.au/projects/albatross/wiki/ProposedChanges

Use keyword arguments for all mixins

Albatross is supposed to make it possible to easily switch between different deployment options. Currently when you change application class you must change the list of arguments that you pass to the constructor. Take for instance the ModularSessionApp class:

class ModularSessionApp(PickleSignMixin,
                        Application,
                        CachingTemplateLoaderMixin,
                        PageModuleMixin,
                        SessionServerAppMixin):
    def __init__(self, base_url, module_path, template_path, start_page, secret,
                 session_appid, session_server = 'localhost', server_port = 34343, session_age = 1800):
        Application.__init__(self, base_url)
        PickleSignMixin.__init__(self, secret)
        CachingTemplateLoaderMixin.__init__(self, template_path)
        PageModuleMixin.__init__(self, module_path, start_page)
        SessionServerAppMixin.__init__(self, session_appid, session_server, server_port, session_age)
                                                                                
    def create_context(self):
        return SessionAppContext(self)

There is a mixture of keyword and non-keyword arguments. If the interface to all of the mixins was changed to just accept **kw then the above could look like this:

class ModularSessionApp(PickleSignMixin,
                        Application,
                        CachingTemplateLoaderMixin,
                        PageModuleMixin,
                        SessionServerAppMixin):
    def __init__(self, **kw):
        Application.__init__(self, **kw)
        PickleSignMixin.__init__(self, **kw)
        CachingTemplateLoaderMixin.__init__(self, **kw)
        PageModuleMixin.__init__(self, **kw)
        SessionServerAppMixin.__init__(self, **kw)

Taking the above a little further it should be possible to do something like this:

class ModularSessionApp(KwInitBase,
                        PickleSignMixin,
                        Application,
                        CachingTemplateLoaderMixin,
                        PageModuleMixin,
                        SessionServerAppMixin):
    pass

Then in Albatross the KwInitBase class would be something like this:

class KwInitBase:
    def __init__(self, **kw):
        for klass in self.__class__.__bases__:
            if klass != KwInitBase:
                klass.__init__(self, **kw)

One big advantage to all of this is that it allows you to change application classes very easily. It would also greatly simplify the task of construcitng your own application classes from the standard mixins and your own mixins. http://www.object-craft.com.au/projects/albatross/wiki/ProposedChanges

None: KeywordArguments (last edited 2011-02-15 06:05:17 by localhost)