<filename>extensions/yaml_support/yaml_support/loader/python_file_loader.py<gh_stars>100-1000
#!/usr/bin/env python3
# Copyright 2004-present Facebook. All Rights Reserved.

from .base_loader import BaseLoader
from .errors.errors import PythonFileLoaderError
import os


class PythonFileLoader(BaseLoader):
    """
    Represents a python (.py) file loader
    """
    @staticmethod
    def load_from_file(path: str) -> str:
        """
        Returns the content of a python (.py) file as a string

        Args:
            path: The path of the python (.py) file to be load
        """
        if not os.path.exists(path):
            raise PythonFileLoaderError(f"{path} file not found")

        if (not os.path.isfile(path)) or (not path.endswith('.py')):
            raise PythonFileLoaderError(f"{path} should be a .py file")

        with open(path, mode='r', encoding='utf8') as file:
            content = file.read()
            assert isinstance(content, str)
            return content

<filename>extensions/yaml_support/yaml_support/loader/python_file_loader.py<gh_stars>100-1000
#!/usr/bin/env python3
# Copyright 2004-present Facebook. All Rights Reserved.

from .base_loader import BaseLoader
from .errors.errors import PythonFileLoaderError
import os


class PythonFileLoader(BaseLoader):
    """
    Represents a python (.py) file loader
    """
    @staticmethod
    def load_from_file(path: str) -> str:
        """
        Returns the content of a python (.py) file as a string

        Args:
            path: The path of the python (.py) file to be load
        """
        if not os.path.exists(path):
            raise PythonFileLoaderError(f"{path} file not found")

        if (not os.path.isfile(path)) or (not path.endswith('.py')):
            raise PythonFileLoaderError(f"{path} should be a .py file")

        with open(path, mode='r', encoding='utf8') as file:
            content = file.read()
            assert isinstance(content, str)
            return content

#!/usr/bin/env python3 # Copyright 2004-present Facebook. All Rights Reserved. Represents a python (.py) file loader Returns the content of a python (.py) file as a string          Args:             path: The path of the python (.py) file to be load