From e2ed4c1feeef1e32a8a4302d69367d6489593b11 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Tue, 21 Apr 2026 17:59:19 +0200 Subject: [PATCH] report: introduce _get_replacements helper method Carve out `Report._get_replacements` from the big `Report.anonymize()` method to make the code more readable and pylint happy. --- apport/report.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apport/report.py b/apport/report.py index c828c8b63..aad7654e7 100644 --- a/apport/report.py +++ b/apport/report.py @@ -1895,15 +1895,8 @@ def crash_signature_addresses(self) -> str | None: return f"{self['ExecutablePath']}:{self['Signal']}:{':'.join(stack)}" - # TODO: Split into smaller functions/methods - # pylint: disable-next=too-complex - def anonymize(self) -> None: - """Remove user identifying strings from the report. - - This particularly removes the user name, host name, and IPs - from attributes which contain data read from the environment, and - removes the ProcCwd attribute completely. - """ + @staticmethod + def _get_replacements() -> list[tuple[re.Pattern[str], str]]: replacements = [] # Do not replace "root" if os.getuid() > 0: @@ -1926,6 +1919,17 @@ def anonymize(self) -> None: if len(hostname) >= 2: replacements.append((re.compile(rf"\b{re.escape(hostname)}\b"), "hostname")) + return replacements + + def anonymize(self) -> None: + """Remove user identifying strings from the report. + + This particularly removes the user name, host name, and IPs + from attributes which contain data read from the environment, and + removes the ProcCwd attribute completely. + """ + replacements = self._get_replacements() + try: del self["ProcCwd"] except KeyError: