From e5166d9636e52d756772fcd06d9cb3d9abb81718 Mon Sep 17 00:00:00 2001 From: bashrc Date: Sun, 26 Apr 2026 17:09:34 +0100 Subject: [PATCH] Revert "Replace appends with functions" This reverts commit 9a30659731b17704caa5cc6a0e2d804fbc8f724b. --- blocking.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/blocking.py b/blocking.py index bd19b39e7..7376cf0c5 100644 --- a/blocking.py +++ b/blocking.py @@ -1740,20 +1740,24 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str, if not append_blocks: return True - text = '' - for new_block in append_blocks: - text += new_block + '\n' - append_string(text, blocking_filename, - 'EX: ' + - 'unable to append imported blocks to ' + - blocking_filename) - text = '' - for new_reason in append_reasons: - text += new_reason + '\n' - append_string(text, blocking_reasons_filename, - 'EX: ' + - 'unable to append imported block reasons to ' + - blocking_reasons_filename) + try: + with open(blocking_filename, 'a+', encoding='utf-8') as fp_blocks: + for new_block in append_blocks: + fp_blocks.write(new_block + '\n') + except OSError: + print('EX: ' + + 'unable to append imported blocks to ' + + blocking_filename) + + try: + with open(blocking_reasons_filename, 'a+', + encoding='utf-8') as fp_blocks: + for new_reason in append_reasons: + fp_blocks.write(new_reason + '\n') + except OSError: + print('EX: ' + + 'unable to append imported block reasons to ' + + blocking_reasons_filename) return True