[utils] Added utils.to_yaml action.

This commit is contained in:
Fabio Manganiello 2023-10-18 22:50:52 +02:00
parent c7acc03c8f
commit f0255549c8
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -3,6 +3,8 @@ import threading
import time import time
from typing import Dict, Union from typing import Dict, Union
import yaml
from platypush.backend.http.utils import HttpUtils from platypush.backend.http.utils import HttpUtils
from platypush.config import Config from platypush.config import Config
from platypush.plugins import Plugin, action from platypush.plugins import Plugin, action
@ -363,5 +365,12 @@ class UtilsPlugin(Plugin):
return docutils.core.publish_parts(text, writer_name='html')['html_body'] 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: # vim:sw=4:ts=4:et: