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

replace ChainPredicate class with 'functools.partial'

This commit is contained in:
Mike Fährmann 2021-07-19 02:43:23 +02:00
parent 1b2f9050fb
commit 9e42cd58ea
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 9 additions and 15 deletions

View File

@ -403,8 +403,14 @@ def build_predicate(predicates):
return lambda url, kwdict: True
elif len(predicates) == 1:
return predicates[0]
else:
return ChainPredicate(predicates)
return functools.partial(chain_predicates, predicates)
def chain_predicates(predicates, url, kwdict):
for pred in predicates:
if not pred(url, kwdict):
return False
return True
class RangePredicate():
@ -508,18 +514,6 @@ class FilterPredicate():
raise exception.FilterError(exc)
class ChainPredicate():
"""Predicate; True if all of its predicates return True"""
def __init__(self, predicates):
self.predicates = predicates
def __call__(self, url, kwdict):
for pred in self.predicates:
if not pred(url, kwdict):
return False
return True
class ExtendedUrl():
"""URL with attached config key-value pairs"""
def __init__(self, url, gconf, lconf):

View File

@ -124,7 +124,7 @@ class TestPredicate(unittest.TestCase):
pred = util.build_predicate([util.UniquePredicate(),
util.UniquePredicate()])
self.assertIsInstance(pred, util.ChainPredicate)
self.assertIs(pred.func, util.chain_predicates)
class TestISO639_1(unittest.TestCase):