Function
zope.app.publisher.browser.metaconfigure.skin

Signature

skin(_context, name=None, interface=None, layers=None)

Documentation String

Provides a new skin.

First, let's ignore the warnigns: >>> showwarning = warnings.showwarning >>> warnings.showwarning = lambda *a, **k: None

System Message: WARNING/2 (<string>, line 3); backlink

Inline emphasis start-string without end-string.

System Message: WARNING/2 (<string>, line 3); backlink

Inline strong start-string without end-string.
>>> import pprint
>>> class Info(object):
...     file = u'doctest'
...     line = 1
...
>>> class Context(object):
...     info = Info()
...     def __init__(self): self.actions = []
...     def action(self, **kw): self.actions.append(kw)
>>> class Layer1(ILayer): pass
>>> class Layer2(ILayer): pass

Possibility 1: The Old Way

>>> context = Context()
>>> skin(context, u'skin1', layers=[Layer1, Layer2])
>>> iface = context.actions[3]['args'][1]
>>> iface.getName()
'skin1'
>>> pprint.pprint(iface.__bases__)
(<InterfaceClass zope.app.publisher.browser.metaconfigure.Layer1>,
 <InterfaceClass zope.app.publisher.browser.metaconfigure.Layer2>)
>>> import sys
>>> hasattr(sys.modules['zope.app.skins'], 'skin1')
True
>>> del sys.modules['zope.app.skins'].skin1

Possibility 2: Just specify an interface

>>> class skin1(Layer1, Layer2):
...     pass
>>> context = Context()
>>> skin(context, interface=skin1)
>>> context.actions[0]['args'][1] is skin1
True

Possibility 3: Specify an interface and a Name

>>> context = Context()
>>> skin(context, name='skin1', interface=skin1)
>>> context.actions[0]['args'][1] is skin1
True
>>> import pprint
>>> pprint.pprint([action['discriminator'] for action in context.actions])
[('skin', 'skin1'),
 ('interface', 'zope.app.publisher.browser.metaconfigure.skin1'),
 ('skin', 'zope.app.publisher.browser.metaconfigure.skin1')]

Here are some disallowed configurations.

>>> context = Context()
>>> skin(context)
Traceback (most recent call last):
...
ConfigurationError: You must specify the 'name' or 'interface' attribute.
>>> skin(context, layers=[Layer1])
Traceback (most recent call last):
...
ConfigurationError: You must specify the 'name' or 'interface' attribute.

Enabling the warnings again: >>> warnings.showwarning = showwarning