skin(_context, name=None, interface=None, layers=None)
Provides a new skin.
First, let's ignore the warnigns: >>> showwarning = warnings.showwarning >>> warnings.showwarning = lambda *a, **k: None
>>> 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
>>> 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
>>> class skin1(Layer1, Layer2): ... pass
>>> context = Context() >>> skin(context, interface=skin1) >>> context.actions[0]['args'][1] is skin1 True
>>> 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