Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix ruff lint errors #127

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mailadm/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def main(mailadm_db, admbot_db_path):
while 1:
for logmsg in prune(mailadm_db).get("message"):
logging.info("%s", logmsg)
for _second in range(0, 600):
for _second in range(600):
if not ac._event_thread.is_alive():
logging.error("dc core event thread died, exiting now")
os._exit(1)
Expand Down
4 changes: 3 additions & 1 deletion src/mailadm/gen_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def gen_qr(config, token_info):
qr_final_size = width - (qr_padding * 2)

# draw text
info_pos = (width - font.getsize(info.strip())[0]) // 2
font_left, _font_top, font_right, _font_bottom = font.getbbox(info.strip())
font_width = font_right - font_left
info_pos = (width - font_width) // 2
draw.multiline_text(
(info_pos, size - qr_padding // 2),
info,
Expand Down
8 changes: 4 additions & 4 deletions src/mailadm/mailcow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def add_user_mailcow(self, addr, password, token, quota=0):
"tags": ["mailadm:" + token],
}
result = r.post(url, json=payload, headers=self.auth, timeout=HTTP_TIMEOUT)
if type(result.json()) != list or result.json()[0].get("type") != "success":
if not isinstance(result.json(), list) or result.json()[0].get("type") != "success":
raise MailcowError(result.json())

def del_user_mailcow(self, addr):
Expand All @@ -59,12 +59,12 @@ def get_user(self, addr):
json = result.json()
if json == {}:
return None
if type(json) == dict:
if isinstance(json, dict):
if json.get("type") == "error":
raise MailcowError(json)
return MailcowUser(json)
# some mailcow versions return all users, even if you only ask for a specific one:
if type(json) == list:
if isinstance(json, list):
for user in [MailcowUser(user) for user in json]:
if user.addr == addr:
return user
Expand All @@ -79,7 +79,7 @@ def get_user_list(self):
json = result.json()
if json == {}:
return []
if type(json) == dict:
if isinstance(json, dict):
if json.get("type") == "error":
raise MailcowError(json)
return [MailcowUser(user) for user in json]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def add_user_db(*args, **kwargs):
auth = {"X-API-Key": conn.config.mailcow_token}
result = requests.get(url, headers=auth)
assert result.status_code == 200
if result.json() is not {} and type(result.json()) == list:
if result.json() is not {} and not isinstance(result.json(), list):
for user in result.json():
assert user["username"] != addr

Expand Down Expand Up @@ -243,4 +243,4 @@ def test_delete_user_mailcow_missing(conn, mailcow, mailcow_domain):

def test_db_version(conn):
version = conn.get_dbversion()
assert type(version) == int
assert isinstance(version, int)
Loading