def read_ftl_resource()

in fluent/migrate/_context.py [0:0]


    def read_ftl_resource(self, path: str):
        """Read an FTL resource and parse it into an AST."""
        f = codecs.open(path, "r", "utf8")
        try:
            contents = f.read()
        except UnicodeDecodeError as err:
            logger = logging.getLogger("migrate")
            logger.warning(f"Unable to read file {path}: {err}")
            raise err
        finally:
            f.close()

        ast = self.fluent_parser.parse(contents)

        annots = [
            annot
            for entry in ast.body
            if isinstance(entry, FTL.Junk)
            for annot in entry.annotations
        ]

        if len(annots):
            logger = logging.getLogger("migrate")
            for annot in annots:
                msg = annot.message
                logger.warning(f"Syntax error in {path}: {msg}")

        return ast