Exemplo n.º 1
0
    def add(self, spec, content, path=None, do_filter=True):
        if not path:  # path must change to allow parsers to fire
            path = self._make_path()
        if not path.startswith("/"):
            path = "/" + path

        if dr.get_delegate(spec).raw:
            content_iter = content
        else:
            if not isinstance(content, list):
                content_iter = [
                    l.rstrip() for l in StringIO(content).readlines()
                ]
            else:
                content_iter = content

            if do_filter:
                content_iter = list(apply_filters(spec, content_iter))

        content_provider = context_wrap(content_iter, path=path, split=False)
        if dr.get_delegate(spec).multi_output:
            if spec not in self.data:
                self.data[spec] = []
            self.data[spec].append(content_provider)
        else:
            self.data[spec] = content_provider

        return self
Exemplo n.º 2
0
    def add(self, spec, content, path=None, do_filter=True):
        if not path:  # path must change to allow parsers to fire
            path = str(next_gn()) + "BOGUS"
        if not path.startswith("/"):
            path = "/" + path

        if dr.get_delegate(spec).raw:
            content_iter = content
        else:
            if not isinstance(content, list):
                content_iter = [
                    l.rstrip() for l in StringIO(content).readlines()
                ]
            else:
                content_iter = content

            if do_filter:
                content_iter = list(apply_filters(spec, content_iter))

        content_provider = ContentProvider()
        content_provider.path = path
        content_provider._content = content_iter

        if dr.get_delegate(spec).multi_output:
            if spec not in self.data:
                self.data[spec] = []
            self.data[spec].append(content_provider)
        else:
            logger.warn("Replacing %s", spec.__name__)
            logger.warn(traceback.format_stack())
            self.data[spec] = content_provider

        return self