From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.57]) by gnuweeb.org (Postfix) with ESMTPSA id 7573C7E7BE; Tue, 19 Jul 2022 00:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658189902; bh=OWqEoJAvuUHATv7xyCic6oqWhaFoxmc4FSfYAXQNRtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8veMELI5mbg00H7Y46qrwlN5hl9CZSyVrcExUjUIlnMMgG+XeAjSeZkVeK2nkJJ/ aPecsn1FcVcARKtkNTcycSGJ3Pt0Fv8+ULDnySHUn7ldEysX2hqpA0XrWLwAHJ5TVe 1xCGOZOxsxQiE1ceSt94Gu0eswGcFvRT9AA96DoXS++XDNaEmfcQMjcSe7xTHq16XN iMWI2BXGCAVnXoqqxKiRVLNjQM2pr4Xlew94YKRR2dB5Qf8dbYSdhivYe0946QAYOX SXEFkOOefqESiK1qIH6UhvSE3Gpm4KJmFhuJ4cIPH+G4o2k9hkgql0tSumdbz/N6Bk ShFUBlttPMVqg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 10/18] Create fix_utf8_chars function Date: Tue, 19 Jul 2022 07:17:36 +0700 Message-Id: <20220719001744.1950-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220719001744.1950-1-kiizuha@gnuweeb.org> References: <20220719001744.1950-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: From: Muhammad Rizki Some of the codes are repeated, so I create this function to make it cleaner. Signed-off-by: Muhammad Rizki --- daemon/scraper/utils.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/daemon/scraper/utils.py b/daemon/scraper/utils.py index 5335fe2..3f0d254 100644 --- a/daemon/scraper/utils.py +++ b/daemon/scraper/utils.py @@ -183,10 +183,7 @@ def create_template(thread: Message, to=None, cc=None): ret = ret[:4000] + "..." ret = ( - ret.rstrip() - .replace("<", "<") - .replace(">",">") - .replace("�"," ") + fix_utf8_char(ret) ) + "\n------------------------------------------------------------------------" return ret, files, is_patch @@ -213,10 +210,7 @@ def prepare_send_patch(mail, text, url): caption = ( "#patch #ml\n" + - cap.rstrip() - .replace("<", "<") - .replace(">",">") - .replace("�"," ") + fix_utf8_char(cap) ) return tmp, file, caption, url @@ -225,6 +219,15 @@ def clean_up_after_send_patch(tmp): shutil.rmtree(tmp) +def fix_utf8_char(text: str): + return ( + text.rstrip() + .replace("<", "<") + .replace(">",">") + .replace("�"," ") + ) + + EMAIL_MSG_ID_PATTERN = r"<([^\<\>]+)>" def extract_email_msg_id(msg_id): ret = re.search(EMAIL_MSG_ID_PATTERN, msg_id) -- Muhammad Rizki