From f0255549c88e3578815c2f8e68aa27ea84490858 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 18 Oct 2023 22:50:52 +0200 Subject: [PATCH] [`utils`] Added `utils.to_yaml` action. --- platypush/plugins/utils/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platypush/plugins/utils/__init__.py b/platypush/plugins/utils/__init__.py index 989f3e2b7..d969904b6 100644 --- a/platypush/plugins/utils/__init__.py +++ b/platypush/plugins/utils/__init__.py @@ -3,6 +3,8 @@ import threading import time from typing import Dict, Union +import yaml + from platypush.backend.http.utils import HttpUtils from platypush.config import Config from platypush.plugins import Plugin, action @@ -363,5 +365,12 @@ class UtilsPlugin(Plugin): return docutils.core.publish_parts(text, writer_name='html')['html_body'] + @action + def to_yaml(self, obj: Union[dict, list, tuple, str, int, float, bool]): + """ + Convert an object to YAML + """ + return yaml.dump(obj, indent=2) + # vim:sw=4:ts=4:et: