mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
[formatter] support putting keys in quotes
i.e. obj["key"] or obj['key'] as in f-strings
This commit is contained in:
parent
46fdf46f21
commit
fe41a2b159
@ -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
|
||||
|
||||
|
@ -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])
|
||||
|
Loading…
Reference in New Issue
Block a user