Beispiel #1
0

# Backport ZConfig-2.x behaviour of assuming UTF-8, not ASCII.
# (Actually the old behaviour probably was to rely on the py2 str laxness, but
# all we really want is utf-8, so that's alright.)
ZConfig.datatypes.stock_datatypes["string"] = six.ensure_text

if sys.version_info < (3, ):
    # Upstream has `lambda x: x` which is not _quite_ correct.
    fanstatic.compat.as_bytestring = six.ensure_binary


class BrowserRequest(zope.publisher.browser.BrowserRequest):
    def _parseCookies(self, text, result=None):
        """Upstream uses python stdlib SimpleCookie, which returns a completely
        empty result when one cookie contains a non-ASCII character.
        """
        if result is None:
            result = {}
        cookies = webob.cookies.RequestCookies({'HTTP_COOKIE': text})
        result.update(cookies)
        return result

    @classmethod
    def factory(cls):
        return cls


grok.global_utility(BrowserRequest.factory,
                    zope.app.publication.interfaces.IBrowserRequestFactory)
Beispiel #2
0
    # 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
Beispiel #3
0
# -*- 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')
  >>> 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)
"""
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)
Beispiel #6
0
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):
Beispiel #7
0
    grok.implements(IUtilityInterface)
    grok.name('mixed class')


@provider(IUtilityInterface)
class Direct1(grok.GlobalUtility):
    grok.name('direct class')
    grok.direct()


@provider(IUtilityInterface)
class Direct2(grok.GlobalUtility):
    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')
Beispiel #8
0
    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')
"""
Subclasses of grok.GlobalUtility must implement exactly one interface:

  >>> grok.testing.grok(__name__)
  Traceback (most recent call last):
    ...
  GrokError: <class 'grokcore.component.tests.utility.implementsnone2.Club'> must
  implement at least one interface (use grok.implements to specify).
"""
import grokcore.component as grok

class Club(object):
    pass

grok.global_utility(Club)
Beispiel #10
0
import grokcore.component as grok
from z3c.saconfig import EngineFactory, GloballyScopedSession
from z3c.saconfig.interfaces import IEngineCreatedEvent

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import relation

from megrok import rdb

TEST_DSN = 'sqlite:///:memory:'

engine_factory = EngineFactory(TEST_DSN)
scoped_session = GloballyScopedSession()

grok.global_utility(engine_factory, direct=True)
grok.global_utility(scoped_session, direct=True)

metadata = rdb.MetaData()


@grok.subscribe(IEngineCreatedEvent)
def setUpDatabase(event):
    rdb.setupDatabase(metadata)


rdb.metadata(metadata)


class Courses(rdb.Container):
    pass
Beispiel #11
0
    pass


@implementer(ISpecialContent)
class SpecialContent(content.Content):
    content.schema(ISpecialContent)
    content.name('MyContent')


class WorkflowState(workflow.WorkflowState, Adapter):
    context(ISpecialContent)
    provides(IWorkflowState)
    name("special")


class WorkflowInfo(workflow.WorkflowInfo, Adapter):
    context(ISpecialContent)
    provides(IWorkflowInfo)
    name = 'special'


create_transition = workflow.Transition(transition_id='create',
                                        title='create',
                                        source=None,
                                        destination=666)

global_utility(workflow.Workflow([create_transition]),
               provides=IWorkflow,
               name="special",
               direct=True)
Beispiel #12
0
# -*- 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)

Beispiel #13
0
    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)
Beispiel #14
0
        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):
"""
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)
Beispiel #16
0
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)
Beispiel #17
0
  <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)