Package zope :: Package configuration :: Module xmlconfig :: Class ConfigurationHandler
[show private | hide private]
[frames | no frames]

Class ConfigurationHandler

ContentHandler --+
                 |
                ConfigurationHandler


Interface to the xml parser

Translate parser events into calls into the configuration system.


Method Summary
  __init__(self, context, testing)
  characters(self, text)
  endElementNS(self, name, qname)
Signals the end of an element in namespace mode.
  evaluateCondition(self, expression)
Evaluate a ZCML condition.
  setDocumentLocator(self, locator)
Called by the parser to give the application a locator for locating the origin of document events.
  startElementNS(self, name, qname, attrs)
Signals the start of an element in namespace mode.

Method Details

endElementNS(self, name, qname)

Signals the end of an element in namespace mode.

The name parameter contains the name of the element type, just as with the startElementNS event.
Overrides:
_xmlplus.sax.handler.ContentHandler.endElementNS (inherited documentation)

evaluateCondition(self, expression)

Evaluate a ZCML condition.

expression is a string of the form "verb arguments".

Currently the two supported verba are 'have' and 'installed'.

The 'have' verb takes one argument: the name of a feature.

>>> from zope.configuration.config import ConfigurationContext
>>> context = ConfigurationContext()
>>> context.provideFeature('apidoc')
>>> c = ConfigurationHandler(context, testing=True)
>>> c.evaluateCondition("have apidoc")
True
>>> c.evaluateCondition("have onlinehelp")
False

Ill-formed expressions raise an error

>>> c.evaluateCondition("want apidoc")
Traceback (most recent call last):
  ...
ValueError: Invalid ZCML condition: 'want apidoc'
>>> c.evaluateCondition("have x y")
Traceback (most recent call last):
  ...
ValueError: Only one feature allowed: 'have x y'
>>> c.evaluateCondition("have")
Traceback (most recent call last):
  ...
ValueError: Feature name missing: 'have'

The 'installed' verb takes one argument: the dotted name of a pacakge. If the pacakge is found, in other words, can be imported, then the condition will return true.

>>> from zope.configuration.config import ConfigurationContext
>>> context = ConfigurationContext()
>>> c = ConfigurationHandler(context, testing=True)
>>> c.evaluateCondition('installed zope.interface')
True
>>> c.evaluateCondition('installed zope.foo')
False

Ill-formed expressions raise an error

>>> c.evaluateCondition("installed foo bar")
Traceback (most recent call last):
  ...
ValueError: Only one package allowed: 'installed foo bar'
>>> c.evaluateCondition("installed")
Traceback (most recent call last):
  ...
ValueError: Package name missing: 'installed'

setDocumentLocator(self, locator)

Called by the parser to give the application a locator for locating the origin of document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.
Overrides:
_xmlplus.sax.handler.ContentHandler.setDocumentLocator (inherited documentation)

startElementNS(self, name, qname, attrs)

Signals the start of an element in namespace mode.

The name parameter contains the name of the element type as a (uri, localname) tuple, the qname parameter the raw XML 1.0 name used in the source document, and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

The uri part of the name tuple is None for elements which have no namespace.
Overrides:
_xmlplus.sax.handler.ContentHandler.startElementNS (inherited documentation)

Generated by Epydoc 2.1 on Fri Jun 24 12:01:20 2005 http://epydoc.sf.net