Beispiel #1
0
    def add_transforms(self, path, transforms):
        """Define transforms for path.

        Each transform is an extended FTL node with `Transform` nodes as some
        values.  Transforms are stored in their lazy AST form until
        `merge_changeset` is called, at which point they are evaluated to real
        FTL nodes with migrated translations.

        Each transform is scanned for `SOURCE` nodes which will be used to
        build the list of dependencies for the transformed message.
        """
        def get_sources(acc, cur):
            if isinstance(cur, SOURCE):
                acc.add((cur.path, cur.key))
            return acc

        for node in transforms:
            # Scan `node` for `SOURCE` nodes and collect the information they
            # store into a set of dependencies.
            dependencies = fold(get_sources, node, set())
            # Set these sources as dependencies for the current transform.
            self.dependencies[(path, node.id.name)] = dependencies

        path_transforms = self.transforms.setdefault(path, [])
        path_transforms += transforms
Beispiel #2
0
    def test_copy_value(self):
        node = FTL.Entity(
            id=FTL.Identifier('key'),
            value=LITERAL_FROM('path', 'key')
        )

        self.assertEqual(
            fold(get_source, node, ()),
            (('path', 'key'),)
        )
Beispiel #3
0
    def test_copy_concat(self):
        node = FTL.Entity(
            FTL.Identifier('hello'),
            value=CONCAT(
                LITERAL_FROM('path1', 'key1'),
                LITERAL_FROM('path2', 'key2')
            )
        )

        self.assertEqual(
            fold(get_source, node, ()),
            (('path1', 'key1'), ('path2', 'key2'))
        )
Beispiel #4
0
    def test_copy_traits(self):
        node = FTL.Entity(
            id=FTL.Identifier('key'),
            traits=[
                FTL.Member(
                    FTL.Keyword('trait1'),
                    value=LITERAL_FROM('path1', 'key1')
                ),
                FTL.Member(
                    FTL.Keyword('trait2'),
                    value=LITERAL_FROM('path2', 'key2')
                )
            ]
        )

        self.assertEqual(
            fold(get_source, node, ()),
            (('path1', 'key1'), ('path2', 'key2'))
        )
Beispiel #5
0
    def test_pattern(self):
        node = FTL.Entity(
            id=FTL.Identifier('key'),
            value=FTL.Pattern(
                source=None,
                elements=[
                    FTL.TextElement('Value')
                ]
            )
        )

        def get_value(acc, cur):
            if isinstance(cur, FTL.TextElement):
                return acc + (cur.value,)
            return acc

        self.assertEqual(
            fold(get_value, node, ()),
            ('Value',)
        )