From 5eae0334de4494b63207e8e1ad784f8a4c1c7d4d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 17:25:57 +0200 Subject: [PATCH] fs.read_file_object --- rwx/fs/__init__.py | 14 ++++++++++++++ rwx/sw/freetube/db.py | 1 + 2 files changed, 15 insertions(+) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 6abcce7..184c198 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -2,6 +2,7 @@ import os import shutil +import tomllib from pathlib import Path from rwx import ps @@ -106,6 +107,19 @@ def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: return read_file_text(file_path, charset).split(os.linesep) +def read_file_object(file_path: Path, charset: str = CHARSET) -> object: + """Read whole file as toml object. + + :param file_path: source input file + :type file_path: Path + :param charset: charset to use for decoding input + :type charset: str + :rtype: object + """ + text = read_file_text(file_path, charset) + return tomllib.loads(text) + + def read_file_text(file_path: Path, charset: str = CHARSET) -> str: """Read whole file text. diff --git a/rwx/sw/freetube/db.py b/rwx/sw/freetube/db.py index 9e37162..e3eb31e 100644 --- a/rwx/sw/freetube/db.py +++ b/rwx/sw/freetube/db.py @@ -1,5 +1,6 @@ """Output FreeTube db.""" + def to_db(value: object) -> str: """Render value as string.