Limiting the sizes of logs
[theonering] / src / presence.py
1 import logging
2
3 import tp
4 import util.misc as misc_utils
5
6
7 _moduleLogger = logging.getLogger(__name__)
8
9
10 class PresenceMixin(tp.ConnectionInterfacePresence):
11
12         def __init__(self, torPresence):
13                 tp.ConnectionInterfacePresence.__init__(self)
14                 self.__torPresence = torPresence
15
16         @misc_utils.log_exception(_moduleLogger)
17         def GetStatuses(self):
18                 # the arguments are in common to all on-line presences
19                 arguments = {}
20
21                 return dict(
22                         (localType, (telepathyType, True, True, arguments))
23                         for (localType, telepathyType) in self.__torPresence.TO_PRESENCE_TYPE.iteritems()
24                 )
25
26         @misc_utils.log_exception(_moduleLogger)
27         def RequestPresence(self, contactIds):
28                 presences = self.__get_presences(contactIds)
29                 self.PresenceUpdate(presences)
30
31         @misc_utils.log_exception(_moduleLogger)
32         def GetPresence(self, contactIds):
33                 return self.__get_presences(contactIds)
34
35         @misc_utils.log_exception(_moduleLogger)
36         def SetStatus(self, statuses):
37                 assert len(statuses) == 1
38                 status, arguments = statuses.items()[0]
39                 assert len(arguments) == 0
40                 self.__torPresence.set_presence(status)
41
42         def __get_presences(self, contacts):
43                 arguments = {}
44                 return dict(
45                         (h, (0, {presence: arguments}))
46                         for (h, (presenceType, presence)) in self.__torPresence.get_presences(contacts).iteritems()
47                 )