11 _moduleLogger = logging.getLogger("gvoice.session")
14 class Session(object):
16 def __init__(self, cookiePath = None):
20 self._backend = backend.GVoiceBackend(cookiePath)
21 self._addressbook = addressbook.Addressbook(self._backend)
22 self._conversations = conversations.Conversations(self._backend)
23 self._stateMachine = state_machine.StateMachine([self.addressbook], [self.conversations])
25 self._conversations.updateSignalHandler.register_sink(
26 self._stateMachine.request_reset_timers
30 self._conversations.updateSignalHandler.unregister_sink(
31 self._stateMachine.request_reset_timers
33 self._stateMachine.close()
35 def login(self, username, password):
36 self._username = username
37 self._password = password
38 if not self._backend.is_authed():
39 self._backend.login(self._username, self._password)
41 self._stateMachine.start()
44 self._stateMachine.stop()
45 self._backend.logout()
50 def is_logged_in(self):
51 if self._username is None and self._password is None:
52 _moduleLogger.info("Hasn't even attempted to login yet")
54 elif self._backend.is_authed():
58 loggedIn = self._backend.login(self._username, self._password)
59 except RuntimeError, e:
60 _moduleLogger.exception("Re-authenticating and erroring")
65 _moduleLogger.info("Login failed")
72 Login enforcing backend
74 assert self.is_logged_in(), "User not logged in"
78 def addressbook(self):
80 Delay initialized addressbook
82 return self._addressbook
85 def conversations(self):
87 Delay initialized addressbook
89 return self._conversations
92 def stateMachine(self):
93 return self._stateMachine