mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 04:02:32 +01:00
[formatter] allow dots etc in '…' literals (#5539)
don't parse fields starting with ' this disables the ability to directly apply […] to '…' literals, but that's not really useful anyway and can still be done with _lit
This commit is contained in:
parent
619bf5c644
commit
d0cead105b
@ -243,13 +243,12 @@ class TemplateFStringFormatter(FStringFormatter):
|
||||
|
||||
|
||||
def parse_field_name(field_name):
|
||||
if field_name[0] == "'":
|
||||
return "_lit", (operator.itemgetter(field_name[1:-1]),)
|
||||
|
||||
first, rest = _string.formatter_field_name_split(field_name)
|
||||
funcs = []
|
||||
|
||||
if first[0] == "'":
|
||||
funcs.append(operator.itemgetter(first[1:-1]))
|
||||
first = "_lit"
|
||||
|
||||
for is_attr, key in rest:
|
||||
if is_attr:
|
||||
func = operator.attrgetter
|
||||
|
@ -336,14 +336,14 @@ class TestFormatter(unittest.TestCase):
|
||||
def test_literals(self):
|
||||
value = "foo"
|
||||
|
||||
self._run_test("{'foo'}" , value)
|
||||
self._run_test("{'foo'!u}" , value.upper())
|
||||
self._run_test("{'f00':R0/o/}" , value)
|
||||
self._run_test("{'foobar'[:3]}", value)
|
||||
self._run_test("{z|'foo'}" , value)
|
||||
self._run_test("{z|''|'foo'}" , value)
|
||||
self._run_test("{z|''}" , "")
|
||||
self._run_test("{''|''}" , "")
|
||||
self._run_test("{'foo'}" , value)
|
||||
self._run_test("{'foo'!u}" , value.upper())
|
||||
self._run_test("{'f00':R0/o/}", value)
|
||||
|
||||
self._run_test("{z|'foo'}" , value)
|
||||
self._run_test("{z|''|'foo'}" , value)
|
||||
self._run_test("{z|'foo'!u}" , value.upper())
|
||||
self._run_test("{z|'f00':R0/o/}", value)
|
||||
|
||||
self._run_test("{_lit[foo]}" , value)
|
||||
self._run_test("{_lit[foo]!u}" , value.upper())
|
||||
@ -351,6 +351,17 @@ class TestFormatter(unittest.TestCase):
|
||||
self._run_test("{_lit[foobar][:3]}", value)
|
||||
self._run_test("{z|_lit[foo]}" , value)
|
||||
|
||||
# empty (#4492)
|
||||
self._run_test("{z|''}" , "")
|
||||
self._run_test("{''|''}", "")
|
||||
|
||||
# special characters (dots, brackets, singlee quotes) (#5539)
|
||||
self._run_test("{'f.o.o'}" , "f.o.o")
|
||||
self._run_test("{_lit[f.o.o]}", "f.o.o")
|
||||
self._run_test("{_lit[f'o'o]}", "f'o'o")
|
||||
self._run_test("{'f.[].[]'}" , "f.[].[]")
|
||||
self._run_test("{z|'f.[].[]'}", "f.[].[]")
|
||||
|
||||
def test_template(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
path1 = os.path.join(tmpdirname, "tpl1")
|
||||
|
Loading…
Reference in New Issue
Block a user