本文整理汇总了Python中zope.interface.interface.InterfaceClass类的典型用法代码示例。如果您正苦于以下问题:Python InterfaceClass类的具体用法?Python InterfaceClass怎么用?Python InterfaceClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InterfaceClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: menuDirective
def menuDirective(_context, id=None, class_=BrowserMenu, interface=None,
title=u'', description=u''):
"""Registers a new browser menu."""
if id is None and interface is None:
raise ConfigurationError(
"You must specify the 'id' or 'interface' attribute.")
if interface is None:
if id in dir(menus):
# reuse existing interfaces for the id, without this we are not
# able to override menus.
interface = getattr(menus, id)
else:
interface = InterfaceClass(id, (),
__doc__='Menu Item Type: %s' %id,
__module__='zope.app.menus')
# Add the menu item type to the `menus` module.
# Note: We have to do this immediately, so that directives using the
# MenuField can find the menu item type.
setattr(menus, id, interface)
path = 'zope.app.menus.' + id
else:
path = interface.__module__ + '.' + interface.getName()
# If an id was specified, make this menu available under this id.
# Note that the menu will be still available under its path, since it
# is an adapter, and the `MenuField` can resolve paths as well.
if id is None:
id = path
else:
# Make the interface available in the `zope.app.menus` module, so
# that other directives can find the interface under the name
# before the CA is setup.
_context.action(
discriminator=('browser', 'MenuItemType', path),
callable=provideInterface,
args=(path, interface, IMenuItemType, _context.info)
)
setattr(menus, id, interface)
# Register the layer interface as an interface
_context.action(
discriminator=('interface', path),
callable=provideInterface,
args=(path, interface),
kw={'info': _context.info}
)
# Register the menu item type interface as an IMenuItemType
_context.action(
discriminator=('browser', 'MenuItemType', id),
callable=provideInterface,
args=(id, interface, IMenuItemType, _context.info)
)
# Register the menu as a utility
utility(_context, IBrowserMenu, class_(id, title, description), name=id)
示例2: test__uncached_lookupAll_empty_ro
def test__uncached_lookupAll_empty_ro(self):
from zope.interface.interface import InterfaceClass
IFoo = InterfaceClass('IFoo')
IBar = InterfaceClass('IBar', IFoo)
registry = self._makeRegistry()
alb = self._makeOne(registry)
result = alb._uncached_lookupAll((IFoo,), IBar)
self.assertEqual(result, ())
self.assertEqual(len(alb._required), 1)
self.failUnless(IFoo.weakref() in alb._required)
示例3: __init__
def __init__(self, *arg, **kw):
try:
attrs = arg[2] or {}
except IndexError:
attrs = kw.get("attrs", {})
si = attrs.pop("source_integrity", False)
ti = attrs.pop("target_integrity", False)
InterfaceClass.__init__(self, *arg, **kw)
self.setTaggedValue("source_integrity", si)
self.setTaggedValue("target_integrity", ti)
示例4: __init__
def __init__(self, *arg, **kw):
try:
attrs = arg[2] or {}
except IndexError:
attrs = kw.get('attrs', {})
si = attrs.pop('source_integrity', False)
ti = attrs.pop('target_integrity', False)
so = attrs.pop('source_ordered', False)
to = attrs.pop('target_ordered', False)
InterfaceClass.__init__(self, *arg, **kw)
self.setTaggedValue('source_integrity', si)
self.setTaggedValue('target_integrity', ti)
self.setTaggedValue('source_ordered', so)
self.setTaggedValue('target_ordered', to)
示例5: route_request_iface
def route_request_iface(name, bases=()):
# zope.interface treats the __name__ as the __doc__ and changes __name__
# to None for interfaces that contain spaces if you do not pass a
# nonempty __doc__ (insane); see
# zope.interface.interface.Element.__init__ and
# https://github.com/Pylons/pyramid/issues/232; as a result, always pass
# __doc__ to the InterfaceClass constructor.
iface = InterfaceClass('%s_IRequest' % name, bases=bases,
__doc__="route_request_iface-generated interface")
# for exception view lookups
iface.combined = InterfaceClass(
'%s_combined_IRequest' % name,
bases=(iface, IRequest),
__doc__ = 'route_request_iface-generated combined interface')
return iface
示例6: wrapSchema
def wrapSchema(self, sch, field, hfields):
wschema = InterfaceClass(sch.__name__, (interface.Interface,),
__doc__ = sch.__doc__,
__module__ = 'memphisttw.schema.schemas')
for name, fld in schema.getFieldsInOrder(sch):
if name in self.skipFields or name in hfields:
continue
mfield = self.mapField(name, fld)
if mfield is not None:
fld = mfield(
__name__ = name,
title = fld.title,
description = fld.description,
required = False)
if fld.__class__ == schema.Field:
continue
wschema._InterfaceClass__attrs[name] = fld
return wschema
示例7: __init__
def __init__(self, *arg, **kw):
try:
attrs = arg[2] or {}
except IndexError:
attrs = kw.get('attrs', {})
# get class attribute values and remove them
si = attrs.pop('source_integrity', False)
ti = attrs.pop('target_integrity', False)
so = attrs.pop('source_ordered', False)
to = attrs.pop('target_ordered', False)
sif = attrs.pop('source_isheet', ISheet)
sifa = attrs.pop('source_isheet_field', u'')
tif = attrs.pop('target_isheet', ISheet)
# initialize interface class
InterfaceClass.__init__(self, *arg, **kw)
# set tagged values based on attribute values
self.setTaggedValue('source_integrity', si)
self.setTaggedValue('target_integrity', ti)
self.setTaggedValue('source_ordered', so)
self.setTaggedValue('target_ordered', to)
self.setTaggedValue('source_isheet', sif)
self.setTaggedValue('source_isheet_field', sifa)
self.setTaggedValue('target_isheet', tif)
示例8: __call__
def __call__(self, other, default=_notag):
""" XXX use TypedInterfaceConfigurable as a fallback if this interface doesn't
work for some reason
"""
result = InterfaceClass.__call__(self, other, _notag)
if result is not _notag:
return result
from formless.annotate import TypedInterface
if TypedInterface.providedBy(other):
from formless.configurable import TypedInterfaceConfigurable
return TypedInterfaceConfigurable(other)
if default is _notag:
raise TypeError('Could not adapt', other, self)
return default
示例9: __init__
def __init__(self, *args, **kw):
Persistent.__init__(self)
InterfaceClass.__init__(self, *args, **kw)
self.dependents = PersistentDict()
示例10: __init__
def __init__(self, name, bases=(), attrs=None, __doc__=None,
__module__=None):
InterfaceClass.__init__(self, name, bases, attrs, __doc__, __module__)
self._SchemaClass_finalize()
示例11: route_request_iface
def route_request_iface(name, bases=()):
iface = InterfaceClass('%s_IRequest' % name, bases=bases)
# for exception view lookups
iface.combined = InterfaceClass('%s_combined_IRequest' % name,
bases=(iface, IRequest))
return iface
示例12: __init__
def __init__(self, name, bases=(), attrs=None, __doc__=None, __module__=None):
InterfaceClass.__init__(self, name, bases, attrs, __doc__, __module__)
示例13: skin
def skin(_context, name=None, interface=None, layers=None):
"""Provides a new skin.
>>> import pprint
>>> class Context(object):
... info = u'doc'
... 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>)
>>> 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.
"""
if name is None and interface is None:
raise ConfigurationError("You must specify the 'name' or 'interface' attribute.")
if name is not None and layers is not None:
interface = InterfaceClass(str(name), layers, __doc__="Skin: %s" % str(name), __module__="zope.app.skins")
# Add the layer to the skins module.
# Note: We have to do this immediately, so that directives using the
# InterfaceField can find the layer.
setattr(zope.app.skins, name, interface)
path = "zope.app.skins" + name
# Register the layers
for layer in layers:
_context.action(
discriminator=None, callable=provideInterface, args=(layer.getName(), layer, ILayer, _context.info)
)
else:
path = interface.__module__ + "." + interface.getName()
# Register the skin interface as a skin using the passed name.
if name is not None:
_context.action(
discriminator=("skin", name), callable=provideInterface, args=(name, interface, ISkin, _context.info)
)
name = path
# Register the skin interface as an interface
_context.action(
discriminator=("interface", path), callable=provideInterface, args=(path, interface), kw={"info": _context.info}
)
# Register the skin interface as a skin
_context.action(
#.........这里部分代码省略.........
示例14: __init__
def __init__(self, name):
InterfaceClass.__init__(self, name, (Interface,))
Baz.__init__(self, name)
示例15: __new__
def __new__(cls, name, bases, dct):
rv = cls = InterfaceClass.__new__(cls)
cls.__id__ = nextId()
cls.__methods__ = methods = []
cls.__properties__ = properties = []
cls.default = 'DEFAULT'
cls.complexType = True
possibleActions = []
actionAttachers = []
for key, value in list(dct.items()):
if key[0] == '_': continue
if isinstance(value, MetaTypedInterface):
## A Nested TypedInterface indicates a GroupBinding
properties.append(GroupBinding(key, value, value.__id__))
## zope.interface doesn't like these
del dct[key]
setattr(cls, key, value)
elif isinstance(value, collections.Callable):
names, _, _, typeList = inspect.getargspec(value)
_testCallArgs = ()
if typeList is None:
typeList = []
if len(names) == len(typeList) + 1:
warnings.warn(
"TypeInterface method declarations should not have a 'self' parameter",
DeprecationWarning,
stacklevel=2)
del names[0]
_testCallArgs = (_Marker,)
if len(names) != len(typeList):
## Allow non-autocallable methods in the interface; ignore them
continue
argumentTypes = [
Argument(n, argtype, argtype.id) for n, argtype in zip(names[-len(typeList):], typeList)
]
result = value(*_testCallArgs)
label = None
description = None
if getattr(value, 'autocallable', None):
# autocallables have attributes that can set label and description
label = value.attributes.get('label', None)
description = value.attributes.get('description', None)
adapted = iformless.ITyped(result, None)
if adapted is None:
adapted = Object(result)
# ITyped has label and description we can use
if label is None:
label = adapted.label
if description is None:
description = adapted.description
defaultLabel, defaultDescription = labelAndDescriptionFromDocstring(value.__doc__)
if defaultLabel is None:
# docstring had no label, try the action if it is an autocallable
if getattr(value, 'autocallable', None):
if label is None and value.action is not None:
# no explicit label, but autocallable has action we can use
defaultLabel = value.action
if defaultLabel is None:
# final fallback: use the function name as label
defaultLabel = nameToLabel(key)
if label is None:
label = defaultLabel
if description is None:
description = defaultDescription
theMethod = Method(
adapted, argumentTypes, label=label, description=description
)
if getattr(value, 'autocallable', None):
methods.append(
MethodBinding(
key, theMethod, value.id, value.action, value.attributes))
else:
possibleActions.append((value, MethodBinding(key, theMethod)))
else:
if not value.label:
value.label = nameToLabel(key)
if iformless.IActionableType.providedBy(value):
actionAttachers.append(value)
properties.append(
Property(key, value, value.id)
)
for attacher in actionAttachers:
attacher.attachActionBindings(possibleActions)
methods.sort(key=_sorter)
#.........这里部分代码省略.........