当前位置: 首页>>代码示例>>Python>>正文


Python declarations.implementedBy函数代码示例

本文整理汇总了Python中zope.interface.declarations.implementedBy函数的典型用法代码示例。如果您正苦于以下问题:Python implementedBy函数的具体用法?Python implementedBy怎么用?Python implementedBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了implementedBy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _getAdapterRequired

def _getAdapterRequired(factory, required):
    if required is None:
        try:
            required = factory.__component_adapts__
        except AttributeError:
            raise TypeError(
                "The adapter factory doesn't have a __component_adapts__ "
                "attribute and no required specifications were specified"
                )
    elif ISpecification.providedBy(required):
        raise TypeError("the required argument should be a list of "
                        "interfaces, not a single interface")

    result = []
    for r in required:
        if r is None:
            r = Interface
        elif not ISpecification.providedBy(r):
            if isinstance(r, CLASS_TYPES):
                r = implementedBy(r)
            else:
                raise TypeError("Required specification must be a "
                                "specification or class."
                                )
        result.append(r)
    return tuple(result)
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:26,代码来源:registry.py

示例2: implementedBy

    def implementedBy(self, cls):
        """Test whether the specification is implemented by a class or factory.

        Raise TypeError if argument is neither a class nor a callable.
        """
        spec = implementedBy(cls)
        return self in spec._implied
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:7,代码来源:interface.py

示例3: __get__

 def __get__(self, inst, cls=None):
     global generated
     if inst is None:
         return getObjectSpecification(cls)
     spec = getattr(inst, '__provides__', None)
     if spec is None:
         spec = implementedBy(cls)
     signature = getattr(inst, 'signature', None)
     if signature is None:
         return spec
     if not ismd5hex(signature):
         if not isdottedname(signature):
             return spec
         # not an md5 signature, so perhaps we have a dotted name
         try:
             iface = resolve(signature)
             if not IInterface.providedBy(iface):
                 raise ValueError('Not interface: %s' % signature)
             return Implements(iface, spec)
         except ImportError:
             logger.warning('SignatureAwareDescriptor: '
                            'unabled to resolve interface '
                            '%s by dotted name.')
             return spec
     iface_name = 'I%s' % signature
     dynamic = [getattr(generated, iface_name)]
     dynamic.append(spec)
     spec = Implements(*dynamic)
     return spec
开发者ID:upiq,项目名称:uu.dynamicschema,代码行数:29,代码来源:schema.py

示例4: _getAdapterProvided

def _getAdapterProvided(factory):
    provided = list(implementedBy(factory))
    if len(provided) == 1:
        return provided[0]
    raise TypeError(
        "The adapter factory doesn't implement a single interface "
        "and no provided interface was specified.")
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:7,代码来源:registry.py

示例5: __get__

    def __get__(self, inst, cls=None):
        if inst is None:
            return getObjectSpecification(cls)

        tp = inst.__type__
        cached = getattr(tp, '_v__providedBy', _marker)
        if cached is not _marker:
            return cached

        provided = [implementedBy(inst.__class__)]
        bhreg = AdapterRegistry()
        for behavior in tp.behaviors:
            behavior = queryBehavior(behavior)
            if behavior is not None:
                bhreg.register((), behavior.spec, '', behavior)
                provided.append(behavior.spec)

        schreg = AdapterRegistry()
        for schId in tp.schemas:
            sch = querySchema(schId)
            if sch is not None and sch.spec not in provided:
                schreg.register((), sch.spec, '', sch)
                provided.append(sch.spec)

        spec = Implements(*provided)

        tp._v__providedBy = spec
        tp._v__bhCache = bhreg
        tp._v__schCache = schreg

        return spec
开发者ID:fafhrd91,项目名称:memphis-dev,代码行数:31,代码来源:instance.py

示例6: __get__

    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 data we need to know if our cache needs to be invalidated
        direct_spec = getattr(inst, '__provides__', None)
        portal_type = getattr(inst, 'portal_type', None)
        
        spec = direct_spec

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

        # If the instance has no portal type, then we're done.
        if portal_type is None:
            return spec

        fti = queryUtility(IDexterityFTI, name=portal_type)
        if fti is None:
            return spec

        schema = SCHEMA_CACHE.get(portal_type)
        subtypes = SCHEMA_CACHE.subtypes(portal_type)

        # Find the cached value. This calculation is expensive and called
        # hundreds of times during each request, so we require a fast cache
        cache = getattr(inst, '_v__providedBy__', None)
        updated = inst._p_mtime, schema, subtypes, direct_spec

        # See if we have a valid cache. Reasons to do this include:
        #
        #  - The schema was modified.
        #  - The subtypes were modified.
        #  - The instance was modified and persisted since the cache was built.
        #  - The instance has a different direct specification.
        if cache is not None:
            cached_mtime, cached_schema, cached_subtypes, \
                cached_direct_spec, cached_spec = cache

            if cache[:-1] == updated:
                return cached_spec

        dynamically_provided = [] if schema is None else [schema]
        dynamically_provided.extend(subtypes)

        # If we have neither a schema, nor a subtype, then we're also done.
        if not dynamically_provided:
            return spec

        dynamically_provided.append(spec)
        spec = Implements(*dynamically_provided)
        inst._v__providedBy__ = updated + (spec, )

        return spec
开发者ID:numahell,项目名称:plone.dexterity,代码行数:57,代码来源:content.py

示例7: setup

    def setup(self, *args, **kwargs):
        super(ChatCommandPlugin, self).setup(*args, **kwargs)

        for name in dir(self):
            cls = getattr(self, name)
            try:
                if ICommand in implementedBy(cls):
                    log.info("Loading command {0}".format(cls.__name__))
                    self.commands.append(cls(self))
            except (DoesNotImplement, TypeError, AttributeError):
                pass
开发者ID:MiCurry,项目名称:hamper,代码行数:11,代码来源:interfaces.py

示例8: get

def get(adapted_iface, adapt=IDriver):
    """ Return registered adapter for a given class and interface. """

    if not isinstance(adapt, interface.InterfaceClass):
        if not inspect.isclass(adapt):
            adapt = adapt.__class__
        adapt = declarations.implementedBy(adapt)

    registred_type = _iface_registry.lookup1(adapt, adapted_iface, '')
    if not registred_type:
        raise NotImplementedError('No implementation has been registered')
    return registred_type
开发者ID:mardiros,项目名称:aiorm,代码行数:12,代码来源:registry.py

示例9: get

def get(adapted_iface, original_iface=IDriver):
    """ Return registered adapter for a given class and interface. """

    if not isinstance(original_iface, interface.InterfaceClass):
        if hasattr(original_iface, '__class__'):
            original_iface = original_iface.__class__
        original_iface = declarations.implementedBy(original_iface)

    registred_type = _iface_registry.lookup1(original_iface, adapted_iface, '')
    if not registred_type:
        raise NotImplementedError('No implementation has been registered')
    return registred_type
开发者ID:mardiros,项目名称:apium,代码行数:12,代码来源:registry.py

示例10: getAdapterFactory

def getAdapterFactory(fromInterface, toInterface, default):
    """Return registered adapter for a given class and interface.

    Note that is tied to the *Twisted* global registry, and will
    thus not find adapters registered elsewhere.
    """
    self = globalRegistry
    if not isinstance(fromInterface, interface.InterfaceClass):
        fromInterface = declarations.implementedBy(fromInterface)
    factory = self.lookup1(fromInterface, toInterface)
    if factory is None:
        factory = default
    return factory
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:13,代码来源:components.py

示例11: registerFlattener

def registerFlattener(flattener, forType):
    """Register a function, 'flattener', which will be invoked when an object of type 'forType'
    is encountered in the stan dom. This function should return or yield strings, or objects
    for which there is also a flattener registered.
    
    flattener should take (original, ctx) where original is the object to flatten.
    """
    if type(flattener) is str or type(forType) is str:
        assert type(flattener) is str and type(forType) is str, "Must pass both strings or no strings to registerFlattener"
        flattener = util._namedAnyWithBuiltinTranslation(flattener)
        forType = util._namedAnyWithBuiltinTranslation(forType)

    if not isinstance(forType, interface.InterfaceClass):
        forType = declarations.implementedBy(forType)
        
    tpc.globalRegistry.register([forType], ISerializable, 'nevow.flat', flattener)
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:16,代码来源:ten.py

示例12: registerAdapter

def registerAdapter(adapterFactory, origInterface, *interfaceClasses):
    """Register an adapter class.

    An adapter class is expected to implement the given interface, by
    adapting instances implementing 'origInterface'. An adapter class's
    __init__ method should accept one parameter, an instance implementing
    'origInterface'.
    """
    assert interfaceClasses, "You need to pass an Interface"

    # deal with class->interface adapters:
    if not isinstance(origInterface, InterfaceClass):
        origInterface = declarations.implementedBy(origInterface)
        
    for interfaceClass in interfaceClasses:
        globalRegistry.register([origInterface], interfaceClass, '', adapterFactory)
开发者ID:comfuture,项目名称:numbler,代码行数:16,代码来源:compyCompat.py

示例13: register_adapter

def register_adapter(registry, adapter_factory, adapted, *interfaces):
    assert interfaces, "You need to pass an Interface"

    # deal with class->interface adapters:
    if not isinstance(adapted, interface.InterfaceClass):
        adapted_ = declarations.implementedBy(adapted)
    else:
        adapted_ = adapted

    for iface in interfaces:
        factory = registry.registered([adapted_], iface)
        if factory is not None:
            raise ValueError("an adapter (%s) was already registered."
                             % (factory, ))
    for iface in interfaces:
        registry.register([adapted_], iface, '', adapter_factory)

    return adapter_factory
开发者ID:pragmaticcoders,项目名称:serialization,代码行数:18,代码来源:adapter.py

示例14: __get__

    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
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:collective.alias,代码行数:42,代码来源:content.py

示例15: registerAdapter

def registerAdapter(adapterFactory, origInterface, *interfaceClasses):
    """Register an adapter class.

    An adapter class is expected to implement the given interface, by
    adapting instances implementing 'origInterface'. An adapter class's
    __init__ method should accept one parameter, an instance implementing
    'origInterface'.
    """
    assert interfaceClasses, "You need to pass an Interface"

    # deal with class->interface adapters:
    if not isinstance(origInterface, interface.InterfaceClass):
        origInterface = declarations.implementedBy(origInterface)

    for interfaceClass in interfaceClasses:
        factory = _registered(_vcoRegistry, origInterface, interfaceClass)
        if factory is not None:
            raise ValueError("an adapter (%s) was already registered." % (factory, ))
    for interfaceClass in interfaceClasses:
        _vcoRegistry.register([origInterface], interfaceClass, '', adapterFactory)
开发者ID:BillTheBest,项目名称:vmw.vco,代码行数:20,代码来源:components.py


注:本文中的zope.interface.declarations.implementedBy函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。