From caa452116927d54b37c96c086bd2f7e62a8a56e4 Mon Sep 17 00:00:00 2001 From: Alexander Koeppe Date: Fri, 8 Apr 2016 22:47:09 +0200 Subject: [PATCH] optional IP address argument of iparg decorator --- fail2ban/ipaddr.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fail2ban/ipaddr.py b/fail2ban/ipaddr.py index bde4105d..702f21a1 100644 --- a/fail2ban/ipaddr.py +++ b/fail2ban/ipaddr.py @@ -21,7 +21,7 @@ # __author__ = "Alexander Koeppe" -__copyright__ = "Copyright (c) 2004 Cyril Jaquier" +__copyright__ = "Copyright (c) 2016 Alexander Koeppe" __license__ = "GPL" import inspect @@ -33,11 +33,11 @@ from functools import wraps ## # Helper functions / decorator -# +# Thanks to Yaroslav Halchenko (yarikoptic) # def asip(ip): """A little helper to guarantee ip being an IPAddr instance""" - return ip if isinstance(ip, IPAddr) else IPAddr(ip) + return ip if isinstance(ip, IPAddr) or ip == None else IPAddr(ip) def iparg(f): """A helper decorator to simplify use of asip throughout the code""" @@ -48,11 +48,11 @@ def iparg(f): if args and args[0] == 'self': # method -- just above simpler version @wraps(f) - def checkip(self, ip, *argv, **kwargs): + def checkip(self, ip=None, *argv, **kwargs): return f(self, asip(ip), *argv, **kwargs) else: @wraps(f) - def checkip(ip, *argv, **kwargs): + def checkip(ip=None, *argv, **kwargs): return f(asip(ip), *argv, **kwargs) return checkip