本文整理汇总了Python中zope.component.zcml.utility函数的典型用法代码示例。如果您正苦于以下问题:Python utility函数的具体用法?Python utility怎么用?Python utility使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utility函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _register_datasource
def _register_datasource(_context,
name, json_source, site,
title, description,
select_label, select_description,
setting_iface,
adapter_factory,
label_getter=lambda x,y:y['settingsdata']):
json_data = simplejson.loads(open(json_source).read())
utility(_context, name=name, factory=lambda : json_data,
provides=IGroupSource)
utility_factory = type(str(name), (LookupRecipientSourceRegistration,), {
'name': name,
'title': title,
'description': description,
'site': site,
'settings_schema': setting_iface,
'get_label': label_getter
})
utility(_context, name=name, factory=utility_factory)
adapter(_context, factory=(adapter_factory,),
for_=(IMegaphone, IBrowserRequest),
provides=IRecipientSource,
name=name)
开发者ID:inigoconsulting,项目名称:collective.megaphonegrouplookup,代码行数:26,代码来源:meta.py
示例2: contenttype_directive
def contenttype_directive(_context, portal_type, class_, schema, behaviors=None,
add_permission=None, allowed_types=None):
"""
Generate factory for the passed schema
"""
logger.warn('plone:contenttype directive will be removed in 1.0.0 final')
# prevent circular import
from plone.server.content import ResourceFactory
factory = ResourceFactory(
class_,
title='',
description='',
portal_type=portal_type,
schema=schema,
behaviors=behaviors or (),
add_permission=add_permission or DEFAULT_ADD_PERMISSION,
allowed_types=allowed_types
)
utility(
_context,
provides=IResourceFactory,
component=factory,
name=portal_type,
)
开发者ID:plone,项目名称:plone.server,代码行数:26,代码来源:metaconfigure.py
示例3: tile
def tile(_context, name,
title=None, description=None, add_permission=None, schema=None,
for_=None, layer=None, class_=None, template=None, permission=None):
"""Implements the <plone:tile /> directive
"""
if title is not None or description is not None or add_permission is not None or schema is not None:
if title is None or add_permission is None:
raise ConfigurationError(u"When configuring a new type of tile, 'title' and 'add_permission' are required")
type_ = TileType(name, title, add_permission, description, schema)
utility(_context, provides=ITileType, component=type_, name=name)
if for_ is not None or layer is not None or class_ is not None or template is not None or permission is not None:
if class_ is None and template is None:
raise ConfigurationError(u"When configuring a tile, 'class' or 'template' must be given.")
if permission is None:
raise ConfigurationError(u"When configuring a tile, 'permission' is required")
if for_ is None:
for_ = Interface
if layer is None:
layer = IDefaultBrowserLayer
if class_ is None:
class_ = Tile
page(_context, name=name, permission=permission, for_=for_, layer=layer,
template=template, class_=class_)
开发者ID:pchanxxx,项目名称:deLuca,代码行数:30,代码来源:meta.py
示例4: registerSiteMapping
def registerSiteMapping(_context, source_site_name, target_site_name):
"""
Create and register a site mapping, as a utility under the `source_site_name`.
"""
site_mapping = SiteMapping(source_site_name=source_site_name,
target_site_name=target_site_name)
utility(_context, provides=ISiteMapping,
component=site_mapping, name=source_site_name)
开发者ID:NextThought,项目名称:nti.site,代码行数:8,代码来源:zcml.py
示例5: handlerDirective
def handlerDirective(_context, name, transform, generator,
scope, class_=None, attribute=None, order=-1):
if attribute and class_:
msg = u"Either ``class`` or ``attribute`` must be set."
raise ConfigurationError(msg)
name = '%s.%s.%s' % (transform, generator, name)
handler = class_(name, scope, order)
utility(_context, provides=IHandler, component=handler, name=name)
开发者ID:bluedynamics,项目名称:agx.core,代码行数:8,代码来源:metaconfigure.py
示例6: after
def after(self):
permission = Permission(self.id, self.title, self.description)
utility(self.context, IPermission, permission, name=self.id)
zope2_permission = str(self.title)
if self.roles:
addPermission(zope2_permission, default_roles=tuple(self.roles))
else:
addPermission(zope2_permission)
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:9,代码来源:security.py
示例7: 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)
开发者ID:zopefoundation,项目名称:zope.browsermenu,代码行数:57,代码来源:metaconfigure.py
示例8: hotspotDirective
def hotspotDirective(_context, name, obj=None, interface=None,
resource=[], considerparams=[]):
if not obj and not interface and not resource:
raise ConfigurationError(u"Du solltest dich entscheiden, Jonny!")
hotspot = Hotspot(obj, interface, resource, considerparams)
utility(_context,
provides=IHotspot,
component=hotspot,
name=name)
开发者ID:bluedynamics,项目名称:cornerstone.browser,代码行数:9,代码来源:metaconfigure.py
示例9: engine
def engine(_context, url, name='', echo=False, pool_recycle=-1, **kwargs):
engine_component = sqlalchemy.create_engine(
url, echo=echo,
pool_recycle=pool_recycle, **kwargs)
zcml.utility(_context,
provides = interfaces.IDatabaseEngine,
component = engine_component,
name = name)
开发者ID:jasonheffner,项目名称:contentmirror,代码行数:10,代码来源:zcml.py
示例10: componentFieldSpecDirective
def componentFieldSpecDirective(_context, class_, fields=()):
meta_type = class_.meta_type
klass = type('ComponentFieldSpec',
(ComponentFieldSpec,),
{
'fields':fields,
'meta_type':meta_type,
}
)
utility(_context, name=meta_type, factory=klass, provides=IComponentFieldSpec)
开发者ID:zenoss,项目名称:zenoss-prodbin,代码行数:10,代码来源:metaconfigure.py
示例11: __init__
def __init__(self, _context, id, schema, title,
for_=None, description=u'', class_=None, provides=[],
permission='zojax.ModifyPreference', accesspermission='',
tests=(), order = 9999):
if not accesspermission:
accesspermission = permission
if permission == 'zope.Public':
permission = CheckerPublic
if accesspermission == 'zope.Public':
accesspermission = CheckerPublic
Class = PreferenceType(str(id), schema, class_, title, description)
Class.order = order
Class.__permission__ = permission
Class.__accesspermission__ = accesspermission
tests = tuple(tests)
if permission != CheckerPublic:
tests = tests + (PermissionChecker,)
if interface.interfaces.IInterface.providedBy(for_):
tests = tests + (PrincipalChecker(for_),)
group = Class(tests)
utility(_context, IPreferenceGroup, group, name=id)
adapter(_context, (PreferenceGroupAdapter(id),), schema,
(for_ or IPrincipal,))
adapter(_context, (PreferenceGroupAdapter(id),), schema,
(for_ or IPrincipal, interface.Interface))
interface.classImplements(Class, *provides)
self._class = Class
self._context = _context
self._permission = permission
self.require(_context, permission, set_schema=(schema,))
self.require(_context, accesspermission,
interface=(IPreferenceGroup, schema))
self.require(_context, CheckerPublic,
interface=(IEnumerableMapping, ILocation),
attributes=('isAvailable',
'__id__', '__schema__',
'__title__', '__description__',
'__permission__'))
schema.setTaggedValue('preferenceID', id)
_context.action(
discriminator=('zojax:preferences', schema),
callable=addSubgroup, args=(group,))
开发者ID:Zojax,项目名称:zojax.preferences,代码行数:55,代码来源:zcml.py
示例12: behaviorDirective
def behaviorDirective(_context, title, provides, description=None, marker=None,
factory=None, for_=None):
if marker is None and factory is None:
marker = provides
if factory is None and marker is not None and marker is not provides:
raise ConfigurationError(
u"You cannot specify a different 'marker' and 'provides' if "
u"there is no adapter factory for the provided interface."
)
# Instantiate the real factory if it's the schema-aware type. We do
# this here so that the for_ interface may take this into account.
if factory is not None and ISchemaAwareFactory.providedBy(factory):
factory = factory(provides)
# Attempt to guess the factory's adapted interface and use it as the for_
if for_ is None and factory is not None:
adapts = getattr(factory, '__component_adapts__', None)
if adapts:
if len(adapts) != 1:
raise ConfigurationError(
u"The factory cannot be declared a multi-adapter."
)
for_ = adapts[0]
else:
for_ = Interface
elif for_ is None:
for_ = Interface
registration = BehaviorRegistration(
title=title,
description=description,
interface=provides,
marker=marker,
factory=factory
)
adapter_factory = BehaviorAdapterFactory(registration)
utility(
_context,
provides=IBehavior,
name=provides.__identifier__,
component=registration
)
if factory is not None:
adapter(
_context,
factory=(adapter_factory,),
provides=provides,
for_=(for_,)
)
开发者ID:urska19,项目名称:Plone-test,代码行数:55,代码来源:metaconfigure.py
示例13: factory
def factory(self, _context, id=None, title="", description=''):
"""Register a zmi factory for this class"""
id = id or self.__id
factoryObj = Factory(self.__class, title, description)
# note factories are all in one pile, utilities and content,
# so addable names must also act as if they were all in the
# same namespace, despite the utilities/content division
utility(_context, IFactory, factoryObj,
permission=PublicPermission, name=id)
开发者ID:kislovm,项目名称:findburo,代码行数:11,代码来源:metaconfigure.py
示例14: transformDirective
def transformDirective(_context, provides=None, component=None, factory=None,
permission=None, name=None):
if factory:
if component:
raise TypeError("Can't specify factory and component.")
component = factory()
factory = None
if name is None:
name = component.name
if [True for n in KNOWN_BASE_NAMES if name.startswith(n)]:
# If no name was specified or we are subclassing one of the
# base classes, automatically generate the name based on the full
# dotted class name.
module = component.__module__
classname = component.__class__.__name__
name = component.name = module + '.' + classname
if permission is None:
# Default to all public permission
permission = PublicPermission
if provides is None:
provides = list(providedBy(component))
if len(provides) == 1:
provides = provides[0]
else:
# Try to be a bit smarter about the interface guessing.
for iface in provides:
if (not iface.isOrExtends(ITransform) or
iface in INVALID_INTERFACES):
provides.remove(iface)
# See if we still have more than one interface
if len(provides) == 1:
provides = provides[0]
else:
# See if we have both ITransform and something else in here
if ITransform in provides:
provides.remove(ITransform)
if len(provides) == 1:
provides = provides[0]
else:
# Look again for ICommandTransform and something else
if ICommandTransform in provides:
provides.remove(ICommandTransform)
if len(provides) == 1:
provides = provides[0]
else:
raise TypeError("Missing 'provides' attribute")
utility(_context, provides=provides, component=component, factory=factory,
permission=permission, name=name)
开发者ID:NitikaAgarwal,项目名称:plone.transforms,代码行数:53,代码来源:metaconfigure.py
示例15: __call__
def __call__(self):
# Set up the utility with an appropriate proxy.
# Note that this does not take into account other security
# directives on this content made later on during the execution
# of the zcml.
checker = Checker(
self.permission_collector.get_permissions,
self.permission_collector.set_permissions)
component = ProxyFactory(self.component, checker=checker)
utility(
self._context, self.provides, component=component, name=self.name)
return ()
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:12,代码来源:metazcml.py
示例16: flavorDirective
def flavorDirective(_context, title, behavior, description=None, for_=None, icon=None):
info = FlavorInfo(behavior)
info.title = title
info.description = description
info.icon = icon
if for_:
info.interfaces = for_
else:
info.interfaces = (IFlavorAware,)
# register a utility, used in vocabularies of flavors:
utility(_context, provides=IFlavor, name=info.identifier, component=info)
开发者ID:seanupton,项目名称:experimental.flavors,代码行数:12,代码来源:metaconfigure.py
示例17: unauthenticatedPrincipal
def unauthenticatedPrincipal(_context, id, title, description=''):
principal = principalregistry.UnauthenticatedPrincipal(
id, title, description)
_context.action(
discriminator = 'unauthenticatedPrincipal',
callable = principalregistry.principalRegistry.defineDefaultPrincipal,
args = (id, title, description, principal) )
utility(_context, interfaces.IUnauthenticatedPrincipal, principal)
_context.action(
discriminator = None,
callable = _unauthenticatedPrincipal,
args = (),
)
开发者ID:jean,项目名称:zope.principalregistry,代码行数:13,代码来源:metaconfigure.py
示例18: __init__
def __init__(
self,
_context,
name,
schema,
title,
description="",
class_=None,
provides=(),
permission="zojax.ManageProducts",
tests=(),
configurable=False,
require=(),
):
product_class = Product
if class_ is None:
class_ = product_class
else:
class_ = (class_, product_class)
if configurable:
test = ProductTest()
tests = (test,) + tuple(tests)
else:
tests = (NotConfigurable,)
# create component registry
registry = ProductRegistry(name, title)
zojax.product.registries[name] = registry
setattr(zojax.product, name, registry)
utility(_context, IComponents, registry, name=name)
# register configlet
productName = name
name = "product." + name
super(ProductDirective, self).__init__(
_context, name, schema, title, description, class_, provides, permission, tests
)
self._class.__require__ = require
self._class.__product_name__ = productName
if configurable:
test.product = self._configlet
utility(_context, IProduct, self._configlet, name=productName)
self.require(_context, permission, interface=(IProduct,))
self.require(_context, CheckerPublic, attributes=("isInstalled", "__installed__"))
开发者ID:Zojax,项目名称:zojax.product,代码行数:51,代码来源:zcml.py
示例19: authenticatedGroup
def authenticatedGroup(_context, id, title, description=''):
principal = principalregistry.AuthenticatedGroup(
id, title, description)
utility(_context, interfaces.IAuthenticatedGroup, principal)
_context.action(
discriminator = None,
callable = _authenticatedGroup,
args = (principal.id, ),
)
_context.action(
discriminator = None,
callable = principalregistry.principalRegistry.registerGroup,
args = (principal, ),
)
开发者ID:jean,项目名称:zope.principalregistry,代码行数:14,代码来源:metaconfigure.py
示例20: everybodyGroup
def everybodyGroup(_context, id, title, description=''):
principal = principalregistry.EverybodyGroup(
id, title, description)
utility(_context, interfaces.IEveryoneGroup, principal)
_context.action(
discriminator = None,
callable = _everybodyGroup,
args = (principal.id, ),
)
_context.action(
discriminator = None,
callable = principalregistry.principalRegistry.registerGroup,
args = (principal, ),
)
开发者ID:jean,项目名称:zope.principalregistry,代码行数:14,代码来源:metaconfigure.py
注:本文中的zope.component.zcml.utility函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论