How to use the zope.interface.implements function in Zope

To help you get started, we’ve selected a few Zope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tmoravec / fastjsonrpc / tests / test_server.py View on Github external
class ReceiverProtocol(Protocol):
            def __init__(self, finished):
                self.finished = finished
                self.body = []

            def dataReceived(self, bytes):
                self.body.append(bytes)

            def connectionLost(self, reason):
                self.finished.callback(''.join(self.body))


        class StringProducer(object):
            implements(IBodyProducer)

            def __init__(self, body):
                self.body = body
                self.length = len(body)

            def startProducing(self, consumer):
                consumer.write(self.body)
                return defer.succeed(None)

            def pauseProducing(self):
                pass

            def stopProducing(self):
                pass
github ned14 / Easyshop / easyshop.carts / easyshop / carts / adapters / cart_item_prices.py View on Github external
# zope imports
from zope.interface import implements
from zope.component import adapts

# easyshop imports
from easyshop.core.interfaces import ICartItem
from easyshop.core.interfaces import IPrices
from easyshop.core.interfaces import IPropertyManagement

class CartItemPrices:
    """Adapter which provides IPrices for cart item content objects.
    """
    implements(IPrices)
    adapts(ICartItem)
    
    def __init__(self, context):
        """
        """
        self.context = context

    def getPriceForCustomer(self):
        """Returns the customer price for a cart item. This is just the 
        customer product price plus the customer properties prices (can be
        positiv or negative) multiply with the amount.
        """
        product = self.context.getProduct()
        price  = IPrices(product).getPriceForCustomer()        

        # Add prices of selected properties
github twisted / ldaptor / docs / source / examples / addressbook / 05_form / addressbook.py View on Github external
from ldaptor.protocols import pureldap

class ILDAPConfig(Interface):
    """Addressbook configuration retrieval."""

    def getBaseDN(self):
        """Get the LDAP base DN, as a DistinguishedName."""

    def getServiceLocationOverrides(self):
        """
        Get the LDAP service location overrides, as a mapping of
        DistinguishedName to (host, port) tuples.
        """

class LDAPConfig(object):
    implements(ILDAPConfig)

    def __init__(self,
                 baseDN,
                 serviceLocationOverrides=None):
        self.baseDN = distinguishedname.DistinguishedName(baseDN)
        self.serviceLocationOverrides = {}
        if serviceLocationOverrides is not None:
            for k,v in serviceLocationOverrides.items():
                dn = distinguishedname.DistinguishedName(k)
                self.serviceLocationOverrides[dn]=v

    def getBaseDN(self):
        return self.baseDN

    def getServiceLocationOverrides(self):
        return self.serviceLocationOverrides
github zenoss / ZenPacks.zenoss.Microsoft.Windows / ZenPacks / zenoss / Microsoft / Windows / datasources / EventLogDataSource.py View on Github external
group=_t('WindowsEventLog'),
        title=_t('Event Log')
    )
    query = schema.Text(
        group=_t(u'WindowsEventLog'),
        title=_t('Event Query'),
        xtype='twocolumntextarea'
    )
    max_age = schema.Text(
        group=_t(u'WindowsEventLog'),
        title=_t('Max age of events to get (hours)'),
    )


class EventLogInfo(RRDDataSourceInfo):
    implements(IEventLogInfo)
    adapts(EventLogDataSource)

    testable = False
    cycletime = ProxyProperty('cycletime')
    eventlog = ProxyProperty('eventlog')
    query = ProxyProperty('query')
    max_age = ProxyProperty('max_age')


def string_to_lines(string):
    if isinstance(string, (list, tuple)):
        return string
    elif hasattr(string, 'splitlines'):
        return string.splitlines()
github dmclain / scrapy-heroku / scrapy_heroku / scheduler.py View on Github external
from zope.interface import implements

from scrapyd.interfaces import ISpiderScheduler

from .utils import get_spider_queues


class Psycopg2SpiderScheduler(object):
    implements(ISpiderScheduler)

    def __init__(self, config):
        self.config = config
        self.update_projects()

    def schedule(self, project, spider_name, **spider_args):
        q = self.queues[project]
        q.add(spider_name, **spider_args)

    def list_projects(self):
        return self.queues.keys()

    def update_projects(self):
        self.queues = get_spider_queues(self.config)
github twisted / imaginary / imaginary / events.py View on Github external
# -*- test-case-name: imaginary.test.test_actions.TargetActionTests.test_resolveTargetCaseInsensitively -*-

from zope.interface import implements

from twisted.python import context

from imaginary import iimaginary, language, eimaginary
from imaginary.idea import Proximity, ProviderOf


class Event(language.BaseExpress):
    implements(iimaginary.IConcept)

    actorMessage = targetMessage = toolMessage = otherMessage = None

    def __init__(self,
                 location=None, actor=None, target=None, tool=None,
                 actorMessage=None, targetMessage=None, toolMessage=None,
                 otherMessage=None):

        if location is None and actor is not None:
            location = actor.location

        self.location = location
        self.actor = actor
        self.target = target
        self.tool = tool
        if actorMessage is not None:
github senaite / senaite.core / bika / lims / content / referencesamplesfolder.py View on Github external
from bika.lims.interfaces import IHaveNoBreadCrumbs
from bika.lims.interfaces import IReferenceSamplesFolder
from plone.app.folder import folder
from plone.app.folder.folder import ATFolder
from Products.Archetypes.public import registerType
from Products.ATContentTypes.content import schemata
from zope.interface import implements


schema = folder.ATFolderSchema.copy()


class ReferenceSamplesFolder(ATFolder):
    """Root folder for Reference Samples
    """
    implements(IReferenceSamplesFolder, IHaveNoBreadCrumbs)

    schema = schema
    displayContentsTab = False
    security = ClassSecurityInfo()


schemata.finalizeATCTSchema(schema, folderish=True, moveDiscussion=False)

registerType(ReferenceSamplesFolder, PROJECTNAME)
github opennode / opennode-management / opennode / oms / model / model / proc.py View on Github external
def signal_handler(self, name):
        if name == 'STOP':
            log.msg("Stopping %s" % self.__name__, system='proc')
            self.paused = True
        elif name == 'CONT':
            log.msg("Continuing %s" % self.__name__, system='proc')
            self.paused = False


class IProcessStateRenderer(Interface):
    def __str__():
        pass


class DaemonStateRenderer(Adapter):
    implements(IProcessStateRenderer)
    context(DaemonProcess)

    def __str__(self):
        return "[%s%s]" % (self.context.__name__, ': paused' if self.context.paused else '')


class Task(ReadonlyContainer):
    implements(ITask)

    def __init__(self, name, parent, subject, deferred, cmdline, ptid,
                 signal_handler=None, principal=None, write_buffer=None):
        self.__name__ = name
        self.__parent__ = parent
        self.subject = subject
        self.deferred = deferred
        self.cmdline = cmdline
github collective / collective.cover / src / collective / cover / tiles / link.py View on Github external
remote_url = schema.TextLine(
        title=_(u'URL'),
        required=False,
    )

    uuid = schema.TextLine(
        title=_(u'UUID'),
        required=False,
        readonly=True,  # the field can not be edited or configured
    )


class LinkTile(PersistentCoverTile):

    implements(ILinkTile)

    index = ViewPageTemplateFile('templates/link.pt')

    # TODO: make it configurable
    is_configurable = False

    # XXX: can we do this without waking the object up?
    # XXX: commented because we're not rendering the date
#    def get_date(self):
#        # TODO: we must support be able to select which date we want to
#        # display
#        obj = uuidToObject(self.data['uuid'])
#        if obj:
#            return obj.Date()

    def get_remote_url(self):
github ploneintranet / ploneintranet / src / ploneintranet / invitations / events.py View on Github external
from zope.interface import Attribute
from zope.interface import Interface
from zope.interface import implements
from ploneintranet.core import ploneintranetCoreMessageFactory as _


class ITokenAccepted(Interface):

    token_id = Attribute(_(u"The id of the Token that was consumed"))


class TokenAccepted(object):
    """
    Event to be fired whenever a token is consumed
    """
    implements(ITokenAccepted)

    def __init__(self, token_id):
        self.token_id = token_id