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:
parent
1b2f9050fb
commit
9e42cd58ea
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user