[postprocessor:metadata] filter private entries

i.e. keys starting with an underscore
This commit is contained in:
Mike Fährmann
2019-11-21 16:57:39 +01:00
parent ea094692c8
commit 3fc1e12949
6 changed files with 34 additions and 12 deletions

View File

@@ -151,6 +151,9 @@ class MetadataTest(BasePostprocessorTest):
"ascii" : True,
"indent" : 2,
"extension": "JSON",
}, {
"public" : "hello",
"_private" : "world",
})
self.assertEqual(pp.write , pp._write_json)
@@ -167,7 +170,8 @@ class MetadataTest(BasePostprocessorTest):
self.assertEqual(self._output(m), """{
"category": "test",
"extension": "ext",
"filename": "file"
"filename": "file",
"public": "hello"
}
""")

View File

@@ -207,7 +207,7 @@ class ResultJob(job.DownloadJob):
def _update_kwdict(self, kwdict, to_list=True):
if to_list:
self.kwdict_list.append(kwdict.copy())
kwdict = self._filter(kwdict)
kwdict = util.filter_dict(kwdict)
self.kwdict_hash.update(
json.dumps(kwdict, sort_keys=True, default=str).encode())

View File

@@ -358,6 +358,21 @@ class TestOther(unittest.TestCase):
self.assertEqual(
d, {1: 123, 2: 123, 3: 0, 4: {11: 321, 12: 321, 13: 0}})
def test_filter_dict(self):
d = {}
r = util.filter_dict(d)
self.assertEqual(r, d)
self.assertIsNot(r, d)
d = {"foo": 123, "bar": [], "baz": None}
r = util.filter_dict(d)
self.assertEqual(r, d)
self.assertIsNot(r, d)
d = {"foo": 123, "_bar": [], "__baz__": None}
r = util.filter_dict(d)
self.assertEqual(r, {"foo": 123})
def test_number_to_string(self, f=util.number_to_string):
self.assertEqual(f(1) , "1")
self.assertEqual(f(1.0) , "1.0")