forked from openrightsgroup/OrgProbe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory.py
28 lines (23 loc) · 889 Bytes
/
category.py
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
import logging
import urlparse
class Categorizor(object):
def __init__(self, category_rule):
"""category_rule is a string of the format:
type:parameter:modifier
To get the base64 decoded value of the category querystring
parameter, use:
"querystring:category:base64"
"""
self.rule = category_rule.split(':')
def categorize(self, final_url):
if self.rule[0] == 'querystring':
try:
qs = urlparse.parse_qs(urlparse.urlparse(final_url).query)
param = qs[self.rule[1]][0]
if len(self.rule) == 3:
if self.rule[2] == 'base64':
param = param.decode('base64')
logging.debug("Got category: %s", param)
return param
except (KeyError, IndexError):
return None