def installSiteHook(_context, class_, site_class=None): if site_class is None: if not IPossibleSite.implementedBy(class_): # This is not a possible site, we need to monkey-patch it so that # it is. site_class = FiveSite else: if not IPossibleSite.implementedBy(site_class): raise ConfigurationError('Site class does not implement ' 'IPossibleClass: %s' % site_class) # only install the hook once already = getattr(class_, '_localsite_marker', False) if site_class is not None and not already: class_._localsite_marker = True _context.action( discriminator = (class_,), callable = classSiteHook, args=(class_, site_class) ) _context.action( discriminator = (class_, IPossibleSite), callable = classImplements, args=(class_, IPossibleSite) )
def installSiteHook(_context, class_, site_class=None): if site_class is None: if not IPossibleSite.implementedBy(class_): # This is not a possible site, we need to monkey-patch it so that # it is. site_class = FiveSite else: if not IPossibleSite.implementedBy(site_class): raise ConfigurationError('Site class does not implement ' 'IPossibleClass: %s' % site_class) if site_class is not None: _context.action(discriminator=(class_, ), callable=classSiteHook, args=(class_, site_class)) _context.action(discriminator=(class_, IPossibleSite), callable=classImplements, args=(class_, IPossibleSite))
def installSiteHook(_context, class_, site_class=None): if site_class is None: if not IPossibleSite.implementedBy(class_): # This is not a possible site, we need to monkey-patch it so that # it is. site_class = FiveSite else: if not IPossibleSite.implementedBy(site_class): raise ConfigurationError('Site class does not implement ' 'IPossibleClass: %s' % site_class) if site_class is not None: _context.action( discriminator = (class_,), callable = classSiteHook, args=(class_, site_class) ) _context.action( discriminator = (class_, IPossibleSite), callable = classImplements, args=(class_, IPossibleSite) )
def enableLocalSiteHook(obj): """Install __before_traverse__ hook for Local Site """ # We want the original object, not stuff in between, and no acquisition obj = aq_base(obj) if not IPossibleSite.providedBy(obj): raise TypeError, 'Must provide IPossibleSite' hook = AccessRule(HOOK_NAME) registerBeforeTraverse(obj, hook, HOOK_NAME, 1) if not hasattr(obj, HOOK_NAME): setattr(obj, HOOK_NAME, LocalSiteHook()) directlyProvides(obj, ISite, directlyProvidedBy(obj))
def enableSite(obj, iface=ISite): """Install __before_traverse__ hook for Local Site """ # We want the original object, not stuff in between, and no acquisition obj = aq_base(obj) if not IPossibleSite.providedBy(obj): raise TypeError, 'Must provide IPossibleSite' hook = AccessRule(HOOK_NAME) registerBeforeTraverse(obj, hook, HOOK_NAME, 1) if not hasattr(obj, HOOK_NAME): setattr(obj, HOOK_NAME, LocalSiteHook()) zope.interface.alsoProvides(obj, iface)
def installSiteHook(_context, class_, site_class=None): warnings.warn_explicit( "The five:localsite directive is deprecated and " "will be removed in Zope 2.12. \n" "See Five/doc/localsite.txt .", DeprecationWarning, _context.info.file, _context.info.line) if site_class is not None: _context.action(discriminator=(class_, ), callable=classSiteHook, args=(class_, site_class)) if not IPossibleSite.implementedBy(class_): _context.action(discriminator=(class_, IPossibleSite), callable=classImplements, args=(class_, IPossibleSite))
def installSiteHook(_context, class_, site_class=None): warnings.warn_explicit("The five:localsite directive is deprecated and " "will be removed in Zope 2.12. \n" "See Five/doc/localsite.txt .", DeprecationWarning, _context.info.file, _context.info.line) if site_class is not None: _context.action( discriminator = (class_,), callable = classSiteHook, args=(class_, site_class) ) if not IPossibleSite.implementedBy(class_): _context.action( discriminator = (class_, IPossibleSite), callable = classImplements, args=(class_, IPossibleSite) )
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.app.component.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 >>> ensure_site(om) >>> ISite.providedBy(om) 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): enableLocalSiteHook(context) setSite(context) if not ISite.providedBy(context): raise TypeError('Somehow trying to configure "%s" as an ISite ' 'has failed' % '/'.join(context.getPhysicalPath()))
def installSiteHook(_context, class_, site_class=None): warnings.warn_explicit( "The five:localsite directive is deprecated and " "will be removed in Zope 2.12. \n" "See Five/doc/localsite.txt .", DeprecationWarning, _context.info.file, _context.info.line) # only install the hook once already = getattr(class_, '_localsite_marker', False) if site_class is not None and not already: class_._localsite_marker = True _context.action(discriminator=(class_, ), callable=classSiteHook, args=(class_, site_class)) if not IPossibleSite.implementedBy(class_): _context.action(discriminator=(class_, IPossibleSite), callable=classImplements, args=(class_, IPossibleSite))
def installSiteHook(_context, class_, site_class=None): warnings.warn_explicit("The five:localsite directive is deprecated and " "will be removed in Zope 2.12. \n" "See Five/doc/localsite.txt .", DeprecationWarning, _context.info.file, _context.info.line) # only install the hook once already = getattr(class_, '_localsite_marker', False) if site_class is not None and not already: class_._localsite_marker = True _context.action( discriminator = (class_,), callable = classSiteHook, args=(class_, site_class) ) if not IPossibleSite.implementedBy(class_): _context.action( discriminator = (class_, IPossibleSite), callable = classImplements, args=(class_, IPossibleSite) )