weaver.transform.handlers ========================= .. py:module:: weaver.transform.handlers Module Contents --------------- .. py:data:: LOGGER .. py:data:: HTML_CONTENT :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """

%CONTENT%

""" .. raw:: html
.. py:function:: exception_handler(func) Decorator to handle exceptions in functions and log them. :param func: Function to wrap with exception handling. :return: The wrapped function. .. py:function:: image_to_any(image: str, out: str) -> None Converts image files to a specified output format. If no conversion is needed, it copies the file. :param image: Input image file path. :param out: Output file path. .. py:function:: images_to_any(images: List[PIL.Image.Image], out: str) -> None Processes a list of images and converts them to the desired format, saving them in the specified output path. :param images: List of Image objects to process. :param out: Output file path. .. py:function:: any_to_html(i: str, out: str) -> None Converts any content type (text or image) to HTML format. :param i: Input file path. :param out: Output file path. .. py:function:: any_to_pdf(i: str, out: str) -> None Converts a file to PDF format. If the file is an image, it is embedded in the PDF, otherwise, it is treated as text. :param i: Input file path. :param out: Output PDF file path. .. py:function:: csv_to_json(i: str, out: str) -> None Converts a CSV file to a JSON file with a 'datas' key containing the rows. :param i: Path to the input CSV file. :param out: Path to the output JSON file. .. py:function:: csv_to_xml(i: str, out: str) -> None Converts a CSV file to an XML file by first converting it to JSON. :param i: Path to the input CSV file. :param out: Path to the output XML file. .. py:function:: json_to_xml(i: str, out: str) -> None Converts a JSON file to an XML file. :param i: Path to the input JSON file. :param out: Path to the output XML file. .. py:function:: json_to_txt(i: str, out: str) -> None Converts a JSON file to a text file. :param i: Path to the input JSON file. :param out: Path to the output text file. .. py:function:: json_to_yaml(i: str, out: str) -> None Converts a JSON file to a YAML file. :param i: Path to the input JSON file. :param out: Path to the output YAML file. .. py:function:: yaml_to_json(i: str, out: str) -> None Converts a YAML file to a JSON file. :param i: Path to the input YAML file. :param out: Path to the output JSON file. .. py:function:: json_to_csv(i: str, out: str) -> None Converts a JSON file to a CSV file. :param i: Path to the input JSON file. :param out: Path to the output CSV file. .. py:function:: xml_to_json(i: str, out: str) -> None Converts an XML file to a JSON file. :param i: Path to the input XML file. :param out: Path to the output JSON file. .. py:function:: html_to_txt(i: str, out: str) -> None Converts an HTML file to a text file. :param i: Path to the input HTML file. :param out: Path to the output text file. .. py:function:: yaml_to_csv(i: str, out: str) -> None Converts a YAML file to a CSV file by first converting it to JSON. :param i: Path to the input YAML file. :param out: Path to the output CSV file. .. py:function:: yaml_to_xml(i: str, out: str) -> None Converts a YAML file to an XML file. :param i: Path to the input YAML file. :param out: Path to the output XML file. .. py:function:: xml_to_yaml(i: str, out: str) -> None Converts an XML file to a YAML file. :param i: Path to the input XML file. :param out: Path to the output YAML file. .. py:function:: csv_to_yaml(i: str, out: str) -> None Converts a CSV file to a YAML file by first converting it to JSON. :param i: Path to the input CSV file. :param out: Path to the output YAML file. .. py:class:: Transform(file_path: str, current_media_type: str, wanted_media_type: str) Class for handling the transformation of files between different media types (e.g., text, image, application). :param file_path: The path to the input file to be transformed. :param current_media_type: The media type of the input file. :param wanted_media_type: The desired media type after transformation. Attributes: file_path (str): The path to the input file to be transformed. current_media_type (str): The media type of the input file. wanted_media_type (str): The desired media type after transformation. output_path (str): The path where the transformed file will be saved. ext (str): The extension of the output file based on the wanted media type. Methods: process(): Initiates the file transformation process based on the input and output media types. get(): Returns a `FileResponse` with the transformed file for download. Initializes the Transform object with file paths and media types. :param file_path: Path to the file to be transformed. :param current_media_type: The media type of the input file. :param wanted_media_type: The desired media type for the output file. .. py:attribute:: file_path .. py:attribute:: cmt .. py:attribute:: wmt .. py:attribute:: output_path .. py:attribute:: ext :value: None .. py:method:: process() -> None Processes the file based on the current and wanted media types and performs the transformation. :raises RuntimeError: If an error occurs during the file transformation process. .. py:method:: process_text() -> None Handles the transformation of text-based files (e.g., plain text, HTML, CSV). :raises RuntimeError: If a conversion type is unsupported. .. py:method:: process_csv() -> None Handles the conversion of CSV files to other formats like JSON, XML, and YAML. :raises RuntimeError: If a conversion type is unsupported. .. py:method:: process_application() -> None Handles the conversion of application files (e.g., JSON, XML, YAML). :raises RuntimeError: If a conversion type is unsupported. .. py:method:: process_json() -> None Handles the transformation of JSON files to other formats like CSV, XML, YAML, and plain text. :raises RuntimeError: If a conversion type is unsupported. .. py:method:: process_yaml() -> None Handles the conversion of YAML files to other formats like CSV, JSON, and XML. :raises RuntimeError: If a conversion type is unsupported. .. py:method:: process_xml() -> None Handles the conversion of XML files to JSON or YAML. :raises RuntimeError: If a conversion type is unsupported. .. py:method:: process_image() -> None Handles the conversion of image files to other formats (e.g., image to image or image to PDF). :raises RuntimeError: If a conversion type is unsupported. .. py:method:: get() -> pyramid.response.FileResponse Returns the transformed file as a response for download. :returns: The response containing the transformed file. :raises HTTPUnprocessableEntity: If an error occurs during file transformation.