Package zope :: Package configuration :: Module config :: Class ConfigurationMachine
[show private | hide private]
[frames | no frames]

Type ConfigurationMachine

                  object --+    
                           |    
ConfigurationAdapterRegistry --+
                               |
                  object --+   |
                           |   |
        ConfigurationContext --+
                               |
                              ConfigurationMachine


Configuration machine

Example:

>>> machine = ConfigurationMachine()
>>> ns = "http://www.zope.org/testing"

Register a directive:

>>> machine((metans, "directive"),
...         namespace=ns, name="simple",
...         schema="zope.configuration.tests.directives.ISimple",
...         handler="zope.configuration.tests.directives.simple")

and try it out:

>>> machine((ns, "simple"), a=u"aa", c=u"cc")
>>> machine.actions
[(('simple', u'aa', u'xxx', 'cc'), f, (u'aa', u'xxx', 'cc'))]

A more extensive example can be found in the unit tests.


Method Summary
  __init__(self)
  __call__(self, _ConfigurationMachine__name, _ConfigurationMachine__info, **_ConfigurationMachine__kw)
  begin(self, _ConfigurationMachine__name, _ConfigurationMachine__data, _ConfigurationMachine__info, **kw)
  end(self)
  execute_actions(self, clear, testing)
Execute the configuration actions
  getInfo(self)
  setInfo(self, info)
    Inherited from ConfigurationAdapterRegistry
  document(self, name, schema, usedIn, handler, info, parent)
  factory(self, context, name)
  register(self, interface, name, factory)
    Inherited from ConfigurationContext
  action(self, discriminator, callable, args, kw, order)
Add an action with the given discriminator, callable and arguments
  checkDuplicate(self, filename)
Check for duplicate imports of the same file.
  hasFeature(self, feature)
Check whether a named feature has been provided.
  path(self, filename)
Examples:
  processFile(self, filename)
Check whether a file needs to be processed
  provideFeature(self, feature)
Declare thata named feature has been provided.
  resolve(self, dottedname)
Resolve a dotted name to an object
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
Implements __implemented__ = <implementedBy zope.configuration.conf...
ClassProvides __provides__ = <zope.interface.declarations.ClassProvide...
NoneType basepath = None                                                                  
tuple includepath = ()
str info = ''
NoneType package = None                                                                  
    Inherited from ConfigurationAdapterRegistry
ClassProvides __providedBy__ = <zope.interface.declarations.ClassProvi...

Method Details

execute_actions(self, clear=True, testing=False)

Execute the configuration actions

This calls the action callables after resolving conflicts

For example:

>>> output = []
>>> def f(*a, **k):
...    output.append(('f', a, k))
>>> context = ConfigurationMachine()
>>> context.actions = [
...   (1, f, (1,)),
...   (1, f, (11,), {}, ('x', )),
...   (2, f, (2,)),
...   ]
>>> context.execute_actions()
>>> output
[('f', (1,), {}), ('f', (2,), {})]

If the action raises an error, we convert it to a ConfigurationExecutionError.

>>> output = []
>>> def bad():
...    bad.xxx
>>> context.actions = [
...   (1, f, (1,)),
...   (1, f, (11,), {}, ('x', )),
...   (2, f, (2,)),
...   (3, bad, (), {}, (), 'oops')
...   ]
>>> try:
...    v = context.execute_actions()
... except ConfigurationExecutionError, v:
...    pass
>>> print v
exceptions.AttributeError: 'function' object has no attribute 'xxx'
  in:
  oops

Note that actions executed before the error still have an effect:

>>> output
[('f', (1,), {}), ('f', (2,), {})]

Class Variable Details

__implemented__

Type:
Implements
Value:
<implementedBy zope.configuration.config.ConfigurationMachine>         

__provides__

Type:
ClassProvides
Value:
<zope.interface.declarations.ClassProvides object at 0xb64a802c>       

basepath

Type:
NoneType
Value:
None                                                                  

includepath

Type:
tuple
Value:
()                                                                     

info

Type:
str
Value:
''                                                                     

package

Type:
NoneType
Value:
None                                                                  

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