Example #1
0
    def grok(self, name, class_, module_info=None, **kw):
        module = None
        if module_info is not None:
            module = module_info.getModule()

        # Populate the data dict with information from class or module
        directives = directive.bind().get(self.__class__)
        for d in directives:
            kw[d.name] = d.get(class_, module, **kw)

        # Ignore methods that are present on the component baseclass.
        basemethods = set(util.public_methods_from_class(
            component.bind().get(self.__class__)))
        methods = set(util.public_methods_from_class(class_)) - basemethods
        if not methods:
            raise GrokError("%r does not define any public methods. "
                            "Please add methods to this class to enable "
                            "its registration." % class_, class_)

        results = []
        for method in methods:
            # Directives may also be applied to methods, so let's
            # check each directive and potentially override the
            # class-level value with a value from the method *locally*.
            data = kw.copy()
            for bound_dir in directives:
                d = bound_dir.directive
                class_value = data[bound_dir.name]
                data[bound_dir.name] = d.store.get(d, method,
                                                   default=class_value)
            results.append(self.execute(class_, method, **data))

        return max(results)
Example #2
0
 def register(self, grokker):
     key = component.bind().get(grokker)
     grokkers = self._grokkers.setdefault(key, [])
     for g in grokkers:
         if g.__class__ is grokker.__class__:
             return
     grokkers.append(grokker)
Example #3
0
    def grok(self, name, class_, module_info=None, **kw):
        module = None
        if module_info is not None:
            module = module_info.getModule()

        # Populate the data dict with information from class or module
        directives = directive.bind().get(self.__class__)
        for d in directives:
            kw[d.name] = d.get(class_, module, **kw)

        # Ignore methods that are present on the component baseclass.
        basemethods = set(util.public_methods_from_class(
            component.bind().get(self.__class__)))
        methods = set(util.public_methods_from_class(class_)) - basemethods
        if not methods:
            raise GrokError("%r does not define any public methods. "
                            "Please add methods to this class to enable "
                            "its registration." % class_, class_)

        results = []
        for method in methods:
            # Directives may also be applied to methods, so let's
            # check each directive and potentially override the
            # class-level value with a value from the method *locally*.
            data = kw.copy()
            for bound_dir in directives:
                d = bound_dir.directive
                class_value = data[bound_dir.name]
                data[bound_dir.name] = d.store.get(d, method,
                                                   default=class_value)
            results.append(self.execute(class_, method, **data))

        return max(results)
Example #4
0
 def register(self, grokker):
     key = component.bind().get(grokker)
     grokkers = self._grokkers.setdefault(key, [])
     for g in grokkers:
         if g.__class__ is grokker.__class__:
             return
     grokkers.append(grokker)