Browse Source

- Replaced loop with list comprehension

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@454 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 18 years ago
parent
commit
f8989581b4
  1. 27
      server/banmanager.py

27
server/banmanager.py

@ -136,14 +136,6 @@ class BanManager:
finally:
self.__lock.release()
##
# Delete a ban ticket.
#
# Remove a BanTicket from the ban list.
# @param ticket the ticket
def __delBanTicket(self, ticket):
self.__banList.remove(ticket)
##
# Get the size of the ban list.
@ -177,20 +169,23 @@ class BanManager:
# Return a list of BanTicket which need to be unbanned.
# @param time the time
# @return the list of ticket to unban
# @todo Check the delete operation
def unBanList(self, time):
try:
self.__lock.acquire()
uBList = list()
# Permanent banning
if self.__banTime < 0:
return uBList
for ticket in self.__banList:
if ticket.getTime() < time - self.__banTime:
uBList.append(ticket)
self.__delBanTicket(ticket)
return uBList
return list()
# Gets the list of ticket to remove.
unBanList = [ticket for ticket in self.__banList
if ticket.getTime() < time - self.__banTime]
# Removes tickets.
self.__banList = [ticket for ticket in self.__banList
if ticket not in unBanList]
return unBanList
finally:
self.__lock.release()

Loading…
Cancel
Save