From 6eb17a5602005900975c925dce7329a4ac322d3b Mon Sep 17 00:00:00 2001 From: Marko Hauptvogel Date: Tue, 11 Nov 2025 10:54:08 +0100 Subject: [PATCH] make Ticket.getID() return str If the original id is a str, it's internally stored as IPAddr. Instead of returning the IPAddr, the getter now only returns a plain str. If it originally was a tuple or None, that is passed as-is. Also now throws an error if the id has an unexpected type. One testcase now fails. --- fail2ban/server/ticket.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fail2ban/server/ticket.py b/fail2ban/server/ticket.py index f25ea509..787f4e84 100644 --- a/fail2ban/server/ticket.py +++ b/fail2ban/server/ticket.py @@ -24,6 +24,8 @@ __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" +from typing import Union + from ..helpers import getLogger from .ipdns import IPAddr, asip from .mytime import MyTime @@ -89,13 +91,17 @@ class Ticket(object): if v is not None: setattr(self, n, v) - def setID(self, value): + def setID(self, value: Union[str, IPAddr, tuple, None]) -> None: # guarantee using IPAddr instead of unicode, str for the IP if isinstance(value, str): value = IPAddr(value) + if not isinstance(value, (IPAddr, tuple, type(None))): + raise TypeError(f"ID has unsupported type: {type(value).__name__}") self._id = value - def getID(self): + def getID(self) -> Union[IPAddr, tuple, None]: + if isinstance(self._id, IPAddr): + return str(self._id) return self._id def getIP(self) -> IPAddr: