From a22c14f21c03738ee345a75d7dc169a8aa1ed3dc Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 15 Sep 2023 02:19:44 +0300 Subject: [PATCH] remove unnecessary shit --- files/helpers/config/const.py | 2 +- files/helpers/const_stateful.py | 2 +- files/helpers/logging.py | 2 +- files/helpers/media.py | 2 +- files/helpers/settings.py | 4 ++-- files/routes/admin.py | 6 +++--- files/routes/comments.py | 6 +++--- files/routes/jinja2.py | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 26f87964a..6e251266d 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -1139,5 +1139,5 @@ csp = f"default-src 'none'; frame-ancestors 'none'; form-action 'self'; manifest if not IS_LOCALHOST: csp += ' upgrade-insecure-requests;' -with open("includes/content-security-policy", "w", encoding="utf-8") as f: +with open("includes/content-security-policy", "w") as f: f.write(f'add_header Content-Security-Policy "{csp}";') diff --git a/files/helpers/const_stateful.py b/files/helpers/const_stateful.py index 58b95fff8..a045806ee 100644 --- a/files/helpers/const_stateful.py +++ b/files/helpers/const_stateful.py @@ -43,7 +43,7 @@ def const_initialize(): filename = f"snappy_{SITE_NAME}.txt" try: - with open(filename, "r", encoding="utf-8") as f: + with open(filename, "r") as f: SNAPPY_QUOTES = f.read().split("\n{[para]}\n") except FileNotFoundError: pass diff --git a/files/helpers/logging.py b/files/helpers/logging.py index 0ea596ea6..241837b0b 100644 --- a/files/helpers/logging.py +++ b/files/helpers/logging.py @@ -6,7 +6,7 @@ def log_file(log_str, log_filename="rdrama.log"): ''' log_target = f"{LOG_DIRECTORY}/{log_filename}" try: - with open(log_target, "a", encoding="utf-8") as f: + with open(log_target, "a") as f: f.write(log_str + '\n') except Exception as e: print(f"Failed to log to file {log_target} due to {e.__class__.__name__}") diff --git a/files/helpers/media.py b/files/helpers/media.py index 4902d187b..6eda9aa9f 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -65,7 +65,7 @@ def process_files(files, v, body, is_dm=False, dm_user=None): body = body.replace(f'[{file.filename}]', f' {url} ', 1) if is_dm: - with open(f"{LOG_DIRECTORY}/dm_media.log", "a+", encoding="utf-8") as f: + with open(f"{LOG_DIRECTORY}/dm_media.log", "a+") as f: if dm_user: f.write(f'{url}, {v.username}, {v.id}, {dm_user.username}, {dm_user.id}, {int(time.time())}\n') else: diff --git a/files/helpers/settings.py b/files/helpers/settings.py index b31922c04..d37141914 100644 --- a/files/helpers/settings.py +++ b/files/helpers/settings.py @@ -35,13 +35,13 @@ def reload_settings(): global _SETTINGS if not os.path.isfile(SETTINGS_FILENAME): _save_settings() - with open(SETTINGS_FILENAME, 'r', encoding='utf_8') as f: + with open(SETTINGS_FILENAME, 'r') as f: x = f.read() if x: _SETTINGS = json.loads(x) def _save_settings(): - with open(SETTINGS_FILENAME, "w", encoding='utf_8') as f: + with open(SETTINGS_FILENAME, "w") as f: json.dump(_SETTINGS, f) def start_watching_settings(): diff --git a/files/routes/admin.py b/files/routes/admin.py index 2f76eb75c..f0c2725d1 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -46,7 +46,7 @@ def loggedout_list(v): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @admin_level_required(PERMS['ENABLE_DM_MEDIA']) def dm_media(v): - with open(f"{LOG_DIRECTORY}/dm_media.log", "r", encoding="utf-8") as f: + with open(f"{LOG_DIRECTORY}/dm_media.log", "r") as f: items=f.read().split("\n")[:-1] total = len(items) @@ -68,7 +68,7 @@ def dm_media(v): @admin_level_required(PERMS['EDIT_RULES']) def edit_rules_get(v): try: - with open(f'files/templates/rules_{SITE_NAME}.html', 'r', encoding="utf-8") as f: + with open(f'files/templates/rules_{SITE_NAME}.html', 'r') as f: rules = f.read() except: rules = None @@ -85,7 +85,7 @@ def edit_rules_post(v): rules = request.values.get('rules', '').strip() rules = sanitize(rules, blackjack="rules") - with open(f'files/templates/rules_{SITE_NAME}.html', 'w+', encoding="utf-8") as f: + with open(f'files/templates/rules_{SITE_NAME}.html', 'w+') as f: f.write(rules) ma = ModAction( diff --git a/files/routes/comments.py b/files/routes/comments.py index ac53c17b5..9b5a67765 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -247,7 +247,7 @@ def comment(v): body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and posting_to_post and post_target.id == SNAPPY_THREAD and level == 1: - with open(f"snappy_{SITE_NAME}.txt", "r+", encoding="utf-8") as f: + with open(f"snappy_{SITE_NAME}.txt", "r+") as f: body_for_checking = '\n{[para]}\n' + body + '\n{[para]}\n' if body_for_checking in f.read(): abort(400, "Snappy quote already exists!") @@ -452,12 +452,12 @@ def delete_comment(cid, v): if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and c.parent_post == SNAPPY_THREAD and c.level == 1: body = '\n{[para]}\n' + c.body + '\n' - with open(f"snappy_{SITE_NAME}.txt", "r", encoding="utf-8") as f: + with open(f"snappy_{SITE_NAME}.txt", "r") as f: old_text = f.read() if old_text.endswith(body): new_text = old_text.split(body)[0] + '\n' - with open(f"snappy_{SITE_NAME}.txt", "w", encoding="utf-8") as f: + with open(f"snappy_{SITE_NAME}.txt", "w") as f: f.write(new_text) return {"message": "Comment deleted!"} diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 3c671b739..fa5246e46 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -88,11 +88,11 @@ def git_head(): # However, they forbid '..', so I don't see an obvious dir traversal attack. # Also, a malicious branch name would mean someone already owned the server # or repo, so I think this isn't a weak link. - with open('.git/HEAD', encoding='utf_8') as head_f: + with open('.git/HEAD') as head_f: head_txt = head_f.read() try: head_path = git_regex.match(head_txt).group(1) - with open('.git/' + head_path, encoding='utf_8') as ref_f: + with open('.git/' + head_path) as ref_f: gitref = ref_f.read()[:7] except: gitref = 'Error'