本文整理汇总了Python中zope.location.interfaces.ISite.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python ISite.providedBy方法的具体用法?Python ISite.providedBy怎么用?Python ISite.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.location.interfaces.ISite
的用法示例。
在下文中一共展示了ISite.providedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNearestSite
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def getNearestSite(self):
"""See ILocationInfo
"""
if ISite.providedBy(self.context):
return self.context
for parent in self.getParents():
if ISite.providedBy(parent):
return parent
return self.getRoot()
示例2: ensure_site
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def ensure_site(context):
"""Ensure the given context implements ISite. The importance of
this method is that it will ensure the given context is an ISite
regardless of the Zope version (Zope 2.9 had a really hacked up
SiteManager mechanism we have to account for).
>>> from zope.location.interfaces import ISite, IPossibleSite
>>> from OFS.Folder import Folder
>>> if not IPossibleSite.implementedBy(Folder):
... from zope import interface
... from Products.Five.site.metaconfigure import (FiveSite,
... classSiteHook)
... classSiteHook(Folder, FiveSite)
... interface.classImplements(Folder, IPossibleSite)
>>> om = Folder('foo')
>>> ISite.providedBy(om)
False
>>> try:
... ensure_site(om)
... except TypeError:
... # not supposed to do anything unless enableLocalSiteHook was found
... if enableLocalSiteHook is None:
... True
True
"""
if not IPossibleSite.providedBy(context):
if hasattr(context, 'getPhysicalPath'):
p = '/'.join(context.getPhysicalPath())
elif hasattr(context, 'getId'):
p = context.getId()
elif hasattr(context, 'id'):
p = id
else:
p = str(context)
raise TypeError('The object, "%s", is not an IPossibleSite' % p)
if not ISite.providedBy(context):
if enableLocalSiteHook is not None:
enableLocalSiteHook(context)
setSite(context)
else:
raise TypeError('"%s" is not configured as an ISite' %
'/'.join(context.getPhysicalPath()))
if not ISite.providedBy(context):
raise TypeError('Somehow trying to configure "%s" as an ISite '
'has failed' % '/'.join(context.getPhysicalPath()))
示例3: registerService
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def registerService(context, id, service, interface):
"""Set and register the service id, using interface.
"""
if not ISite.providedBy(context.aq_base):
site = context.Destination()
if not ISite.providedBy(site):
raise BadRequest("A service can only be created in a local site")
else:
site = context
site._setObject(id, service)
service = site._getOb(id)
sm = site.getSiteManager()
sm.registerUtility(service, interface)
return service
示例4: SilvaZMIFilter
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def SilvaZMIFilter(container, filter_addable=False):
if filter_addable and not zmi_addable:
return False
try:
inside_silva = interfaces.IRoot.providedBy(container.get_root())
except AttributeError:
inside_silva = False
if not inside_silva:
# Outsite of Silva, you can only add a Silva Root.
return interfaces.IRoot.implementedBy(content)
if interfaces.IZMIObject.implementedBy(content):
if interfaces.ISilvaLocalService.implementedBy(content):
# Add local service in a site.
return ISite.providedBy(container)
# ZMIObject are addable, but not the non-local services
# (they must be installed).
return not interfaces.ISilvaService.implementedBy(content)
if interfaces.IRoot.implementedBy(content):
# Silva Root are not addable inside Silva.
return False
if interfaces.IContainer.providedBy(container):
# In a Container, you can add content.
return interfaces.ISilvaObject.implementedBy(content)
if interfaces.IVersionedObject.providedBy(container):
# In a Versioned object, you can add version.
return interfaces.IVersion.implementedBy(content)
return False
示例5: silva_session_arg_generator
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def silva_session_arg_generator(parent):
root, options = parent.next()
if not hasattr(options, 'paths') or not len(options.paths):
fail(u"specifiy at least one Silva root path")
for path in options.paths:
try:
silva = root.unrestrictedTraverse(path)
except KeyError:
fail("%s is not a valid Zope path" % path)
if not IRoot.providedBy(silva):
fail("%s is not a valid Silva root" % path)
if ISite.providedBy(silva):
setSite(silva)
else:
setSite(None)
setHooks()
if hasattr(options, 'username') and options.username:
user = zope_find_user(silva, options.username)
newSecurityManager(None, user)
yield silva, options
try:
parent.next()
except StopIteration:
pass
else:
fail(u"internal error")
示例6: test_enable_site
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def test_enable_site(self):
"""Event handler should have configured local sitemanager."""
mnet = self.portal['maastricht']
self.assertTrue(ISite.providedBy(mnet))
self.assertTrue(IObjectManagerSite.providedBy(mnet))
self.assertNotEquals(self.portal.getSiteManager(),
mnet.getSiteManager())
示例7: enableZope3Site
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def enableZope3Site(context):
portal = getToolByName(context, 'portal_url').getPortalObject()
if not ISite.providedBy(portal):
make_objectmanager_site(portal)
logger.info('Made the portal a Zope3 site.')
try:
components = portal.getSiteManager()
except ComponentLookupError:
next = find_next_sitemanager(portal)
if next is None:
next = base
name = '/'.join(portal.getPhysicalPath())
components = PersistentComponents(name, (next,))
components.__parent__ = portal
portal.setSiteManager(components)
logger.info("Site manager '%s' added." % name)
else:
if components.utilities.LookupClass != FiveVerifyingAdapterLookup:
# for CMF 2.1 beta instances
components.__parent__ = portal
components.utilities.LookupClass = FiveVerifyingAdapterLookup
components.utilities._createLookup()
components.utilities.__parent__ = components
logger.info('LookupClass replaced.')
# Make sure to set the new site as the new active one
setSite(portal)
示例8: findSite
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def findSite(container):
"""Return the nearest site.
"""
if ISite.providedBy(container):
return container
return findNextSite(container)
示例9: unregisterService
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def unregisterService(service, interface):
"""Unregister the service using the given interface.
"""
site = service.aq_parent
if not ISite.providedBy(site):
raise ValueError("Service parent is not a site.")
sm = ISite(site).getSiteManager()
sm.unregisterUtility(service, interface)
示例10: validate
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def validate(self, context):
if context is self.startpoint:
return False
if ISite.providedBy(context):
for obj in context.objectValues():
if IFilesService.providedBy(obj):
raise StopIteration()
return False
示例11: activate
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def activate(context):
"""Change the context to a local site.
"""
if not ISite.providedBy(context):
create_new_sm(context)
sm = context.getSiteManager()
if IFiveSiteManager is not None and IFiveSiteManager.providedBy(sm):
clean_old_five_sm(context, create=True)
setup_intid(context)
示例12: closest_short_url_service
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def closest_short_url_service(location):
# XXX Why not use getUtility ?
while location:
if ISite.providedBy(location):
service = location._getOb(SERVICE_NAME, None)
if service is not None and \
IShortURLService.providedBy(service):
return service
location = aq_parent(location)
return None
示例13: test_utility_only_in_local_site
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def test_utility_only_in_local_site(self):
# A service_customization can be added only in a local site.
self.assertTrue(ISite.providedBy(self.root))
factory = self.root.manage_addProduct['Silva']
factory.manage_addPublication('publication', 'Publication')
self.publication = self.root.publication
self.assertFalse(ISite.providedBy(self.publication))
factory = self.publication.manage_addProduct['silva.core.layout']
self.assertRaises(BadRequest,
factory.manage_addCustomizationService,
'service_customization')
# Now our publication become a local site.
make_objectmanager_site(self.publication)
self.assertTrue(ISite.providedBy(self.publication))
factory = self.publication.manage_addProduct['silva.core.layout']
factory.manage_addCustomizationService('service_customization')
self.assertTrue(hasattr(self.publication, 'service_customization'))
示例14: find_next_sitemanager
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def find_next_sitemanager(site):
"""Find the closest sitemanager that is not the specified site's
sitemanager.
"""
while True:
site = get_parent(site, default=None)
if site is None:
return None
if ISite.providedBy(site):
return site.getSiteManager()
示例15: upgrade
# 需要导入模块: from zope.location.interfaces import ISite [as 别名]
# 或者: from zope.location.interfaces.ISite import providedBy [as 别名]
def upgrade(self, root):
# If it's a Five site manager disable it first. The annoying
# part might be that the code might already have been removed
# from Zope ...
setattr(root, '__initialization__', True)
if ISite.providedBy(root):
sm = root.getSiteManager()
if ((IFiveSiteManager is not None and
IFiveSiteManager.providedBy(sm)) or
isinstance(sm, ZODB.broken.Broken)):
setSite(None)
setHooks()
unregisterBeforeTraverse(aq_base(root), '__local_site_hook__')
if hasattr(aq_base(root), '__local_site_hook__'):
delattr(aq_base(root), '__local_site_hook__')
zope.interface.noLongerProvides(root, ISite)
root.setSiteManager(None)
else:
# Cleanup broken utilities
for registration in list(sm.registeredUtilities()):
if isinstance(registration.component, ZODB.broken.Broken):
sm.unregisterUtility(
registration.component,
registration.provided)
# Activate local site, add an intid service.
ism = interfaces.ISiteManager(root)
if not ism.is_site():
ism.make_site()
setSite(root)
setHooks()
# Delete unused Silva Document service
for s in ['service_doc_previewer',
'service_nlist_previewer',
'service_sub_previewer',]:
if hasattr(root, s):
root.manage_delObjects([s,])
# Update service_files settings
service_files = root.service_files
if hasattr(aq_base(service_files), '_filesystem_storage_enabled'):
service_files.storage = BlobFile
delattr(service_files , '_filesystem_storage_enabled')
elif service_files.storage is not BlobFile:
# For the upgrade
service_files.storage = BlobFile
# Disable quota verification (but not accounting if this
# enabled) during the migration, so the file migration can
# safely happens.
root.service_extensions._quota_verify = False
return root