Module Menu and ZCML Directive Details


A browser view class that provides support for the ZCML directive overview.

Let’s create a directive that we can use as context for the details:

>>> from zope.interface import Interface, Attribute
>>> class IFoo(Interface):
...     class_ = Attribute('class_')
>>> def foo():
...     pass
>>> directive = Directive(ns, 'page', IFoo, foo, None, ())

Now we can isntantiate the view:

>>> from import DirectiveDetails
>>> details = DirectiveDetails()
>>> details.context = directive
>>> details.request = TestRequest()

We are now ready to see what the details class has to offer.


Returns the interface details class for the schema.

>>> iface_details = details.getSchema()
>>> iface_details
< object at ...>
>>> iface_details.context
<InterfaceClass __builtin__.IFoo>

The DirectiveDetails._getFieldName() method of the interface details has been overridden to neglect trailing underscores in the field name. This is necessary, since Python keywords cannot be used as field names:

>>> iface_details._getFieldName(IFoo['class_'])


Return the name of the namespace.

>>> details.getNamespaceName()

If the directive is in the ‘ALL’ namespace, a special string is returned:

>>> details2 = DirectiveDetails()
>>> ns2 = Namespace(module, 'ALL')
>>> details2.context = Directive(ns2, 'include', None, None, None, None)
>>> details2.getNamespaceName()
'<i>all namespaces</i>'


Get the file where the directive was declared. If the info attribute is not set, return None:

>>> details.getFileInfo() is None

If the info attribute is a parser info, then return the details:

>>> from zope.configuration.xmlconfig import ParserInfo
>>> = ParserInfo('foo.zcml', 2, 3)
>>> info = details.getFileInfo()
>>> from pprint import pprint
>>> pprint(info, width=1)
{'column': 3,
 'ecolumn': 3,
 'eline': 2,
 'file': 'foo.zcml',
 'line': 2}

If the info is a string, None should be returned again:

>>> = 'info here'
>>> details.getFileInfo() is None


Get the configuration information string of the directive:

>>> = 'info here'
>>> details.getInfo()
'info here'

Return None, if the info attribute is a parser info:

>>> = ParserInfo('foo.zcml', 2, 3)
>>> details.getInfo() is None


Return information about the directive handler object.

>>> pprint(details.getHandler(), width=1)
{'path': '',
 'url': None}


Create a list of subdirectives. Currently, we have not specifiedany subdirectives

>>> details.getSubdirectives()

but if we add one

>>> def handler():
...     pass
>>> details.context.subdirs = (
...     ('browser', 'foo', IFoo, handler, 'info'),)

the result becomes more interesting:

>>> pprint(details.getSubdirectives(), width=1)
[{'handler': {'path': 'None.handler', 'url': None},
  'info': 'info',
  'name': 'foo',
  'namespace': 'browser',
  'schema': < ...>}]