Module Menu and ZCML Directive Details

DirectiveDetails

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 zope.app.apidoc.zcmlmodule.browser import DirectiveDetails
>>> details = DirectiveDetails()
>>> details.context = directive
>>> details.request = TestRequest()

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

DirectiveDetails.getSchema()

Returns the interface details class for the schema.

>>> iface_details = details.getSchema()
>>> iface_details
<zope.app.apidoc.ifacemodule.browser.InterfaceDetails object at ...>
>>> iface_details.context
<InterfaceClass builtins.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_'])
'class'

DirectiveDetails.getNamespaceName()

Return the name of the namespace.

>>> details.getNamespaceName()
'http://namespaces.zope.org/browser'

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>'

getFileInfo()

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

>>> details.getFileInfo() is None
True

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

>>> from zope.configuration.xmlconfig import ParserInfo
>>> details.context.info = 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:

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

DirectiveDetails.getInfo()

Get the configuration information string of the directive:

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

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

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

DirectiveDetails.getHandler()

Return information about the directive handler object.

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

DirectiveDetails.getSubdirectives()

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': <zope.app.apidoc.ifacemodule.browser.InterfaceDetails ...>}]