[PEAK] sitemap.xml and unicode module names

Radek Kanovsky rk at dat.cz
Fri Nov 12 04:16:59 EST 2004


Hi,

playing with simple sitemaps I have found that <import .../> statement
doesn't work in some situations. Try the followin example:

sitemap_impl.py:
    from peak.api import *
    class Foo (web.Location) : pass

sitemap.xml:
    <location id="root">
        <import module="sitemap_impl" as="impl"/>
        <location id="root_foo" name="foo" class="impl.Foo">
            <view name="index_html" resource="example.res/foo"/>
        </location>
    </location>

sitemap.py:
    from peak.api import *
    root = config.makeRoot()
    sm = root.lookupComponent('ref:sitemap at file:/path/to/sitemap.xml')


Problem is in peak.web.sitemaps.doImport that injects unicode module
name u'sitemap_impl' into sys.modules if module isn't already loaded.
Then lazy import cannot find this module by name and complains
with SystemError('nameless module') in 'reload' on line 195 in
peak.utils.imports. Quick patch for the problem is below. Maybe there
are more places in sitemap.py or templates.py that need some repair.
Inserting 'modname=str(modname)' into lazyModule() itself could be best,
but I am not sure. Althoug it is working too.

RadekK


--- sitemaps.py (revision 22)
+++ sitemaps.py (working copy)
@@ -308,7 +308,7 @@
     attrs = SOX.validatedAttributes(parser,data,('module',),('as',))
     module = attrs['module']
     as_ = attrs.get('as', module.split('.')[-1])
-    getGlobals(data['previous'])[as_] = lazyModule(module)
+    getGlobals(data['previous'])[as_] = lazyModule(str(module))
 
 def defineImport(parser,data):
     assertNotTop(parser,data)



More information about the PEAK mailing list