From da56210e5e638c05ecf2d615bb9b320f37bbfc49 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:45:09 +0000 Subject: [PATCH 1/2] Merge collapsible `if` statements --- werwolf.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/werwolf.py b/werwolf.py index b96fe50..9b411ec 100644 --- a/werwolf.py +++ b/werwolf.py @@ -849,14 +849,16 @@ def generiere_token(name: str, rolle: str) -> str: :return: A token """ - if validiere_rolle_original(name, rolle): - if not ist_token_vorhandem(name, rolle): + if ( + validiere_rolle_original(name, rolle) + and not ist_token_vorhandem(name, rolle) + ): - token = secrets.token_hex(16) - # write the token and the name and the role to the file tokens.txt - with open("tokens.txt", "a", encoding="UTF8") as file: - file.write("+" + token + "+" + name + "+" + rolle + "+1+ \n") - return token + token = secrets.token_hex(16) + # write the token and the name and the role to the file tokens.txt + with open("tokens.txt", "a", encoding="UTF8") as file: + file.write("+" + token + "+" + name + "+" + rolle + "+1+ \n") + return token def validiere_token(token: str) -> bool: @@ -960,10 +962,13 @@ def status_aus_token(token: str): # read the file tokens.txt and check if the token is in the file with open("tokens.txt", "r") as file: for line in file: - if line != "\n": - if "+" + token + "+" in line and line.count("+") == 5: - # split the line at the + and return the name and the role - return line.split("+")[4] + if ( + line != "\n" + and "+" + token + "+" in line + and line.count("+") == 5 + ): + # split the line at the + and return the name and the role + return line.split("+")[4] return "Fehler" From 715248df9d1dcef045ba7e8503eb5670e18e694f Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:45:23 +0000 Subject: [PATCH 2/2] Format code with prettier and black --- werwolf.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/werwolf.py b/werwolf.py index 9b411ec..91a8c1c 100644 --- a/werwolf.py +++ b/werwolf.py @@ -849,10 +849,7 @@ def generiere_token(name: str, rolle: str) -> str: :return: A token """ - if ( - validiere_rolle_original(name, rolle) - and not ist_token_vorhandem(name, rolle) - ): + if validiere_rolle_original(name, rolle) and not ist_token_vorhandem(name, rolle): token = secrets.token_hex(16) # write the token and the name and the role to the file tokens.txt @@ -962,11 +959,7 @@ def status_aus_token(token: str): # read the file tokens.txt and check if the token is in the file with open("tokens.txt", "r") as file: for line in file: - if ( - line != "\n" - and "+" + token + "+" in line - and line.count("+") == 5 - ): + if line != "\n" and "+" + token + "+" in line and line.count("+") == 5: # split the line at the + and return the name and the role return line.split("+")[4] return "Fehler"