diff src/memory/memory.py @ 1693:35426d58471c

core (memory): stopSession implementation
author Goffi <goffi@goffi.org>
date Fri, 27 Nov 2015 16:48:41 +0100
parents a40124e03baf
children 3c608d660f0b
line wrap: on
line diff
--- a/src/memory/memory.py	Fri Nov 27 16:45:55 2015 +0100
+++ b/src/memory/memory.py	Fri Nov 27 16:48:41 2015 +0100
@@ -357,6 +357,20 @@
 
         return self.host.initialised.addCallback(backendInitialised)
 
+    def stopSession(self, profile):
+        """Delete a profile session
+
+        @param profile: %(doc_profile)s
+        """
+        if self.host.isConnected(profile):
+            log.debug(u"Disconnecting profile because of session stop")
+            self.host.disconnect(profile)
+        self.auth_sessions.profileDelUnique(profile)
+        try:
+            self._entities_cache[profile]
+        except KeyError:
+            log.warning(u"Profile was not in cache")
+
     def _isSessionStarted(self, profile_key):
         return self.isSessionStarted(self.getProfileName(profile_key))
 
@@ -374,6 +388,7 @@
         @param password (unicode): the SàT profile password
         @param profile: %(doc_profile)s
         @return (D): a deferred None in case of success, a failure otherwise.
+        @raise exceptions.PasswordError: the password does not match
         """
         session_data = self.auth_sessions.profileGetUnique(profile)
         if not password and session_data:
@@ -385,7 +400,7 @@
         def check_result(result):
             if not result:
                 log.warning(u'Authentication failure of profile {}'.format(profile))
-                raise exceptions.PasswordError(u"The provided profile password doesn't match.")
+                raise failure.Failure(exceptions.PasswordError(u"The provided profile password doesn't match."))
             if not session_data:  # avoid to create two profile sessions when password if specified
                 return self.newAuthSession(password, profile)