[albatross-users] page module import magic

Andrew McNamara andrewm at object-craft.com.au
Tue Jan 13 00:04:24 EST 2004


>Yes, it's getting a bit ugly. It's certainly not particularly 
>straightforward.
>
>When you say, "maybe we should only support a flat page module 
>namspace", what do you mean? Do you mean that Albatross should not 
>support URLs like /login/help , requiring something like /login_help 
>instead, or something else?

I'm referring to the page names - with this scheme, you can do things like
ctx.set_page('preferences.simple') and ctx.set_page('preferences.advanced')

The separator is the normal python namespace separate (dot) - previously,
the filesystem separator was used, although I'm not convinced hierarchies
of pages would have worked correctly.

I can imagine an app where you'd want to map the url to page name - maybe
it was a mistake to change it (I was assuming that the old code was broken,
and nobody would have been using hierarchies)? Dots seem more natural in
the context (and it means the import hook can call the function directly).

>Also, I'm not sure what you mean by "dummy parent modules have to be 
>created". Is this referring to the create_module_holder() magic or 
>modules that an Albatross user would need to create?

In the flat case, we create a dummy module at the root, called
'__alpage__', and we load the page modules into that.  If a hierarchy
of page modules is used, dummy modules have to be created to represent
the intervening directories. So... if you have the following:

        login.py
        preferences/simple.py
        preferences/advanced.py

they would be loaded as:

        __alpage__ (dummy)
        __alpage__.login.py
        __alpage__.preferences (dummy)
        __alpage__.preferences.simple
        __alpage__.preferences.advanced

get_module_holder() just makes sure the dummies are created (recursively)
and returns the parent of the module to be loaded.

In decode_session(), I've replaced a sys.path fiddle with an import hook.
On import, if the name starts with __alpage__, the load_page_module()
method is called instead of the system import code.

That pretty much describes the changes - does it make more sense now? I'm
reasonably happy with the result - certainly no less happy that I was
with the original implementation.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list