mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 04:02:32 +01:00
add 'noop()' and 'identity()' functions
This commit is contained in:
parent
755164b36a
commit
c5ca7905ce
@ -10,7 +10,7 @@
|
||||
|
||||
from .booru import BooruExtractor
|
||||
from .common import Message
|
||||
from .. import text, exception
|
||||
from .. import text, util, exception
|
||||
from ..cache import cache
|
||||
import collections
|
||||
|
||||
@ -206,7 +206,7 @@ class SankakuAPI():
|
||||
|
||||
self.username, self.password = self.extractor._get_auth_info()
|
||||
if not self.username:
|
||||
self.authenticate = lambda: None
|
||||
self.authenticate = util.noop
|
||||
|
||||
def pools(self, pool_id):
|
||||
params = {"lang": "en"}
|
||||
|
@ -638,7 +638,7 @@ class DataJob(Job):
|
||||
self.ascii = config.get(("output",), "ascii", ensure_ascii)
|
||||
|
||||
private = config.get(("output",), "private")
|
||||
self.filter = (lambda x: x) if private else util.filter_dict
|
||||
self.filter = util.identity if private else util.filter_dict
|
||||
|
||||
def run(self):
|
||||
sleep = self.extractor.config("sleep-extractor")
|
||||
|
@ -81,6 +81,15 @@ def raises(cls):
|
||||
return wrap
|
||||
|
||||
|
||||
def identity(x):
|
||||
"""Returns its argument"""
|
||||
return x
|
||||
|
||||
|
||||
def noop():
|
||||
"""Does nothing"""
|
||||
|
||||
|
||||
def generate_token(size=16):
|
||||
"""Generate a random token with hexadecimal digits"""
|
||||
data = random.getrandbits(size * 8).to_bytes(size, "big")
|
||||
@ -804,7 +813,7 @@ class PathFormat():
|
||||
@staticmethod
|
||||
def _build_cleanfunc(chars, repl):
|
||||
if not chars:
|
||||
return lambda x: x
|
||||
return identity
|
||||
elif isinstance(chars, dict):
|
||||
def func(x, table=str.maketrans(chars)):
|
||||
return x.translate(table)
|
||||
|
@ -484,6 +484,13 @@ class TestOther(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
func(3)
|
||||
|
||||
def test_identity(self):
|
||||
for value in (123, "foo", [1, 2, 3], (1, 2, 3), {1: 2}, None):
|
||||
self.assertIs(util.identity(value), value)
|
||||
|
||||
def test_noop(self):
|
||||
self.assertEqual(util.noop(), None)
|
||||
|
||||
def test_generate_token(self):
|
||||
tokens = set()
|
||||
for _ in range(100):
|
||||
|
Loading…
Reference in New Issue
Block a user