-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures.py
More file actions
48 lines (29 loc) · 910 Bytes
/
features.py
File metadata and controls
48 lines (29 loc) · 910 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
from settings import METHODS
class Feature(object):
def __init__(self, l):
self.l = l
def count_factor(self, request):
return self.l(request)
def name(self):
return self.l.__name__
def MethodFeature(request):
return METHODS.index(request.method)
def UriLengthFeature(request):
return len(request.url)
def ParamCountFeature(request):
return len(request.args)
def HeadersCount(request):
return len(request.headers)
def UALengthFeature(request):
return len(request.headers.get('User-Agent', ''))
Features = [Feature(MethodFeature),
Feature(UriLengthFeature),
Feature(ParamCountFeature),
Feature(HeadersCount),
Feature(UALengthFeature)]
FeaturesCount = len(Features)
def count_features(request):
res = []
for f in Features:
res.append(f.count_factor(request))
return res