Class
zope.app.component.back35.LayerField

This field represents a layer.

Besides being able to look up the layer by importing it, we also try to look up the name in the site manager.

>>> from zope.interface import directlyProvides
>>> from zope.interface.interface import InterfaceClass
>>> layer1 = InterfaceClass('layer1', (),
...                         __doc__='Layer: layer1',
...                         __module__='zope.app.layers')
>>> directlyProvides(layer1, ILayer)
>>> layers = None
>>> class Resolver(object):
...     def resolve(self, path):
...         if '..' in path:
...             raise ValueError('Empty module name')
...         if (path.startswith('zope.app.layers') and
...             hasattr(layers, 'layer1') or
...             path == 'zope.app.component.fields.layer1' or
...             path == '.fields.layer1'):
...             return layer1
...         raise ConfigurationError('layer1')
>>> field = LayerField()
>>> field = field.bind(Resolver())

Test 1: Import the layer

>>> field.fromUnicode('zope.app.component.fields.layer1') is layer1
True

Test 2: We have a shortcut name. Import the layer from zope.app.layers.

>>> from types import ModuleType as module
>>> import sys
>>> layers = module('layers')
>>> import zope.app.layers
>>> old = sys.modules['zope.app.layers']
>>> sys.modules['zope.app.layers'] = layers
>>> setattr(layers, 'layer1', layer1)
>>> field.fromUnicode('layer1') is layer1
True
>>> sys.modules['zope.app.layers'] = old

Test 3: Get the layer from the site manager

>>> from zope.app.testing import ztapi
>>> ztapi.provideUtility(ILayer, layer1, 'layer1')
>>> field.fromUnicode('layer1') is layer1
True

Test 4: Import the layer by using a short name

>>> field.fromUnicode('.fields.layer1') is layer1
True

Base classes

Implemented Interfaces

Attributes/Properties

Methods

Known Subclasses

There are no known subclasses.