Exemplo n.º 1
0
def proxyForInterface(iface, originalAttribute='original'):
    """
    Create a class which proxies all method calls which adhere to an interface
    to another provider of that interface.

    This function is intended for creating specialized proxies. The typical way
    to use it is by subclassing the result::

      class MySpecializedProxy(proxyForInterface(IFoo)):
          def someInterfaceMethod(self, arg):
              if arg == 3:
                  return 3
              return self.original.someInterfaceMethod(arg)

    @param iface: The Interface to which the resulting object will conform, and
        which the wrapped object must provide.

    @param originalAttribute: name of the attribute used to save the original
        object in the resulting class. Default to C{original}.
    @type originalAttribute: C{str}

    @return: A class whose constructor takes the original object as its only
        argument. Constructing the class creates the proxy.
    """
    def __init__(self, original):
        setattr(self, originalAttribute, original)

    contents = {"__init__": __init__}
    for name in iface:
        contents[name] = _ProxyDescriptor(name, originalAttribute)
    proxy = type("(Proxy for %s)" % (reflect.qual(iface), ), (object, ),
                 contents)
    declarations.classImplements(proxy, iface)
    return proxy
def proxyForInterface(iface, originalAttribute='original'):
    """
    Create a class which proxies all method calls which adhere to an interface
    to another provider of that interface.

    This function is intended for creating specialized proxies. The typical way
    to use it is by subclassing the result::

      class MySpecializedProxy(proxyForInterface(IFoo)):
          def someInterfaceMethod(self, arg):
              if arg == 3:
                  return 3
              return self.original.someInterfaceMethod(arg)

    @param iface: The Interface to which the resulting object will conform, and
        which the wrapped object must provide.

    @param originalAttribute: name of the attribute used to save the original
        object in the resulting class. Default to C{original}.
    @type originalAttribute: C{str}

    @return: A class whose constructor takes the original object as its only
        argument. Constructing the class creates the proxy.
    """
    def __init__(self, original):
        setattr(self, originalAttribute, original)
    contents = {"__init__": __init__}
    for name in iface:
        contents[name] = _ProxyDescriptor(name, originalAttribute)
    proxy = type("(Proxy for %s)"
                 % (reflect.qual(iface),), (object,), contents)
    declarations.classImplements(proxy, iface)
    return proxy
Exemplo n.º 3
0
 def __new__(metacls, name, bases, dct):
     abstract = False
     if "_abstract" in dct:
         del dct["_abstract"]
         abstract = True
     new_class = type.__new__(metacls, name, bases, dct)
     if not abstract:
         classImplements(new_class, ISection)
         directlyProvides(new_class, ISectionBlueprint)
     return new_class
Exemplo n.º 4
0
 def __new__(metacls, name, bases, dct):
     abstract = False
     if "_abstract" in dct:
         del dct["_abstract"]
         abstract = True
     new_class = type.__new__(metacls, name, bases, dct)
     if not abstract:
         classImplements(new_class, ISection)
         directlyProvides(new_class, ISectionBlueprint)
     return new_class
Exemplo n.º 5
0
def _wire():
    from zope.interface.declarations import classImplements
    # From lest specific to most specific.
    from zope.interface.interfaces import IElement
    classImplements(Element, IElement)

    from zope.interface.interfaces import IAttribute
    classImplements(Attribute, IAttribute)

    from zope.interface.interfaces import IMethod
    classImplements(Method, IMethod)

    from zope.interface.interfaces import ISpecification
    classImplements(Specification, ISpecification)

    from zope.interface.interfaces import IInterface
    classImplements(InterfaceClass, IInterface)
Exemplo n.º 6
0
def _wire():
    from zope.interface.declarations import classImplements

    from zope.interface.interfaces import IAttribute
    classImplements(Attribute, IAttribute)

    from zope.interface.interfaces import IMethod
    classImplements(Method, IMethod)

    from zope.interface.interfaces import IInterface, ISpecification
    classImplements(InterfaceClass, IInterface)
    classImplements(Specification, ISpecification)
Exemplo n.º 7
0
def _wire():
    from zope.interface.declarations import classImplements

    from zope.interface.interfaces import IAttribute
    classImplements(Attribute, IAttribute)

    from zope.interface.interfaces import IMethod
    classImplements(Method, IMethod)

    from zope.interface.interfaces import IInterface, ISpecification
    classImplements(InterfaceClass, IInterface)
    classImplements(Specification, ISpecification)
Exemplo n.º 8
0
from zope.interface import Interface
from paco.models.base import Stack
from zope.interface.declarations import classImplements


class IStack(Interface):
    "A set of related cloud resources"


# add this interface to the paco.models class
classImplements(Stack, IStack)


class ICloudFormationStack(IStack):
    "A set of related AWS resources provisioned as CloudFormation Stack(s)"


class IBotoStack(IStack):
    "A set of related AWS resoruces provisioned with AWS API class"
Exemplo n.º 9
0
 def execute(self, class_, implements, **kw):
     if implements is None:
         return True
     classImplements(class_, implements)
     return True
Exemplo n.º 10
0
 def execute(self, class_, implements, **kw):
     if implements is None:
         return True
     classImplements(class_, implements)
     return True
Exemplo n.º 11
0
def register_utility(klass, *interfaces):
	classImplements(klass, *interfaces)
	zope.component.provideUtility(klass, interfaces[0], klass.__name__)
	return GSM.utilities.names([], interfaces[0])
Exemplo n.º 12
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# filename = interfaces
# author= KGerring
# date = 4/14/18
# from startups import *
"""


class IMyInterface(Interface):
	'''Interface documentation'''
	
@implementer(IMyInterface)
class MyInterface(object):
	pass
	
	
class My(object): pass

class My0(object): pass

classImplements(My0, IMyInterface)

	
m = My()
directlyProvides(m, IMyInterface)

IMyInterface.providedBy(m) == True          for instance usage
IMyInterface.implementedBy(My) == True      for class usage
zope.component.implementedBy(My)(IMyInterface) == True
Exemplo n.º 13
0
        for field in self.fields():
            if field.required:
                yield field
                
    def indexed_fields(self):
        for field in self.fields():
            if field.indexed:
                yield field
                
    def optional_fields(self):
        for field in self.fields():
            if not field.required:
                yield field 

Value = ValueClass("Value", __module__ = "yogomee.entity")
classImplements(ValueClass, interface.IValue)

class EntityClass(ValueClass):
    
    def __init__(self, name, bases=(), attrs=None, __doc__=None, __module__=None):
        ValueClass.__init__(self, name, bases, attrs, __doc__, __module__)
        identity = filter(lambda attr: interface.IIdentity.providedBy(attr), self._InterfaceClass__attrs.values())
        if __module__ != "yogomee.entity":
            if not len(identity):
                raise TypeError("No identity")
            if len(identity) > 1:
                raise TypeError("Entity must have only one Identity")
            self.__identity = identity[0]
    
    def identity(self):
        return self.__identity
Exemplo n.º 14
0
    def _setUpAdapters(self):
        from OFS.Folder import Folder
        from zope.app.tests import ztapi

        from zope.interface.declarations import classImplements
        classImplements(Folder, IObjectManager)

        #from OFS.Image import File

        from Products.CMFSetup.interfaces import IFilesystemExporter
        from Products.CMFSetup.interfaces import IFilesystemImporter
        from Products.CMFSetup.interfaces import ICSVAware
        from Products.CMFSetup.interfaces import IINIAware
        from Products.CMFSetup.interfaces import IDAVAware

        from Products.CMFSetup.content import \
             SimpleINIAware
        from Products.CMFSetup.content import \
             FolderishExporterImporter
        from Products.CMFSetup.content import \
             CSVAwareFileAdapter
        from Products.CMFSetup.content import \
             INIAwareFileAdapter
        from Products.CMFSetup.content import \
             DAVAwareFileAdapter

        ztapi.provideAdapter(IObjectManager,
                             IFilesystemExporter,
                             FolderishExporterImporter,
                            )

        ztapi.provideAdapter(IObjectManager,
                             IFilesystemImporter,
                             FolderishExporterImporter,
                            )

        ztapi.provideAdapter(IPropertyManager,
                             IINIAware,
                             SimpleINIAware,
                            )

        ztapi.provideAdapter(ICSVAware,
                             IFilesystemExporter,
                             CSVAwareFileAdapter,
                            )

        ztapi.provideAdapter(ICSVAware,
                             IFilesystemImporter,
                             CSVAwareFileAdapter,
                            )

        ztapi.provideAdapter(IINIAware,
                             IFilesystemExporter,
                             INIAwareFileAdapter,
                            )

        ztapi.provideAdapter(IINIAware,
                             IFilesystemImporter,
                             INIAwareFileAdapter,
                            )

        ztapi.provideAdapter(IDAVAware,
                             IFilesystemExporter,
                             DAVAwareFileAdapter,
                            )

        ztapi.provideAdapter(IDAVAware,
                             IFilesystemImporter,
                             DAVAwareFileAdapter,
                            )