blind 2to3
[plcapi.git] / PLC / Methods / DeleteSession.py
1 import time
2
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import SessionAuth
6 from PLC.Sessions import Session, Sessions
7
8 class DeleteSession(Method):
9     """
10     Invalidates the current session.
11
12     Returns 1 if successful.
13     """
14
15     roles = ['admin', 'pi', 'user', 'tech', 'node']
16     accepts = [SessionAuth()]
17     returns = Parameter(int, '1 if successful')
18
19
20     def call(self, auth):
21         assert 'session' in auth
22
23         sessions = Sessions(self.api, [auth['session']])
24         if not sessions:
25             raise PLCAPIError("No such session")
26         session = sessions[0]
27
28         session.delete()
29
30         return 1