コード例 #1
0
    def image_fields(self):
        """ read interface
        """
        fields = []

        for field in self.context.Schema().fields():
            if IBlobImageField in providedBy(field).interfaces() or \
               IImageField in providedBy(field).interfaces() and \
               field.get_size(self.context) > 0:
                fields.append(field)

        return fields
コード例 #2
0
    def image_fields(self):
        """ read interface
        """
        fields = []

        for field in self.context.Schema().fields():
            if IBlobImageField in providedBy(field).interfaces() or \
               IImageField in providedBy(field).interfaces() and \
               field.get_size(self.context) > 0:
                fields.append(field)

        return fields
コード例 #3
0
    def __get__(self, inst, cls=None):
        # We're looking at a class - fall back on default
        if inst is None:
            return getObjectSpecification(cls)

        # Find the cached value.
        cache = getattr(inst, "_v__providedBy__", None)

        # Find the data we need to know if our cache needs to be invalidated
        provided = link_provides = getattr(inst._context, "__provides__", None)

        # See if we have a valid cache, and if so return it
        if cache is not None:
            cached_mtime, cached_provides, cached_provided = cache

            if inst._p_mtime == cached_mtime and link_provides is cached_provides:
                return cached_provided

        # If the instance doesn't have a __provides__ attribute, get the
        # interfaces implied by the class as a starting point.
        if provided is None:
            provided = implementedBy(cls)

        # Add the interfaces provided by the target, but ensure that some problematic
        # interfaces are removed
        provided += providedBy(
            inst._context) - IIterateAware - IVersioningSupport
        provided += ISymlinkMarker

        inst._v__providedBy__ = inst._p_mtime, link_provides, provided
        return provided
コード例 #4
0
ファイル: interface.py プロジェクト: bennihepp/sandbox
    def providedBy(self, ob):
        """Is the interface implemented by an object

          >>> from zope.interface import *
          >>> class I1(Interface):
          ...     pass
          >>> class C(object):
          ...     implements(I1)
          >>> c = C()
          >>> class X(object):
          ...     pass
          >>> x = X()
          >>> I1.providedBy(x)
          False
          >>> I1.providedBy(C)
          False
          >>> I1.providedBy(c)
          True
          >>> directlyProvides(x, I1)
          >>> I1.providedBy(x)
          True
          >>> directlyProvides(C, I1)
          >>> I1.providedBy(C)
          True

        """
        spec = providedBy(ob)
        return self in spec._implied
コード例 #5
0
ファイル: registry.py プロジェクト: bennihepp/sandbox
def _getUtilityProvided(component):
    provided = list(providedBy(component))
    if len(provided) == 1:
        return provided[0]
    raise TypeError(
        "The utility doesn't provide a single interface "
        "and no provided interface was specified.")
コード例 #6
0
ファイル: registry.py プロジェクト: AlexanderHerlan/syncpy
def _getUtilityProvided(component):
    provided = list(providedBy(component))
    if len(provided) == 1:
        return provided[0]
    raise TypeError(
        "The utility doesn't provide a single interface "
        "and no provided interface was specified.")
コード例 #7
0
ファイル: components.py プロジェクト: UstadMobile/eXePUB
def getAdapter(obj, interfaceClass, default=_Nothing,
               adapterClassLocator=None, persist=None):
    """DEPRECATED. Return an object that implements the given interface.

    The result will be a wrapper around the object passed as a parameter, or
    the parameter itself if it already implements the interface. If no
    adapter can be found, the 'default' parameter will be returned.

    The recommended way of replacing uses of this function is to use
    IFoo(o), since getAdapter is tied to a specific Twisted registry
    and thus won't interoperate well.
    """
    warnings.warn("components.getAdapter() is deprecated.", ComponentsDeprecationWarning, stacklevel=2)
    if hasattr(obj, '__class__'):
        fixClassImplements(obj.__class__)
    self = globalRegistry
    if interfaceClass.providedBy(obj):
        return obj

    if persist != False:
        pkey = (id(obj), interfaceClass)
        if _adapterPersistence.has_key(pkey):
            return _adapterPersistence[pkey]

    factory = self.lookup1(declarations.providedBy(obj), interfaceClass)
    if factory != None:
        return factory(obj)

    if default == _Nothing:
        raise NotImplementedError
    else:
        return default
コード例 #8
0
    def providedBy(self, ob):
        """Is the interface implemented by an object

          >>> from zope.interface import *
          >>> class I1(Interface):
          ...     pass
          >>> class C(object):
          ...     implements(I1)
          >>> c = C()
          >>> class X(object):
          ...     pass
          >>> x = X()
          >>> I1.providedBy(x)
          False
          >>> I1.providedBy(C)
          False
          >>> I1.providedBy(c)
          True
          >>> directlyProvides(x, I1)
          >>> I1.providedBy(x)
          True
          >>> directlyProvides(C, I1)
          >>> I1.providedBy(C)
          True
        
        """
        spec = providedBy(ob)
        return self in spec._implied
コード例 #9
0
    def test_impl(self):
        myTask = MyTask()
#         print CabbageTask.implementedBy(MyTask)
#         print directlyProvides(myTask,Task)
        print type(MyTask)
        print list(providedBy(myTask))[0]
        print list(implementedBy(MyTask))
        myTask.run()
        pass
コード例 #10
0
        def image_fields(self):
            """ read interface
            """
            fields = []

            for field in self.context.getTypeInfo().lookupSchema():
                img_field = getattr(self.context, field, None)
                if img_field and IImage in providedBy(img_field).interfaces():
                    fields.append(img_field)

            return fields
コード例 #11
0
ファイル: adapter.py プロジェクト: pwarren/AGDeviceControl
    def adapter_hook(self, interface, object, name='', default=None):
        """Hook function used when calling interfaces.

        When called from Interface.__adapt__, only the interface and
        object parameters will be passed.
        
        """
        factory = self.lookup1(providedBy(object), interface, name)
        if factory is not None:
            return factory(object)

        return default
コード例 #12
0
def getInterfaces(klass):
    """DEPRECATED. Return list of all interfaces the class implements. Or the object provides.
    This is horrible and stupid. Please use zope.interface.providedBy() or implementedBy().
    """
    warnings.warn("getInterfaces should not be used, use providedBy() or implementedBy()", ComponentsDeprecationWarning, stacklevel=2)
    if isinstance(klass, (type, types.ClassType)):
        fixClassImplements(klass)
        l = list(declarations.implementedBy(klass))
    else:
        fixClassImplements(klass.__class__)
        l = list(declarations.providedBy(klass))
    r = []
    for i in l:
        r.extend(superInterfaces(i))
    return util.uniquify(r)
コード例 #13
0
ファイル: adapter.py プロジェクト: alga/vejas
    def adapter_hook(self, interface, object, name='', default=None):
        """Hook function used when calling interfaces.

        When called from Interface.__adapt__, only the interface and
        object parameters will be passed.

        If the factory produces `None`, then the default is returned. This
        allows us to prevent adaptation (if desired) and make the factory
        decide whether an adapter will be available.
        """
        factory = self.lookup1(providedBy(object), interface, name)
        if factory is not None:
            adapter = factory(object)
            if adapter is not None:
                return adapter
        return default
コード例 #14
0
ファイル: menu.py プロジェクト: SabatierBoris/CecileWebSite
    def is_allowed_to_view(request, view_name):
        """
        Check if the current user have the right to the view
        """
        try:
            reg = request.registry
        except AttributeError:
            reg = get_current_registry()

        request_iface = reg.queryUtility(IRouteRequest, name=view_name)
        provides = [IViewClassifier,
                    request_iface,
                    providedBy(request.context)]
        view = reg.adapters.lookup(provides, ISecuredView, name='')

        assert view is not None
        return view.__permitted__(request.context, request)
コード例 #15
0
ファイル: components.py プロジェクト: UstadMobile/eXePUB
def getInterfaces(klass):
    """DEPRECATED. Return list of all interfaces the class implements. Or the object provides.

    This is horrible and stupid. Please use zope.interface.providedBy() or implementedBy().
    """
    warnings.warn("getInterfaces should not be used, use providedBy() or implementedBy()", ComponentsDeprecationWarning, stacklevel=2)
    # try to support both classes and instances, giving different behaviour
    # which is HORRIBLE :(
    if isinstance(klass, (type, types.ClassType)):
        fixClassImplements(klass)
        l = list(declarations.implementedBy(klass))
    else:
        fixClassImplements(klass.__class__)
        l = list(declarations.providedBy(klass))
    r = []
    for i in l:
        r.extend(superInterfaces(i))
    return util.uniquify(r)
コード例 #16
0
ファイル: components.py プロジェクト: Jz52710/pythonPChong
    def addComponent(self, component, ignoreClass=0):
        """
        Add a component to me, for all appropriate interfaces.

        In order to determine which interfaces are appropriate, the component's
        provided interfaces will be scanned.

        If the argument 'ignoreClass' is True, then all interfaces are
        considered appropriate.

        Otherwise, an 'appropriate' interface is one for which its class has
        been registered as an adapter for my class according to the rules of
        getComponent.
        """
        for iface in declarations.providedBy(component):
            if (ignoreClass or (self.locateAdapterClass(
                    self.__class__, iface, None) == component.__class__)):
                self._adapterCache[reflect.qual(iface)] = component
コード例 #17
0
 def addComponent(self, component, ignoreClass=0, registry=None):
     """
     Add a component to me, for all appropriate interfaces.
     In order to determine which interfaces are appropriate, the component's
     provided interfaces will be scanned.
     If the argument 'ignoreClass' is True, then all interfaces are
     considered appropriate.
     Otherwise, an 'appropriate' interface is one for which its class has
     been registered as an adapter for my class according to the rules of
     getComponent.
     @return: the list of appropriate interfaces
     """
     if hasattr(component, "__class__"):
         fixClassImplements(component.__class__)
     for iface in declarations.providedBy(component):
         if (ignoreClass or
             (self.locateAdapterClass(self.__class__, iface, None, registry)
              == component.__class__)):
             self._adapterCache[reflect.qual(iface)] = component
コード例 #18
0
    def __get__(self, inst, cls=None):

        # We're looking at a class - fall back on default
        if inst is None:
            return getObjectSpecification(cls)

        # Find the cached value.
        cache = getattr(inst, '_v__providedBy__', None)

        # Find the data we need to know if our cache needs to be invalidated
        provided = alias_provides = getattr(inst, '__provides__', None)

        # See if we have a valid cache, and if so return it
        if cache is not None:
            cached_mtime, cached_provides, cached_provided = cache

            if (
                inst._p_mtime == cached_mtime and
                alias_provides is cached_provides
            ):
                return cached_provided

        # If the instance doesn't have a __provides__ attribute, get the
        # interfaces implied by the class as a starting point.
        if provided is None:
            assert cls == Alias # XXX: remove
            provided = implementedBy(cls)

        # Add the interfaces provided by the target
        target = aq_base(inst._target)
        if target is None:
            return provided # don't cache yet!

        # Add the interfaces provided by the target, but take away
        # IHasAlias if set
        provided += providedBy(target) - IHasAlias - IIterateAware

        if ITranslatable:
            provided -= ITranslatable

        inst._v__providedBy__ = inst._p_mtime, alias_provides, provided
        return provided
コード例 #19
0
    def __get__(self, inst, cls=None):

        # We're looking at a class - fall back on default
        if inst is None:
            return getObjectSpecification(cls)

        # Find the cached value.
        cache = getattr(inst, '_v__providedBy__', None)

        # Find the data we need to know if our cache needs to be invalidated
        provided = alias_provides = getattr(inst, '__provides__', None)

        # See if we have a valid cache, and if so return it
        if cache is not None:
            cached_mtime, cached_provides, cached_provided = cache

            if (inst._p_mtime == cached_mtime
                    and alias_provides is cached_provides):
                return cached_provided

        # If the instance doesn't have a __provides__ attribute, get the
        # interfaces implied by the class as a starting point.
        if provided is None:
            assert cls == Alias  # XXX: remove
            provided = implementedBy(cls)

        # Add the interfaces provided by the target
        target = aq_base(inst._target)
        if target is None:
            return provided  # don't cache yet!

        # Add the interfaces provided by the target, but take away
        # IHasAlias if set
        provided += providedBy(target) - IHasAlias - IIterateAware

        if ITranslatable:
            provided -= ITranslatable

        inst._v__providedBy__ = inst._p_mtime, alias_provides, provided
        return provided
コード例 #20
0
ファイル: components.py プロジェクト: BillTheBest/vmw.vco
def _hook(iface, ob, lookup=_vcoRegistry.lookup1):
    factory = lookup(declarations.providedBy(ob), iface)
    if factory is None:
        return None
    else:
        return factory(ob)
コード例 #21
0
ファイル: components.py プロジェクト: Jz52710/pythonPChong
 def _hook(iface, ob):
     factory = lookup(declarations.providedBy(ob), iface)
     if factory is None:
         return None
     else:
         return factory(ob)
コード例 #22
0
ファイル: interface.py プロジェクト: YazLuna/APIExpressJobs
 def providedBy(self, ob):
     """Is the interface implemented by an object
     """
     spec = providedBy(ob)
     return self in spec._implied
コード例 #23
0
ファイル: applications.py プロジェクト: f3at/feat
 def _adapter_hook(self, iface, ob):
     factory = self._adapters.lookup1(declarations.providedBy(ob), iface)
     return factory and factory(ob)
コード例 #24
0
 def providedBy(self, ob):
     """Is the interface implemented by an object
     """
     spec = providedBy(ob)
     return self in spec._implied
コード例 #25
0
def getFlattener(original):
    """Get a flattener function with signature (ctx, original) for the object original.
    """
    return tpc.globalRegistry.lookup1(declarations.providedBy(original),
                                      ISerializable, 'nevow.flat')
コード例 #26
0
def _lookup_adapter_hook(iface, ob):
    factory = registry.lookup1(declarations.providedBy(ob), iface)
    return factory and factory(ob)
コード例 #27
0
def _lookup_adapter_hook(iface, ob):
    factory = registry.lookup1(declarations.providedBy(ob), iface)
    return factory and factory(ob)
コード例 #28
0
 def _hook(iface, ob):
     factory = lookup(declarations.providedBy(ob), iface)
     if factory is None:
         return None
     else:
         return factory(ob)
コード例 #29
0
ファイル: components.py プロジェクト: BillTheBest/vmw.vco
def _hook(iface, ob, lookup=_vcoRegistry.lookup1):
    factory = lookup(declarations.providedBy(ob), iface)
    if factory is None:
        return None
    else:
        return factory(ob)
コード例 #30
0
ファイル: __init__.py プロジェクト: grodniewicz/oship
def queryType(object, interface):
    """Returns the object's interface which implements interface.

    >>> from zope.interface import Interface
    >>> class IContentType(Interface):
    ...    pass
    >>> from zope.interface import Interface, implements, directlyProvides
    >>> class I(Interface):
    ...     pass
    >>> class J(Interface):
    ...     pass
    >>> directlyProvides(I, IContentType)
    >>> class C(object):
    ...     implements(I)
    >>> class D(object):
    ...     implements(J,I)
    >>> obj = C()
    >>> c1_ctype = queryType(obj, IContentType)
    >>> c1_ctype.__name__
    'I'
    >>> class I1(I):
    ...     pass
    >>> class I2(I1):
    ...     pass
    >>> class I3(Interface):
    ...     pass
    >>> class C1(object):
    ...     implements(I1)
    >>> obj1 = C1()
    >>> c1_ctype = queryType(obj1, IContentType)
    >>> c1_ctype.__name__
    'I'
    >>> class C2(object):
    ...     implements(I2)
    >>> obj2 = C2()
    >>> c2_ctype = queryType(obj2, IContentType)
    >>> c2_ctype.__name__
    'I'

    >>> class C3(object):
    ...     implements(I3)
    >>> obj3 = C3()

    If Interface doesn't provide `IContentType`, `queryType` returns ``None``.

    >>> c3_ctype = queryType(obj3, IContentType)
    >>> c3_ctype
    >>> c3_ctype is None
    True
    >>> class I4(I):
    ...     pass
    >>> directlyProvides(I4, IContentType)
    >>> class C4(object):
    ...     implements(I4)
    >>> obj4 = C4()
    >>> c4_ctype = queryType(obj4, IContentType)
    >>> c4_ctype.__name__
    'I4'

    """
    # Remove the security proxy, so that we can introspect the type of the
    # object's interfaces.
    naked = removeSecurityProxy(object)
    object_iro = providedBy(naked).__iro__
    for iface in object_iro:
        if interface.providedBy(iface):
            return iface

    return None
コード例 #31
0
ファイル: ten.py プロジェクト: perkinslr/nevow-py3
def getFlattener(original):
    """Get a flattener function with signature (ctx, original) for the object original.
    """
    return tpc.globalRegistry.lookup1(declarations.providedBy(original), ISerializable, 'nevow.flat')