mirror of https://github.com/fail2ban/fail2ban
ENH: refactored previous commit to make it more Pythonic (With prev commit closes gh-86, gh-81)
parent
6288ec2757
commit
f14c7ae401
|
@ -127,7 +127,7 @@ class Actions(JailThread):
|
|||
def removeBannedIP(self, ip):
|
||||
# Find the ticket with the IP.
|
||||
ticket = self.__banManager.getTicketByIP(ip)
|
||||
if ticket != False:
|
||||
if ticket is not None:
|
||||
# Unban the IP.
|
||||
self.__unBan(ticket)
|
||||
return ip
|
||||
|
|
|
@ -230,20 +230,14 @@ class BanManager:
|
|||
# @return the ticket for the IP or False.
|
||||
def getTicketByIP(self, ip):
|
||||
try:
|
||||
ipticket = False
|
||||
self.__lock.acquire()
|
||||
|
||||
# Find the ticket the IP goes with.
|
||||
for ticket in self.__banList:
|
||||
# Find the ticket the IP goes with and return it
|
||||
for i, ticket in enumerate(self.__banList):
|
||||
if ticket.getIP() == ip:
|
||||
ipticket = ticket
|
||||
break
|
||||
|
||||
unBanList = [ipticket]
|
||||
# Remove the ticket from the ban list.
|
||||
self.__banList = [ticket for ticket in self.__banList
|
||||
if ticket not in unBanList]
|
||||
|
||||
return ipticket
|
||||
# Return the ticket after removing (popping)
|
||||
# if from the ban list.
|
||||
return self.__banList.pop(i)
|
||||
finally:
|
||||
self.__lock.release()
|
||||
return None # if none found
|
||||
|
|
Loading…
Reference in New Issue