How to use the zope.interface 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 applied-mixnetworks / txmix / tests / test_txmix.py View on Github external
@implementer(IKeyState)
class SphinxNodeKeyState:

    def __init__(self, public_key, private_key):
        self.public_key = public_key
        self.private_key = private_key

    def get_private_key(self):
        return self.private_key

    def get_public_key(self):
        return self.public_key

@zope.interface.implementer(IReader)
class FixedNoiseReader():

    def __init__(self, hexed_noise):
        self.noise = binascii.unhexlify(hexed_noise)
        self.count = 0
        self.fallback = RandReader()

    def read(self, n):
        if n > len(self.noise):
            print("%s > %s" % (n, len(self.noise)))
            return self.fallback.read(n)
        ret = self.noise[:n]
        self.noise = self.noise[n:]
        self.count += n
        return ret
github eea / eea.facetednavigation / eea / facetednavigation / browser / displays.py View on Github external
""" Faceted views
"""
from zope import interface
from zope import component
from Products.CMFDynamicViewFTI import interfaces as cmfdynifaces
from eea.facetednavigation.interfaces import IFacetedNavigable

class ContainerDynamicViews(object):
    """ Display
    """
    interface.implements(cmfdynifaces.IDynamicallyViewable)
    component.adapts(IFacetedNavigable)

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

    def getAvailableViewMethods(self):
        """Get a list of registered view method names
        """
        return [view[0] for view in self.getAvailableLayouts()]

    def getDefaultViewMethod(self):
        """Get the default view method name
        """
        return 'facetednavigation_view'

    def getAvailableLayouts(self):
github redhat-imaging / imagefactory / imgfac / builders / RHELBuilder.py View on Github external
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import zope
from IBuilder import IBuilder
from BaseBuilder import BaseBuilder

class RHELBuilder(BaseBuilder):
    """docstring for RHELBuilder"""
    zope.interface.implements(IBuilder)

# Initializer
    def __init__(self, template=None, target=None):
        super(RHELBuilder, self).__init__(template, target)

# Image actions
    def build_image(self, build_id=None):
        pass

    def abort(self):
        pass
github eevee / flax / flax / component.py View on Github external
# TODO none of these yet, but we should assert that they /are/ given as
# properties of the class
def derived_attribute(doc):
    attr = zi.Attribute(doc)
    attr.setTaggedValue('mode', 'derived')
    return attr


class IComponentFactory(zi.Interface):
    """An object that produces components.  Usually these are component
    classes, but sometimes they're wrapped in a `ComponentInitializer`.
    """
    interface = zi.Attribute("The interface this component implements.")
    component = zi.Attribute("The real underlying component class.")

    def init_entity_type(entity_type):
        """Run the component's `__typeinit__` on the given entity type."""

    def init_entity(entity):
        """Run the component's `__init__` on the given entity."""

    def adapt(entity):
        """Create a component that wraps the given entity.

        This is the actual component constructor, since calling is used for
        something else.
        """


@zi.implementer(IComponentFactory)
github zopefoundation / z3c.form / src / z3c / form / browser / password.py View on Github external
@zope.interface.implementer(interfaces.IFieldWidget)
def PasswordFieldWidget(field, request):
    """IFieldWidget factory for IPasswordWidget."""
    return widget.FieldWidget(field, PasswordWidget(request))
github twisted / twisted / twisted / cred / service.py View on Github external
class IService(components.Interface):
    """An authorized service for internet applications.
    """


class Service(app.ApplicationService):
    """I am a service that internet applications interact with.

    I represent a set of abstractions which users may interact with over a
    specified protocol.

    @see: L{twisted.spread.pb.Service}
    """

    interface.implements(IService)

    # ugh, load order
    perspectiveClass = Perspective

    serviceType = None
    serviceName = None

    def __init__(self, serviceName, serviceParent=None, authorizer=None, application=None):
        """Create me, attached to the given application.

        Arguments: application, a twisted.internet.app.Application instance.
        """
        warnings.warn("Cred services are deprecated, use realms instead.",
                      category=DeprecationWarning, stacklevel=2)
        self.perspectives = {}
        if application:
github twisted / twisted / twisted / trial / itrial.py View on Github external
Maintainer: Jonathan Lange
"""

from __future__ import division, absolute_import

import zope.interface as zi
from zope.interface import Attribute


class ITestCase(zi.Interface):
    """
    The interface that a test case must implement in order to be used in Trial.
    """

    failureException = zi.Attribute(
        "The exception class that is raised by failed assertions")


    def __call__(result):
        """
        Run the test. Should always do exactly the same thing as run().
        """


    def countTestCases():
        """
        Return the number of tests in this test case. Usually 1.
        """


    def id():
github foundit / Piped / piped / providers / web_provider.py View on Github external
class WebResourceProvider(service.MultiService):
    """ Provides HTTP interfaces.

    .. highlight:: yaml

    Example configuration::

        web:
            my_site: # logical name of the web service
                enabled: true/false
                ... # the rest of the keys/values are used by the :class:`WebSite`

    """
    interface.classProvides(piped_resource.IResourceProvider)

    def __init__(self):
        super(WebResourceProvider, self).__init__()

    def configure(self, runtime_environment):
        self.setName('web')
        self.setServiceParent(runtime_environment.application)

        self.sites = runtime_environment.get_configuration_value('web', dict())

        for site_name, site_configuration in self.sites.items():
            if not site_configuration.get('enabled', True):
                continue
            website = WebSite(site_name, site_configuration)
            website.setName(site_name)
            website.setServiceParent(self)
github tanmayb123 / AskTanmay-NLQA-System- / TanmayQA_CAG / zope / interface / document.py View on Github external
if rst:
        inline_literal = lambda s: "``%s``" % (s,)
    else:
        inline_literal = lambda s: s

    r = [inline_literal(I.getName())]
    outp = r.append
    level = 1

    if I.getDoc():
        outp(_justify_and_indent(_trim_doc_string(I.getDoc()), level))

    bases = [base
             for base in I.__bases__
             if base is not zope.interface.Interface
             ]
    if bases:
        outp(_justify_and_indent("This interface extends:", level, munge))
        level += 1
        for b in bases:
            item = "o %s" % inline_literal(b.getName())
            outp(_justify_and_indent(_trim_doc_string(item), level, munge))
        level -= 1

    namesAndDescriptions = sorted(I.namesAndDescriptions())

    outp(_justify_and_indent("Attributes:", level, munge))
    level += 1
    for name, desc in namesAndDescriptions:
        if not hasattr(desc, 'getSignatureString'):   # ugh...
            item = "%s -- %s" % (inline_literal(desc.getName()),
github collective / collective.table / collective / table / local.py View on Github external
# -*- coding: utf-8 -*-
"""Simple, local ZODB source of a table."""

from AccessControl import ClassSecurityInfo
from Products.Archetypes.utils import setSecurity
from collective.table import MessageFactory as _
from collective.table.interfaces import ILocalSource
from collective.table.source import BaseSource
from persistent.mapping import PersistentMapping
from zope import interface
from zope.annotation.interfaces import IAnnotations


class LocalSource(BaseSource):
    interface.implementsOnly(ILocalSource)
    security = ClassSecurityInfo()

    title = _(u'label_localsource', default=u'Locally stored')
    description = _(u'description_localsource',
        default=_('The rows for a local table are stored locally with the '
                  'content item'))
    configurationView = '@@collective.table.localconfig'
    editable = True
    sortable = False
    queryable = False

    @property
    def _annotations(self):
        mapping = IAnnotations(self.instance).setdefault(
            'collective.table.local', PersistentMapping())
        return mapping.setdefault(self.field.getName(), PersistentMapping())