-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.py
39 lines (33 loc) · 876 Bytes
/
params.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
29
30
31
32
33
34
35
36
37
38
39
class Params:
def __init__(self):
self.dict = []
def __getitem__(self, x):
if type(x) is int:
return self.index(x)
if type(x) is str:
return self.get(x)
raise Exception("Bad type index")
def __len__(self):
return len(self.dict)
def __contains__(self, x):
if type(x) == tuple and len(x) == 2:
if type(x[0]) == str and type(x[1]) == str:
return x in self.dict
if type(x) == str:
for k,v in self.dict:
if k == x:
return True
return False
raise Exception("Bad search type")
def add(self, param, value):
if (not type(param) is str) or (not type(value) is str):
raise Exception("Parameters must be strings")
self.dict.append((param, value))
def index(self, i):
return self.dict[i]
def get(self, x):
ret = []
for k,v in self.dict:
if k == x:
ret.append(v)
return ret