1 """
2 Low-level Skype API definitions.
3
4 This subpackage imports one of the:
5
6 - `Skype4Py.api.darwin`
7 - `Skype4Py.api.posix`
8 - `Skype4Py.api.windows`
9
10 modules based on the current platform.
11
12 Name of the imported module in available in the `platform` variable.
13
14 The modules implement the low-level Skype API and define options
15 for the `Skype.__init__` constructor.
16 """
17 __docformat__ = 'restructuredtext en'
18
19
20 import sys
21 import threading
22 import logging
23
24 from Skype4Py.utils import *
25 from Skype4Py.enums import apiAttachUnknown
26 from Skype4Py.errors import SkypeAPIError
27
28
29 __all__ = ['Command', 'SkypeAPINotifier', 'SkypeAPI']
30
31
32 DEFAULT_PROTOCOL = 5
33 DEFAULT_FRIENDLYNAME = u'Skype4Py'
34 DEFAULT_TIMEOUT = 30000
35
36
38 """Represents an API command. Use `Skype.Command` to instantiate.
39
40 To send a command to Skype, use `Skype.SendCommand`.
41 """
42
44 """Use `Skype.Command` to instantiate the object instead of doing it directly.
45 """
46
47 self.Blocking = Blocking
48 """If set to True, `Skype.SendCommand` will block until the reply is received.
49
50 :type: bool"""
51
52 self.Command = tounicode(Command)
53 """Command string.
54
55 :type: unicode"""
56
57 self.Expected = tounicode(Expected)
58 """Expected reply.
59
60 :type: unicode"""
61
62 self.Id = Id
63 """Command Id.
64
65 :type: int"""
66
67 self.Reply = u''
68 """Reply after the command has been sent and Skype has replied.
69
70 :type: unicode"""
71
72 self.Timeout = Timeout
73 """Timeout if Blocking == True.
74
75 :type: int"""
76
78 return '<%s with Command=%s, Blocking=%s, Reply=%s, Id=%s>' % \
79 (object.__repr__(self)[1:-1], repr(self.Command), self.Blocking, repr(self.Reply), self.Id)
80
82 """A wrapper for `api.timeout2float` function. Returns the converted
83 `Timeout` property.
84 """
85 return timeout2float(self.Timeout)
86
87
100
101
104 threading.Thread.__init__(self, name='Skype4Py API thread')
105 self.setDaemon(True)
106 if not hasattr(self, 'logger'):
107
108 self.logger = logging.getLogger('Skype4Py.api.SkypeAPIBase')
109 self.friendly_name = DEFAULT_FRIENDLYNAME
110 self.protocol = DEFAULT_PROTOCOL
111 self.commands = {}
112
113 self.rlock = threading.RLock()
114 self.notifier = SkypeAPINotifier()
115 self.attachment_status = apiAttachUnknown
116 self.logger.info('opened')
117
120
122 self.notifier = notifier
123
125 self.acquire()
126 try:
127 if command.Id < 0:
128 command.Id = 0
129 while command.Id in self.commands:
130 command.Id += 1
131 elif command.Id in self.commands:
132 raise SkypeAPIError('Command Id conflict')
133 self.commands[command.Id] = command
134 finally:
135 self.release()
136
138 self.acquire()
139 try:
140 try:
141 return self.commands.pop(id_)
142 except KeyError:
143 return None
144 finally:
145 self.release()
146
149
152
154 self.logger.info('closed')
155
157 self.friendly_name = friendly_name
158
160 if attachment_status != self.attachment_status:
161 self.logger.info('attachment: %s', attachment_status)
162 self.attachment_status = attachment_status
163 self.notifier.attachment_changed(attachment_status)
164
165 - def attach(self, timeout, wait=True):
166 self._not_implemented()
167
169 self._not_implemented()
170
171 - def startup(self, minimized, nosplash):
172 self._not_implemented()
173
175 self._not_implemented()
176
178 self._not_implemented()
179
180 - def security_context_enabled(self, context):
181 self._not_implemented()
182
183 - def enable_security_context(self, context):
184 self._not_implemented()
185
188
189
191 """Converts a timeout expressed in milliseconds or seconds into a timeout expressed
192 in seconds using a floating point number.
193
194 :Parameters:
195 timeout : int, long or float
196 The input timeout. Assumed to be expressed in number of
197 milliseconds if the type is int or long. For float, assumed
198 to be a number of seconds (or fractions thereof).
199
200 :return: The timeout expressed in number of seconds (or fractions thereof).
201 :rtype: float
202 """
203 if isinstance(timeout, float):
204 return timeout
205 return timeout / 1000.0
206
207
209 """Convinient function called after popping all options from a dictionary.
210 If there are any items left, a TypeError exception is raised listing all
211 unexpected keys in the error message.
212 """
213 if opts:
214 raise TypeError('Unexpected option(s): %s' % ', '.join(opts.keys()))
215
216
217
218 if getattr(sys, 'skype4py_setup', False):
219
220 SkypeAPI = lambda **Options: None
221 platform = ''
222 elif sys.platform.startswith('win'):
223 from windows import SkypeAPI
224 platform = 'windows'
225 elif sys.platform == 'darwin':
226 from darwin import SkypeAPI
227 platform = 'darwin'
228 else:
229 from posix import SkypeAPI
230 platform = 'posix'
231
232
233
234
235
236
237
238
239
240
241