1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[formatter] support putting keys in quotes

i.e. obj["key"] or obj['key']
as in f-strings
This commit is contained in:
Mike Fährmann 2023-03-21 22:06:54 +01:00
parent 46fdf46f21
commit fe41a2b159
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 7 additions and 0 deletions

View File

@ -256,6 +256,8 @@ def parse_field_name(field_name):
try:
if ":" in key:
key = _slice(key)
else:
key = key.strip("\"'")
except TypeError:
pass # key is an integer

View File

@ -128,6 +128,11 @@ class TestFormatter(unittest.TestCase):
self._run_test("{l[0]}" , "a")
self._run_test("{a[6]}" , "w")
def test_dict_access(self):
self._run_test("{d[a]}" , "foo")
self._run_test("{d['a']}", "foo")
self._run_test('{d["a"]}', "foo")
def test_slicing(self):
v = self.kwdict["a"]
self._run_test("{a[1:10]}" , v[1:10])