Ejemplo n.º 1
0
    def check_element(self, e):
        """
        Applies the element_constraint to the given element and returns the
        result.
        """
        my_view = {}
        if self.content_mimetype is not None:
            my_view["mimetype"] = self.content_mimetype
        if self.content_model is not None:
            my_view["model"] = self.content_model

        if self.element_constraint is not None:
            ret = self.element_constraint.apply_to(e)
        else:
            ret = True
        return ret & apply_to(my_view, e)
Ejemplo n.º 2
0
    def check_all(self, package=None, _true=lambda *a: True):
        """
        Applies the element_constraint to all the elements in the given
        package (session.package) if None, and return the aggregated result.
        """
        if self.element_constraint:
            check1 = self.element_constraint.apply_to
        else:
            check1 = _true

        my_view = {}
        if self.content_mimetype is not None:
            my_view["mimetype"] = self.content_mimetype
        if self.content_model is not None:
            my_view["model"] = self.content_model
        if my_view:
            check2 = lambda e: apply_to(my_view, e)
        else:
            check2 = _true

        r = True
        for e in self.iter_elements(package):
            r = r & check1(e) & check2(e)
        return r