-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_of_translateables.py
55 lines (41 loc) · 1.38 KB
/
list_of_translateables.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from collections import MutableSequence
class ListOfTranslateAbles(MutableSequence):
"""A container for manipulating lists of hosts"""
def __init__(self, data=None):
"""Initialize the class"""
super(ListOfTranslateAbles, self).__init__()
if (data is not None):
self._list = list(data)
else:
self._list = list()
def __repr__(self):
return "<{0} {1}>".format(self.__class__.__name__, self._list)
def __len__(self):
"""List length"""
return len(self._list)
def __getitem__(self, ii):
"""Get a list item"""
return self._list[ii]
def __delitem__(self, ii):
"""Delete an item"""
del self._list[ii]
def __setitem__(self, ii, val):
# optional: self._acl_check(val)
self._list[ii] = val
def __str__(self):
return str(self._list)
def insert(self, ii, val):
# optional: self._acl_check(val)
self._list.insert(ii, val)
def append(self, val):
self.insert(len(self._list), val)
def keys(self):
keys = []
for translate_able in self._list:
keys.append(translate_able.new_msgid)
return keys
def get_translate_able(self, key):
for translate_able in self._list:
if translate_able.new_msgid == key:
return translate_able
return None