forked from WithSecureLabs/drozer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.py
44 lines (32 loc) · 1.17 KB
/
session.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
class Session:
"""
Session encapsulates the parameters of a session, established between an
Agent (device) and a Console.
All sessions are persisted in the Sessions collection, which is a singleton
instance of SessionCollection. Sessions are accessed by identifier.
"""
def __init__(self, session_id, device, console):
self.session_id = session_id
self.device = device
self.console = console
def __str__(self):
return "<Mercury Session: %s />" % (self.session_id)
class SessionCollection(set):
"""
SessionCollection provides a thin wrapper on top of a set to provide a DSL
for interacting with the sessions.
"""
def add_session(self, session_id, device, console):
"""
Create a Session, and add it to the collection.
"""
self.add(Session(session_id, device, console))
def get(self, session_id):
"""
Retrieve a Session from the collection, by identifier.
"""
for session in self:
if session.session_id == session_id:
return session
return None
Sessions = SessionCollection()