Add lots of static typing
Signed-off-by: Luis Garcia <git@luigi311.com>
This commit is contained in:
@@ -2,14 +2,14 @@ from src.functions import logger, search_mapping
|
||||
|
||||
|
||||
def setup_black_white_lists(
|
||||
blacklist_library: str,
|
||||
whitelist_library: str,
|
||||
blacklist_library_type: str,
|
||||
whitelist_library_type: str,
|
||||
blacklist_users: str,
|
||||
whitelist_users: str,
|
||||
library_mapping=None,
|
||||
user_mapping=None,
|
||||
blacklist_library: list[str] | None,
|
||||
whitelist_library: list[str] | None,
|
||||
blacklist_library_type: list[str] | None,
|
||||
whitelist_library_type: list[str] | None,
|
||||
blacklist_users: list[str] | None,
|
||||
whitelist_users: list[str] | None,
|
||||
library_mapping: dict[str, str] | None = None,
|
||||
user_mapping: dict[str, str] | None = None,
|
||||
):
|
||||
blacklist_library, blacklist_library_type, blacklist_users = setup_x_lists(
|
||||
blacklist_library,
|
||||
@@ -40,53 +40,44 @@ def setup_black_white_lists(
|
||||
|
||||
|
||||
def setup_x_lists(
|
||||
xlist_library,
|
||||
xlist_library_type,
|
||||
xlist_users,
|
||||
xlist_type,
|
||||
library_mapping=None,
|
||||
user_mapping=None,
|
||||
):
|
||||
xlist_library: list[str] | None,
|
||||
xlist_library_type: list[str] | None,
|
||||
xlist_users: list[str] | None,
|
||||
xlist_type: str | None,
|
||||
library_mapping: dict[str, str] | None = None,
|
||||
user_mapping: dict[str, str] | None = None,
|
||||
) -> tuple[list[str], list[str], list[str]]:
|
||||
out_library: list[str] = []
|
||||
if xlist_library:
|
||||
if len(xlist_library) > 0:
|
||||
xlist_library = xlist_library.split(",")
|
||||
xlist_library = [x.strip() for x in xlist_library]
|
||||
if library_mapping:
|
||||
temp_library = []
|
||||
for library in xlist_library:
|
||||
library_other = search_mapping(library_mapping, library)
|
||||
if library_other:
|
||||
temp_library.append(library_other)
|
||||
out_library = [x.strip() for x in xlist_library]
|
||||
if library_mapping:
|
||||
temp_library: list[str] = []
|
||||
for library in xlist_library:
|
||||
library_other = search_mapping(library_mapping, library)
|
||||
if library_other:
|
||||
temp_library.append(library_other)
|
||||
|
||||
xlist_library = xlist_library + temp_library
|
||||
else:
|
||||
xlist_library = []
|
||||
logger(f"{xlist_type}list Library: {xlist_library}", 1)
|
||||
out_library = out_library + temp_library
|
||||
logger(f"{xlist_type}list Library: {xlist_library}", 1)
|
||||
|
||||
out_library_type: list[str] = []
|
||||
if xlist_library_type:
|
||||
if len(xlist_library_type) > 0:
|
||||
xlist_library_type = xlist_library_type.split(",")
|
||||
xlist_library_type = [x.lower().strip() for x in xlist_library_type]
|
||||
else:
|
||||
xlist_library_type = []
|
||||
logger(f"{xlist_type}list Library Type: {xlist_library_type}", 1)
|
||||
out_library_type = [x.lower().strip() for x in xlist_library_type]
|
||||
|
||||
logger(f"{xlist_type}list Library Type: {out_library_type}", 1)
|
||||
|
||||
out_users: list[str] = []
|
||||
if xlist_users:
|
||||
if len(xlist_users) > 0:
|
||||
xlist_users = xlist_users.split(",")
|
||||
xlist_users = [x.lower().strip() for x in xlist_users]
|
||||
if user_mapping:
|
||||
temp_users = []
|
||||
for user in xlist_users:
|
||||
user_other = search_mapping(user_mapping, user)
|
||||
if user_other:
|
||||
temp_users.append(user_other)
|
||||
out_users = [x.lower().strip() for x in xlist_users]
|
||||
if user_mapping:
|
||||
temp_users: list[str] = []
|
||||
for user in out_users:
|
||||
user_other = search_mapping(user_mapping, user)
|
||||
if user_other:
|
||||
temp_users.append(user_other)
|
||||
|
||||
xlist_users = xlist_users + temp_users
|
||||
else:
|
||||
xlist_users = []
|
||||
else:
|
||||
xlist_users = []
|
||||
logger(f"{xlist_type}list Users: {xlist_users}", 1)
|
||||
out_users = out_users + temp_users
|
||||
|
||||
return xlist_library, xlist_library_type, xlist_users
|
||||
logger(f"{xlist_type}list Users: {out_users}", 1)
|
||||
|
||||
return out_library, out_library_type, out_users
|
||||
|
||||
Reference in New Issue
Block a user