# Quizz3 Supplements question27 = Column('question27', Integer) question28 = Column('question28', Integer) question29 = Column('question29', Integer) question30 = Column('question30', Integer) question31 = Column('question31', Integer) question32 = Column('question32', Integer) question33 = Column('question33', Integer) question34 = Column('question34', Integer) # Extra questions extra_questions = Column('extra_questions', Text) global_utility(Quizz3, provides=IQuizz, name='quizz3', direct=True) @implementer(IQuizzSecurity) class SecurityCheck(Subscription): context(Interface) def check(self, name, quizz, context): return True if name == 'quizz3': principal = current_principal() if (principal.id.endswith('bgetem.de') or principal.id.endswith("novareto.de") or principal.id.endswith("bayernwerk.de") or principal.id.endswith("*****@*****.**")): return True
class ClubMaker(grok.GlobalUtility): grok.implements(IClub) interface.classProvides(IClubMaker) grok.direct() grok.name('maker') class IFireplace(interface.Interface): pass class IHome(interface.Interface): pass class Fireplace(object): grok.implements(IFireplace) class Home(object): grok.implements(IFireplace, IHome) grok.global_utility(Fireplace) grok.global_utility(Fireplace, name='hot') grok.global_utility(Home, provides=IHome) grok.global_utility(NightClub, name='cool') grok.global_utility(NightClub, provides=ISpikyClub) grok.global_utility(SmallClub, provides=ITinyClub) grok.global_utility(SmallClub, name='small') grok.global_utility(SmallClub(), name='smallish', direct=True)
class MessageFactory(object): grok.implements(IFactory) title = u'Message Factory' description = u'Help creating a new message' def getInterfaces(self): return implementedBy(Message) def __call__(self, body=None, header_frame=None, method_frame=None, channel=None, tx_select=None): return Message(body=body, header_frame=header_frame, method_frame=method_frame, channel=channel, tx_select=tx_select) grok.global_utility(MessageFactory, provides=IFactory, name='AMQPMessage') class MessageArrivedEvent(ObjectEvent): """A message has been received""" implements(IMessageArrivedEvent) class MessageArrivedEventFactory(object): grok.implements(IFactory) title = u'Message Arrived Event Factory' description = u'Help creating a new message arrived event' def getInterfaces(self):
# -*- coding: utf-8 -*- """Register a global message receiver and a global session based message source. """ import grokcore.component as grok import z3c.flashmessage grok.global_utility(z3c.flashmessage.receiver.GlobalMessageReceiver) grok.global_utility(z3c.flashmessage.sources.SessionMessageSource, name='session')
""" Subclasses of grok.GlobalUtility that implement more than one interface must specify which interface to use for the registration: >>> grok.testing.grok(__name__) Traceback (most recent call last): ... GrokError: <class 'grokcore.component.tests.utility.implementsmany2.Club'> is implementing more than one interface (use grok.provides to specify which one to use). """ import grokcore.component as grok from zope import interface class IClub(interface.Interface): pass class ISpikyClub(interface.Interface): pass @grok.implementer(IClub, ISpikyClub) class Club(object): pass grok.global_utility(Club)
""" Subclasses of grok.GlobalUtility that are supposed to be registered directly as utilities and which provide more than one interface must specify which interface to use for the registration: >>> grok.testing.grok(__name__) Traceback (most recent call last): ... GrokError: <class 'grokcore.component.tests.utility.providesmany2.Club'> provides more than one interface (use grok.provides to specify which one to use). """ import grokcore.component as grok from zope import interface class IClub(interface.Interface): pass class ISpikyClub(interface.Interface): pass @interface.provider(IClub, ISpikyClub) class Club(object): pass grok.global_utility(Club, direct=True)
# -*- coding: utf-8 -*- # Copyright (c) 2007-2013 NovaReto GmbH # [email protected] import transaction from grokcore.component import global_utility from nva.mq.interfaces import ISender, IListener from nva.mq.manager import Message, MQTransaction from nva.mq.queue import IEmissionQueue from zope.component import getUtility, getGlobalSiteManager, getUtilitiesFor from nva.mq import log, reader from threading import Thread #test purposes global_utility(reader.BaseReader, IListener, direct=True) class Sender(object): def __init__(self, url, queues): self.url = url self.queues = queues def send(self, message): with transaction.manager as tm: log.debug('Sending Message for routing_key %s' % (message.type)) with MQTransaction(self.url, self.queues, tm) as message_manager: message_manager.createMessage(message)
grok.name('mixed class') class Mixed2(grok.GlobalUtility): grok.implements(IUtilityInterface) grok.name('mixed class') class Direct1(grok.GlobalUtility): classProvides(IUtilityInterface) grok.name('direct class') grok.direct() class Direct2(grok.GlobalUtility): classProvides(IUtilityInterface) grok.name('direct class') grok.direct() class ClassLevel(grok.GlobalUtility): """This utility inherits from Grok's base class and is registered this way.""" grok.implements(IUtilityInterface) grok.name('class and module') class ModuleLevel(object): """This utility doesn't inherit from Grok's base class and is registered explicitly using the module-level directive below.""" grok.implements(IUtilityInterface) grok.global_utility(ModuleLevel, name='class and module')
<InterfaceClass grokcore.component.tests.directive.multipletimes.IClub> >>> name 'foo' >>> factory, provides, name, direct = guis[1] >>> factory <class 'grokcore.component.tests.directive.multipletimes.Cave'> >>> provides is None True >>> name u'' """ import grokcore.component as grok from zope import interface class IClub(interface.Interface): pass class ICave(interface.Interface): pass class Club(object): grok.implements(IClub) class Cave(object): grok.implements(ICave) grok.global_utility(Club, provides=IClub, name='foo') grok.global_utility(Cave)