• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python advice.addClassAdvisor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

 def __init__(self, field_name, widget, *args, **kwargs):
     self.field_name = field_name
     if widget is None:
         self.widget = None
     else:
         self.widget = CustomWidgetFactory(widget, *args, **kwargs)
     addClassAdvisor(self.advise)
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:7,代码来源:launchpadform.py


示例2: strictly_implements

def strictly_implements(*interfaces):
    frame = sys._getframe(1)
    f_locals = frame.f_locals

    # Try to make sure we were called from a class def. Assumes Python > 2.2.
    if f_locals is frame.f_globals or '__module__' not in f_locals:
        raise TypeError("implements can be used only from a class definition.")

    if '__implements_advice_data__' in f_locals:
        raise TypeError("implements can be used only once in a class definition.")

    def _implements_advice(cls):
        interfaces, classImplements = cls.__dict__['__implements_advice_data__']
        del cls.__implements_advice_data__
        classImplements(cls, *interfaces)

        if interesting_modules.match(cls.__module__):
            if not excluded_classnames.match(cls.__name__):
                for interface in interfaces:
                    try:
                        verifyClass(interface, cls)
                    except Exception as e:
                        print("%s.%s does not correctly implement %s.%s:\n%s"
                                       % (cls.__module__, cls.__name__,
                                          interface.__module__, interface.__name__, e), file=_err)
        else:
            _other_modules_with_violations.add(cls.__module__)
        return cls

    f_locals['__implements_advice_data__'] = interfaces, zi.classImplements
    addClassAdvisor(_implements_advice, depth=2)
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:31,代码来源:check-interfaces.py


示例3: ping

def ping(log, value):

    def pong(klass):
        log.append((value,klass))
        return [klass]

    addClassAdvisor(pong)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:7,代码来源:advisory_testing.py


示例4: kindInfo

def kindInfo(**attrs):
    """Declare metadata for a class' schema item

    The attributes defined by the keyword arguments will be set on the
    enclosing class' schema Item.  For example, the following class'
    repository Kind will have a ``displayName`` of ``"Example Item"``, and
    a ``displayAttribute`` of ``"someAttr"``::

        class SomeItem(schema.Item):
            schema.kindInfo(
                displayName = "Example Item",
                displayAttribute = "someAttr",
            )

    ``kindInfo()`` can only be used in the body of a class that derives from
    ``schema.Item`` or ``schema.Enumeration``, and it will only accept keywords
    that are valid attributes of the ``Kind`` or ``Enumeration`` kinds,
    respectively.

    (Note: if your class includes a ``__metaclass__`` definition, any calls to
    ``kindInfo`` must come *after* the ``__metaclass__`` assignment.)
    """
    _update_info('kindInfo','__kind_info__',attrs)

    def callback(cls):
        for k,v in attrs.items():
            if not hasattr(cls._kind_class, k):
                raise TypeError(
                    "%r is not an attribute of %s" %
                    (k, cls._kind_class.__name__)
                )
        return cls

    from zope.interface.advice import addClassAdvisor
    addClassAdvisor(callback)
开发者ID:HackLinux,项目名称:chandler-1,代码行数:35,代码来源:schema.py


示例5: __init__

 def __init__(self, arg1, arg2=None, status=None):
     if arg2 is None:
         self.fromname = None
         self.toname = arg1
     else:
         self.fromname = arg1
         self.toname = lambda self: arg2
         addClassAdvisor(self.advise)
     self.status = status
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:9,代码来源:publisher.py


示例6: __call__

    def __call__(self, fn):
        # We are being used as a descriptor.
        assert self.fromname is None, (
            "redirection() can not be used as a descriptor in its "
            "two argument form")

        self.fromname = self.toname
        self.toname = fn
        addClassAdvisor(self.advise)

        return fn
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:11,代码来源:publisher.py


示例7: implements

def implements(*ifaces):
    """
    This is a slight hack, it overrides the default zope.interface implements
    function because it to uses the addClassAdvisor functionality to delay its
    work till after the class is created.  So we must as well, and by placing
    our hook in here we avoid the client having to manually add it.
    """
    declarations._implements("implements", ifaces, _classImplements)

    # These are called after the class that
    advice.addClassAdvisor(_register_class)
    advice.addClassAdvisor(_verify_class)
开发者ID:venkatarajasekhar,项目名称:tortuga,代码行数:12,代码来源:core.py


示例8: _implements

def _implements(name, interfaces, classImplements):
    frame = sys._getframe(2)
    locals = frame.f_locals

    # Try to make sure we were called from a class def
    if (locals is frame.f_globals) or ('__module__' not in locals):
        raise TypeError(name+" can be used only from a class definition.")

    if '__implements_advice_data__' in locals:
        raise TypeError(name+" can be used only once in a class definition.")

    locals['__implements_advice_data__'] = interfaces, classImplements
    addClassAdvisor(_implements_advice, depth=3)
开发者ID:pwarren,项目名称:AGDeviceControl,代码行数:13,代码来源:declarations.py


示例9: delegates

def delegates(interface_spec, context='context'):
    """Make an adapter into a decorator.

    Use like:

        class RosettaProject:
            implements(IRosettaProject)
            delegates(IProject)

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

            def methodFromRosettaProject(self):
                return self.context.methodFromIProject()

    If you want to use a different name than "context" then you can explicitly
    say so:

        class RosettaProject:
            implements(IRosettaProject)
            delegates(IProject, context='project')

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

            def methodFromRosettaProject(self):
                return self.project.methodFromIProject()

    The adapter class will implement the interface it is decorating.

    The minimal decorator looks like this:

    class RosettaProject:
        delegates(IProject)

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

    """
    # pylint: disable-msg=W0212
    frame = sys._getframe(1)
    locals = frame.f_locals

    # Try to make sure we were called from a class def
    if (locals is frame.f_globals) or ('__module__' not in locals):
        raise TypeError(
            "delegates() can be used only from a class definition.")

    locals['__delegates_advice_data__'] = interface_spec, context
    addClassAdvisor(_delegates_advice, depth=2)
开发者ID:aregee,项目名称:Mailman,代码行数:50,代码来源:_delegates.py


示例10: classProvides

def classProvides(*interfaces):
    """Declare interfaces provided directly by a class

      This function is called in a class definition.

      The arguments are one or more interfaces or interface specifications
      (``IDeclaration`` objects).

      The given interfaces (including the interfaces in the specifications)
      are used to create the class's direct-object interface specification.
      An error will be raised if the module class has an direct interface
      specification. In other words, it is an error to call this function more
      than once in a class definition.

      Note that the given interfaces have nothing to do with the interfaces
      implemented by instances of the class.

      This function is provided for convenience. It provides a more convenient
      way to call directlyProvides for a class. For example::

        classProvides(I1)

      is equivalent to calling::

        directlyProvides(theclass, I1)

      after the class has been created.
    """
    # This entire approach is invalid under Py3K.  Don't even try to fix
    # the coverage for this block there. :(
                       
    if PYTHON3: #pragma NO COVER
        raise TypeError(_ADVICE_ERROR % 'provider')

    frame = sys._getframe(1)
    locals = frame.f_locals

    # Try to make sure we were called from a class def
    if (locals is frame.f_globals) or ('__module__' not in locals):
        raise TypeError("classProvides can be used only from a "
                        "class definition.")

    if '__provides__' in locals:
        raise TypeError(
            "classProvides can only be used once in a class definition.")

    locals["__provides__"] = _normalizeargs(interfaces)

    addClassAdvisor(_classProvides_advice, depth=2)
开发者ID:godseraph,项目名称:PyTest,代码行数:49,代码来源:declarations.py


示例11: _implements

def _implements(name, interfaces, classImplements):
    frame = sys._getframe(2)
    locals = frame.f_locals

    # Try to make sure we were called from a class def. In 2.2.0 we can't
    # check for __module__ since it doesn't seem to be added to the locals
    # until later on.
    if (locals is frame.f_globals) or (
        ('__module__' not in locals) and sys.version_info[:3] > (2, 2, 0)):
        raise TypeError(name+" can be used only from a class definition.")

    if '__implements_advice_data__' in locals:
        raise TypeError(name+" can be used only once in a class definition.")

    locals['__implements_advice_data__'] = interfaces, classImplements
    addClassAdvisor(_implements_advice, depth=3)
开发者ID:alga,项目名称:vejas,代码行数:16,代码来源:declarations.py


示例12: instanceClassOf

def instanceClassOf(typeClass):
    """Signal that the class suite is an instance factory for the
    specified protocol class.

    The instance class must have a constructor that accepts no arguments.
    """
    def callback(instanceClass):
        class InstanceFactory:
            def __init__(self, protocolClass):
                pass
            def buildInstance(self):
                return instanceClass()
        components.registerAdapter(InstanceFactory, typeClass, 
                                   igwt.IInstanceFactory)
        annotation.registerTypeAdapter(typeClass, instanceClass)
        return instanceClass
    advice.addClassAdvisor(callback)
开发者ID:jrydberg,项目名称:twisted-gwt,代码行数:17,代码来源:gwttypes.py


示例13: _implements

def _implements(name, interfaces, classImplements):
    # This entire approach is invalid under Py3K.  Don't even try to fix
    # the coverage for this block there. :(
    frame = sys._getframe(2)
    locals = frame.f_locals

    # Try to make sure we were called from a class def. In 2.2.0 we can't
    # check for __module__ since it doesn't seem to be added to the locals
    # until later on.
    if locals is frame.f_globals or '__module__' not in locals:
        raise TypeError(name+" can be used only from a class definition.")

    if '__implements_advice_data__' in locals:
        raise TypeError(name+" can be used only once in a class definition.")

    locals['__implements_advice_data__'] = interfaces, classImplements
    addClassAdvisor(_implements_advice, depth=3)
开发者ID:marcosptf,项目名称:fedora,代码行数:17,代码来源:declarations.py


示例14: factory

 def factory(regex):
     _f = {}
     def decorator(f):
         _f[f.__name__] = f
         return f
     def advisor(cls):
         def wrapped(f):
             def __init__(self, *args, **kwargs):
                 f(self, *args, **kwargs)
                 for func_name in _f:
                     orig = _f[func_name]
                     func = getattr(self, func_name)
                 if func.im_func==orig:
                     self.register(method, regex, func)
             return __init__
         cls.__init__ = wrapped(cls.__init__)
         return cls
     addClassAdvisor(advisor)
     return decorator
开发者ID:baloo,项目名称:txrestapi,代码行数:19,代码来源:methods.py


示例15: _implements

def _implements(name, args, kw, classImplements):

    #NOTE: str(classImplements) в данном случае используется просто в качестве уникального идентификатора

    def _implements_advice(cls):
        classImplements(cls, *args, **kw)
        return cls

    frame = sys._getframe(2)
    locals = frame.f_locals
    # Try to make sure we were called from a class def. In 2.2.0 we can't
    # check for __module__ since it doesn't seem to be added to the locals
    # until later on.
    if (locals is frame.f_globals) or (
        ('__module__' not in locals) and sys.version_info[:3] > (2, 2, 0)):
        raise TypeError(name+" can be used only from a class definition.")
    if str(classImplements) in locals:
        raise TypeError(name+" can be used only once in a class definition.")
    locals[str(classImplements)] = args, kw, classImplements
    addClassAdvisor(_implements_advice, depth=3)
开发者ID:pombredanne,项目名称:spamfighter,代码行数:20,代码来源:registrator.py


示例16: view

def view(name, *args, **kwargs):
    """
    This will attach a view to the controller.
    
    This should be used from within a class such as:
    
    >>> class MyController(Controller):
    ...     view('main')
    ...
    >>>
    
    @name: the name of the view such as 'main'
    """
    action = (_view, (name,) + args, kwargs)
    def installAction(cls):
        if not hasattr(cls, '_lift_items'):
            cls._lift_items = []
        cls._lift_items.append(action)
        return cls
    addClassAdvisor(installAction)
开发者ID:chergert,项目名称:lift,代码行数:20,代码来源:controllers.py


示例17: dependsOn

def dependsOn(itemType, itemCustomizer=None, doc='',
              indexed=True, whenDeleted=reference.NULLIFY):
    """
    This function behaves like L{axiom.attributes.reference} but with
    an extra behaviour: when this item is installed (via
    L{axiom.dependency.installOn} on a target item, the
    type named here will be instantiated and installed on the target
    as well.

    For example::

      class Foo(Item):
          counter = integer()
          thingIDependOn = dependsOn(Baz, lambda baz: baz.setup())

    @param itemType: The Item class to instantiate and install.
    @param itemCustomizer: A callable that accepts the item installed
    as a dependency as its first argument. It will be called only if
    an item is created to satisfy this dependency.

    @return: An L{axiom.attributes.reference} instance.
    """

    frame = sys._getframe(1)
    locals = frame.f_locals

    # Try to make sure we were called from a class def.
    if (locals is frame.f_globals) or ('__module__' not in locals):
        raise TypeError("dependsOn can be used only from a class definition.")
    ref = reference(reftype=itemType, doc=doc, indexed=indexed, allowNone=True,
                    whenDeleted=whenDeleted)
    if "__dependsOn_advice_data__" not in locals:
        addClassAdvisor(_dependsOn_advice)
    locals.setdefault('__dependsOn_advice_data__', []).append(
    (itemType, itemCustomizer, ref))
    return ref
开发者ID:perkinslr,项目名称:axiom-py3,代码行数:36,代码来源:dependency.py


示例18: layout

def layout(engine, *args, **kwargs):
    """
    This will attach a layout to the view allowing for auto loading of
    widgets.
    
    This should be used from within a class such as:
    
    >>> class MyView(View):
    ...     layout('glade', filename = 'myview.glade')
    ...
    >>>
    
    @engine: the layout engine to use such as 'glade'
    """
    if engine not in _layout_engines:
        raise AttributeError, 'Engine %s could not be found' % engine
    
    action = (_layout_engines[engine], args, kwargs)
    def installAction(cls):
        if not hasattr(cls, '_lift_items'):
            cls._lift_items = []
        cls._lift_items.append(action)
        return cls
    addClassAdvisor(installAction)
开发者ID:chergert,项目名称:lift,代码行数:24,代码来源:views.py


示例19: secured_by

def secured_by(*securityinfos):
    """
        Declare that object(s) 'securityinfos' provide
        security information for klass being defind during call.
    """
    for securityinfo in securityinfos:
        if not ISecurityInformation.providedBy(securityinfo):
            raise TypeError('Security objects must provide ISecurityInfo.')

    ##
    # Closure formed by inner-function allows delayed assignement
    #   of security information.
    def setup_security_info(klass):
        if not vars(klass).has_key('__secured_by__'):
            klass.__secured_by__ = []
        map(klass.__secured_by__.append, securityinfos)
        return klass
    return _zadvice.addClassAdvisor(setup_security_info)
开发者ID:mcruse,项目名称:monotone,代码行数:18,代码来源:declarations.py


示例20: adapts

def adapts(*interfaces):
    """
        Called within adapter class definitions.  Parameter 'interface'
        may be single Interface type object, or list of interfaces if
        adapter is to be a multi-adapter.  A multi-adapter adapts
        multiple objects, by interface, to some interface.

        Note: inner-function uses closure to bind 'interface', which
        is provided now, and klass which will be provided to inner function
        when called upon completion of current class statement.

        Inner-function must return klass reference as it is being called
        in similar-fashion as meta-class.
    """
    def setup_adapts(klass):
        if not vars(klass).has_key('__used_for__'):
            klass.__used_for__ = []
        map(klass.__used_for__.append, interfaces)
        return klass
    return _zadvice.addClassAdvisor(setup_adapts)
开发者ID:mcruse,项目名称:monotone,代码行数:20,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python declarations.implementedBy函数代码示例发布时间:2022-05-26
下一篇:
Python interface.provided_by函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap