forked from slackapi/python-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
30 lines (26 loc) · 802 Bytes
/
util.py
File metadata and controls
30 lines (26 loc) · 802 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
class SearchList(list):
def find(self, name):
items = []
for child in self:
if child.__class__ == self.__class__:
items += child.find(name)
else:
if child == name:
items.append(child)
if len(items) == 1:
return items[0]
elif items:
return items
else:
return None
class SearchDict(dict):
def find(self, search_string):
# Find the user by ID
user = self.get(search_string)
if user:
return user
else:
# If the user can't be found by ID, try searching by name
for id, user in self.items():
if str(user.name) == search_string:
return user