00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 from objects.logic.entity.filter.baseFilter import baseFilter
00018 from objects.logic.entity.filter.filterDictionary import filterDictionary
00019 from threading import RLock
00020 import copy
00021
00022
00023
00024
00025
00026 class customFilter(baseFilter):
00027 def __init__(self):
00028 baseFilter.__init__(self)
00029
00030 self.customfilterList = []
00031 self.filterDict = filterDictionary()
00032
00033 self.lck = RLock()
00034
00035
00036
00037
00038
00039 def shouldDisplayEntity(self, networkEntity):
00040 if baseFilter.shouldDisplayEntity(self, networkEntity) == False:
00041 return False
00042 else:
00043
00044 self.lck.acquire(1)
00045 try:
00046 if len(self.customfilterList) == 0: return True
00047
00048 for filterCat, filterVal in self.customfilterList:
00049 attr, type = self.filterDict.filter[filterCat]
00050 if networkEntity[attr] == filterVal:
00051 return False
00052 finally:
00053 self.lck.release()
00054
00055 return True
00056
00057
00058
00059
00060 def getSafeFilterList(self):
00061 copyList = []
00062
00063 self.lck.acquire(1)
00064 try:
00065 copyList = copy.deepcopy(self.customfilterList)
00066 finally:
00067 self.lck.release()
00068
00069 return copyList
00070
00071
00072
00073
00074
00075
00076 def addToFilter(self, filterTuple):
00077 self.lck.acquire(1)
00078 try:
00079 self.customfilterList.append(filterTuple)
00080 finally:
00081 self.lck.release()
00082
00083
00084
00085
00086
00087 def removeFromFilter(self, filterTuple):
00088 self.lck.acquire(1)
00089 try:
00090 self.customfilterList.remove(filterTuple)
00091 finally:
00092 self.lck.release()
00093