diff options
| author | 2022-04-09 00:15:19 -0400 | |
|---|---|---|
| committer | 2022-04-09 00:15:19 -0400 | |
| commit | 2fe1dfed848fc26b7419e3bfe91a62e686960429 (patch) | |
| tree | 901cb64e2a1748df2bb8c7abc60ff6d72ae4bc27 /gallery_dl/formatter.py | |
| parent | c2e774d3f5a4499b8beb5a12ab46a0099b16b1e7 (diff) | |
New upstream version 1.21.1.upstream/1.21.1
Diffstat (limited to 'gallery_dl/formatter.py')
| -rw-r--r-- | gallery_dl/formatter.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/gallery_dl/formatter.py b/gallery_dl/formatter.py index c2b4d99..27d5e40 100644 --- a/gallery_dl/formatter.py +++ b/gallery_dl/formatter.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Mike Fährmann +# Copyright 2021-2022 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -43,6 +43,8 @@ def parse(format_string, default=None): cls = ExpressionFormatter elif kind == "M": cls = ModuleFormatter + elif kind == "F": + cls = FStringFormatter formatter = _CACHE[key] = cls(format_string, default) return formatter @@ -206,6 +208,13 @@ class ModuleFormatter(): self.format_map = getattr(module, function_name) +class FStringFormatter(): + """Generate text by evaluaring an f-string literal""" + + def __init__(self, fstring, default=None): + self.format_map = util.compile_expression("f'''" + fstring + "'''") + + def parse_field_name(field_name): first, rest = _string.formatter_field_name_split(field_name) funcs = [] @@ -245,7 +254,7 @@ def parse_format_spec(format_spec, conversion): "C": string.capwords, "j": json.dumps, "t": str.strip, - "T": util.to_timestamp, + "T": util.datetime_to_timestamp_string, "d": text.parse_timestamp, "U": text.unescape, "S": util.to_string, |
