ENH: refactored previous commit to make it more Pythonic (With prev commit closes gh-86, gh-81)

pull/64/merge
Yaroslav Halchenko 2012-11-05 20:37:06 -05:00
parent 6288ec2757
commit f14c7ae401
2 changed files with 7 additions and 13 deletions

View File

@ -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

View File

@ -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