From 42525cfe8da69d277eb83a5006454ee4239ac599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 7 Jun 2022 17:47:07 +0200 Subject: [PATCH] =?UTF-8?q?fix=20'{=E2=80=A6!j}'=20for=20otherwise=20non-s?= =?UTF-8?q?erializable=20types=20(##2624)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit like 'datetime' --- gallery_dl/formatter.py | 3 ++- test/test_formatter.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gallery_dl/formatter.py b/gallery_dl/formatter.py index d1b3a8a7..f2c2d331 100644 --- a/gallery_dl/formatter.py +++ b/gallery_dl/formatter.py @@ -14,6 +14,7 @@ import string import _string import datetime import operator +import functools from . import text, util _CACHE = {} @@ -257,7 +258,7 @@ def parse_format_spec(format_spec, conversion): "u": str.upper, "c": str.capitalize, "C": string.capwords, - "j": json.dumps, + "j": functools.partial(json.dumps, default=str), "t": str.strip, "T": util.datetime_to_timestamp_string, "d": text.parse_timestamp, diff --git a/test/test_formatter.py b/test/test_formatter.py index efb69636..dc818b00 100644 --- a/test/test_formatter.py +++ b/test/test_formatter.py @@ -56,6 +56,7 @@ class TestFormatter(unittest.TestCase): self._run_test("{t!d:%Y-%m-%d}", "2010-01-01") self._run_test("{dt!T}", "1262304000") self._run_test("{l!j}", '["a", "b", "c"]') + self._run_test("{dt!j}", '"2010-01-01 00:00:00"') with self.assertRaises(KeyError): self._run_test("{a!q}", "hello world")