Пример #1
0
    def __call__(self, component, module, **data):
        """Determine module-level component.

        Look for components in module.

        iface determines the kind of module-level component to look for
        (it will implement iface).

        If there is no module-level component, raise an error.

        If there is one module-level component, it is returned.

        If there are more than one module-level component, raise
        an error.
        """
        components = list(scan_for_classes(module, self.iface))
        if len(components) == 0:
            raise UnknownError(
                "No module-level %s for %r, please use the '%s' "
                "directive." %
                (self.component_name, component, self.directive_name),
                component)
        elif len(components) == 1:
            return components[0]
        else:
            raise UnknownError(
                "Multiple possible %ss for %r, please use the '%s' "
                "directive." %
                (self.component_name, component, self.directive_name),
                component)
Пример #2
0
    def __call__(self, component, module, **data):
        """Determine module-level component.

        Look for components in module.

        iface determines the kind of module-level component to look for
        (it will implement iface).

        If there is no module-level component, raise an error.

        If there is one module-level component, it is returned.

        If there are more than one module-level component, raise
        an error.
        """
        components = list(scan_for_classes(module, self.iface))
        if len(components) == 0:
            raise UnknownError(
                "No module-level %s for %r, please use the '%s' "
                "directive."
                % (self.component_name, component, self.directive_name),
                component)
        elif len(components) == 1:
            return components[0]
        else:
            raise UnknownError(
                "Multiple possible %ss for %r, please use the '%s' "
                "directive."
                % (self.component_name, component, self.directive_name),
                component)
Пример #3
0
def determine_module_component(module_info, directive, iface):
    """Determine module-level component.

    The module-level component can be set explicitly using the
    annotation (such as grok.context).

    If there is no annotation, the module-level component is determined
    by scanning for classes that implement an interface.
    
    If there is no module-level component, the module-level component is
    None.

    If there is one module-level component, it is returned.

    If there are more than one module-level component, AMBIGUOUS_COMPONENT
    is returned.
    """
    module = module_info.getModule()
    components = list(scan_for_classes(module, iface))
    if len(components) == 0:
        component = None
    elif len(components) == 1:
        component = components[0]
    else:
        component= AMBIGUOUS_COMPONENT

    module_component = directive.bind().get(module=module)
    if module_component is not None:
        component = module_component
    return component
Пример #4
0
 def get_default(cls, component, module=None, **data):
     components = list(scan_for_classes(module, IContext))
     if len(components) == 0:
         raise GrokError(
             "No module-level context for %r, please use the 'context' "
             "directive." % (component), component)
     elif len(components) == 1:
         component = components[0]
     else:
         raise GrokError(
             "Multiple possible contexts for %r, please use the 'context' "
             "directive." % (component), component)
     return component
Пример #5
0
 def get_default(cls, component, module=None, **data):
     components = list(scan_for_classes(module, IViewletManager))
     if len(components) == 0:
         raise GrokError(
             "No module-level viewletmanager for %r, please use the "
             "'viewletmanager' directive." % (component), component)
     elif len(components) == 1:
         component = components[0]
     else:
         raise GrokError(
             "Multiple possible viewletmanagers for %r, please use the "
             "'viewletmanager' directive." % (component), component)
     return component
Пример #6
0
 def get_default(cls, component, module=None, **data):
     components = list(scan_for_classes(module, IMenu))
     if len(components) == 0:
         raise GrokError(
             "No module-level menu for %r, please use the "
             "'menu' directive." % (component), component)
     elif len(components) == 1:
         component = components[0]
     else:
         raise GrokError(
             "Multiple possible menus for %r, please use the "
             "'menu' directive." % (component), component)
     return component
Пример #7
0
 def get_default(cls, component, module=None, **data):
     components = list(scan_for_classes(module, IContext))
     if len(components) == 0:
         raise GrokError(
             "No module-level model for %r, please use the 'scaffold' " "directive." % (component), component
         )
     elif len(components) == 1:
         component = components[0]
     else:
         raise GrokError(
             "Multiple possible models for %r, please use the 'scaffold' " "directive." % (component), component
         )
     return dict.fromkeys(SCAFFOLD_ACTIONS, component)
Пример #8
0
 def get_default(cls, component, module=None, **data):
     components = list(scan_for_classes(module, IContext))
     if len(components) == 0:
         raise GrokError(
             "No module-level context for %r, please use the 'context' "
             "directive." % (component), component)
     elif len(components) == 1:
         component = components[0]
     else:
         raise GrokError(
             "Multiple possible contexts for %r, please use the 'context' "
             "directive."
             % (component), component)
     return component
Пример #9
0
 def get_default(cls, component, module=None, **data):
     components = list(scan_for_classes(module, IViewletManager))
     if len(components) == 0:
         raise GrokError(
             "No module-level viewletmanager for %r, please use the "
             "'viewletmanager' directive." % (component), component)
     elif len(components) == 1:
         component = components[0]
     else:
         raise GrokError(
             "Multiple possible viewletmanagers for %r, please use the "
             "'viewletmanager' directive."
             % (component), component)
     return component