Lookinf inside page templates from a script
Hi I'd like to get the names of all the macros in a pt and of all the slots within each macro, but I'm getting guarded_item errors. In PageTemplate.py, I have found pt_macros(), which returns a dictionary with macro names as keys. Great so far. I can even print pt_macros() and get a string representing the whole dictionary. However, when I try to access the corresponding value so I can look for the slots inside each macro, I get the error shown below. Is there a way of gettting the macros and their slots from a script, or do I have to write an external method / product? Thanks Felix. Error Type: TypeError Error Value: unsubscriptable object Traceback (innermost last): File /usr/local/Zope-2.5.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 150, in publish_module File /usr/local/Zope-2.5.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 114, in publish File /usr/local/Zope-2.5.1-linux2-x86/lib/python/Zope/__init__.py, line 159, in zpublisher_exception_hook (Object: Playground) File /usr/local/Zope-2.5.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 98, in publish File /usr/local/Zope-2.5.1-linux2-x86/lib/python/ZPublisher/mapply.py, line 88, in mapply (Object: examineMacros.py) File /usr/local/Zope-2.5.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 39, in call_object (Object: examineMacros.py) File /usr/local/Zope-2.5.1-linux2-x86/lib/python/Shared/DC/Scripts/Bindings.py, line 252, in __call__ (Object: examineMacros.py) File /usr/local/Zope-2.5.1-linux2-x86/lib/python/Shared/DC/Scripts/Bindings.py, line 283, in _bindAndExec (Object: examineMacros.py) File /usr/local/Zope-2.5.1-linux2-x86/lib/python/Products/PythonScripts/PythonScript.py, line 302, in _exec (Object: examineMacros.py) (Info: ({'script': <PythonScript instance at 8b76cd0>, 'context': <Folder instance at 8aeb7e8>, 'container': <Folder instance at 8aeb7e8>, 'traverse_subpath': []}, (None,), {}, (None,))) File Script (Python), line 8, in examineMacros.py File /usr/local/zope/lib/python/AccessControl/ZopeGuards.py, line 90, in guarded_getitem (Object: pt_macros) TypeError: (see above)
Felix Ulrich-Oltean writes:
In PageTemplate.py, I have found pt_macros(), which returns a dictionary with macro names as keys. Great so far. I can even print pt_macros() and get a string representing the whole dictionary. However, when I try to access the corresponding value so I can look for the slots inside each macro, I get the error shown below. ... Error Type: TypeError Error Value: unsubscriptable object ... File Script (Python), line 8, in examineMacros.py Something is wrong with your line 8 of "examineMacros.py". You use "[...]" on something which is not subscriptable.
Dieter
DM> Felix Ulrich-Oltean writes: DM> > In PageTemplate.py, I have found pt_macros(), which returns a DM> > dictionary with macro names as keys. Great so far. I can even print DM> > pt_macros() and get a string representing the whole dictionary. DM> > However, when I try to access the corresponding value so I can look DM> > for the slots inside each macro, I get the error shown below. DM> > ... DM> > Error Type: TypeError DM> > Error Value: unsubscriptable object for key, value in context.main_template.pt_macros().items(): print key print value return printed It works. -- Best regards, www.uralfirm.ru Dmitry Matveev mailto:matveev@uralfirm.ru
participants (3)
-
Dieter Maurer -
Dmitry Matveev -
Felix Ulrich-Oltean