From 9e25b4a936554a1c7a6c857b5a53afd70263169c Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 2 Jul 2026 23:44:53 +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 f349f2ca1..c462e57d1 100644 --- a/apport/report.py +++ b/apport/report.py @@ -1880,15 +1880,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: @@ -1911,6 +1904,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: