Refactored to use lambda expressions
This commit is contained in:
parent
408d766d6d
commit
42ee67a107
@ -21,9 +21,6 @@
|
||||
# yandereBot, or manipulate hash files in some way. Typically instantiating a yandereBot object is unnecessary for this.
|
||||
|
||||
import os
|
||||
import datetime
|
||||
import shutil
|
||||
import contextlib
|
||||
|
||||
|
||||
# Requires properly formatted MD5 checksum lines.
|
||||
@ -75,33 +72,34 @@ class HashObject:
|
||||
# Checking for the binary character when comparing hash string is usually overkill since the CoreUtils package reads
|
||||
# files in binary mode regardless of whether the -b switch is passed.
|
||||
# It is included here since it may be useful for some other applications besides the bot.
|
||||
def is_matching_atter_binary(v_list, v_hash, v_atter):
|
||||
atter_bin = "get_binary_char"
|
||||
def is_matching_atter_binary(v_list, v_hash, callback):
|
||||
return next(
|
||||
(x for x in v_list if
|
||||
getattr(v_hash, v_atter)() == getattr(x, v_atter)() and
|
||||
getattr(v_hash, atter_bin)() == getattr(x, atter_bin)()
|
||||
callback(v_hash) == callback(x) and
|
||||
v_hash.get_binary_char() == x.get_binary_char()
|
||||
), None)
|
||||
|
||||
|
||||
def is_matching_atter(v_list, v_hash, v_atter):
|
||||
return next((x for x in v_list if getattr(v_hash, v_atter)() == getattr(x, v_atter)()), None)
|
||||
def is_matching_atter(v_list, v_hash, callback):
|
||||
return next(
|
||||
(x for x in v_list if
|
||||
callback(v_hash) == callback(x)
|
||||
), None)
|
||||
|
||||
|
||||
def get_matching(v_list, v_hash, atter, match_bin=False):
|
||||
return is_matching_atter(v_list, v_hash, atter) if not match_bin else is_matching_atter_binary(v_list, v_hash, atter)
|
||||
def get_matching(v_list, v_hash, callback, match_bin=False):
|
||||
return is_matching_atter(v_list, v_hash, callback) if not match_bin else is_matching_atter_binary(v_list, v_hash, callback)
|
||||
|
||||
|
||||
def get_matching_hash_in_list(v_list, v_hash, match_bin=False):
|
||||
return get_matching(v_list, v_hash, "get_hash_string", match_bin)
|
||||
return get_matching(v_list, v_hash, lambda x: x.get_hash_string(), match_bin)
|
||||
|
||||
|
||||
def get_matching_path_in_list(v_list, v_hash, match_bin=False):
|
||||
return get_matching(v_list, v_hash, "get_hash_path", match_bin)
|
||||
return get_matching(v_list, v_hash, lambda x: x.get_hash_path(), match_bin)
|
||||
|
||||
|
||||
def get_matching_full_string_in_list(v_list, v_hash, match_bin=False):
|
||||
return get_matching(v_list, v_hash, "get_full_string", match_bin)
|
||||
return get_matching(v_list, v_hash, lambda x: x.get_full_string(), match_bin)
|
||||
|
||||
|
||||
# ---------------------------- HASH LIST FUNCTIONS --------------------------------------------
|
||||
|
Reference in New Issue
Block a user