blob: 924cc3345426f4d45fa9e54ba05ab9c664efc2e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
__author__ = 'roland'
class Filter(object):
def __init__(self):
pass
def __call__(self, *args, **kwargs):
pass
class AllowDescriptor(Filter):
def __init__(self, allow):
"""
:param allow: List of allowed descriptors
:return:
"""
super(AllowDescriptor, self).__init__()
self.allow = allow
def __call__(self, entity_descriptor):
# get descriptors
_all = []
for desc in list(entity_descriptor.keys()):
if desc.endswith("_descriptor"):
typ, _ = desc.rsplit("_", 1)
if typ in self.allow:
_all.append(typ)
else:
del entity_descriptor[desc]
if not _all:
return None
else:
return entity_descriptor
|