Upating telepathy python to a7418e92965713edae61d9e762b8c895a68a7251
[theonering] / src / capabilities.py
1 import logging
2
3 import telepathy
4
5 import tp
6 import util.misc as misc_utils
7
8
9 _moduleLogger = logging.getLogger(__name__)
10
11
12 class CapabilitiesMixin(tp.ConnectionInterfaceCapabilities):
13
14         _CAPABILITIES = {
15                 telepathy.CHANNEL_TYPE_TEXT: (
16                         telepathy.CONNECTION_CAPABILITY_FLAG_CREATE,
17                         0,
18                 ),
19                 telepathy.CHANNEL_TYPE_STREAMED_MEDIA: (
20                         telepathy.CONNECTION_CAPABILITY_FLAG_CREATE |
21                                 telepathy.CONNECTION_CAPABILITY_FLAG_INVITE,
22                         telepathy.CHANNEL_MEDIA_CAPABILITY_AUDIO,
23                 ),
24         }
25
26         def __init__(self):
27                 tp.ConnectionInterfaceCapabilities.__init__(self)
28
29         def get_handle_by_id(self, handleType, handleId):
30                 """
31                 @abstract
32                 """
33                 raise NotImplementedError("Abstract function called")
34
35         @misc_utils.log_exception(_moduleLogger)
36         def GetCapabilities(self, handleIds):
37                 ret = []
38                 for handleId in handleIds:
39                         if handleId != 0 and (telepathy.HANDLE_TYPE_CONTACT, handleId) not in self._handles:
40                                 raise telepathy.errors.InvalidHandle
41
42                         h = self.get_handle_by_id(telepathy.HANDLE_TYPE_CONTACT, handleId)
43                         for type, (gen, spec) in self._CAPABILITIES.iteritems():
44                                 ret.append([handleId, type, gen, spec])
45                 return ret