1 '''Conversion between constants and text.
2 '''
3
4 import enums
5 from errors import *
6 import os
7
8
9
10
11
12
13
14
15
16 if False:
17 import Languages
18
19
21 '''Allows conversion between constants and text. Access using L{ISkype.Convert<skype.ISkype.Convert>}.
22 '''
23
25 '''__init__.
26
27 @param Skype: Skype object.
28 @type Skype: L{ISkype}
29 '''
30 self._Language = u''
31 self._Module = None
32 self._SetLanguage('en')
33
34 - def _TextTo(self, prefix, value):
35 enum = [z for z in [(y, getattr(enums, y)) for y in [x for x in dir(enums) if x.startswith(prefix)]] if z[1] == value]
36 if enum:
37 return str(value)
38 raise ValueError('Bad text')
39
40 - def _ToText(self, prefix, value):
41 enum = [z for z in [(y, getattr(enums, y)) for y in [x for x in dir(enums) if x.startswith(prefix)]] if z[1] == value]
42 if enum:
43 try:
44 return unicode(getattr(self._Module, enum[0][0]))
45 except AttributeError:
46 pass
47 raise ValueError('Bad identifier')
48
49 - def AttachmentStatusToText(self, Status):
50 '''Returns attachment status as text.
51
52 @param Status: Attachment status.
53 @type Status: L{Attachment status<enums.apiAttachUnknown>}
54 @return: Text describing the attachment status.
55 @rtype: unicode
56 '''
57 return self._ToText('api', Status)
58
59 - def BuddyStatusToText(self, Status):
60 '''Returns buddy status as text.
61
62 @param Status: Buddy status.
63 @type Status: L{Buddy status<enums.budUnknown>}
64 @return: Text describing the buddy status.
65 @rtype: unicode
66 '''
67 return self._ToText('bud', Status)
68
70 '''Returns failure reason as text.
71
72 @param Reason: Call failure reason.
73 @type Reason: L{Call failure reason<enums.cfrUnknown>}
74 @return: Text describing the call failure reason.
75 @rtype: unicode
76 '''
77 return self._ToText('cfr', Reason)
78
79 - def CallStatusToText(self, Status):
80 '''Returns call status as text.
81
82 @param Status: Call status.
83 @type Status: L{Call status<enums.clsUnknown>}
84 @return: Text describing the call status.
85 @rtype: unicode
86 '''
87 return self._ToText('cls', Status)
88
89 - def CallTypeToText(self, Type):
90 '''Returns call type as text.
91
92 @param Type: Call type.
93 @type Type: L{Call type<enums.cltUnknown>}
94 @return: Text describing the call type.
95 @rtype: unicode
96 '''
97 return self._ToText('clt', Type)
98
100 '''Returns call video send status as text.
101
102 @param Status: Call video send status.
103 @type Status: L{Call video send status<enums.vssUnknown>}
104 @return: Text describing the call video send status.
105 @rtype: unicode
106 '''
107 return self._ToText('vss', Status)
108
109 - def CallVideoStatusToText(self, Status):
110 '''Returns call video status as text.
111
112 @param Status: Call video status.
113 @type Status: L{Call video status<enums.cvsUnknown>}
114 @return: Text describing the call video status.
115 @rtype: unicode
116 '''
117 return self._ToText('cvs', Status)
118
119 - def ChatLeaveReasonToText(self, Reason):
120 '''Returns leave reason as text.
121
122 @param Reason: Chat leave reason.
123 @type Reason: L{Chat leave reason<enums.leaUnknown>}
124 @return: Text describing the chat leave reason.
125 @rtype: unicode
126 '''
127 return self._ToText('lea', Reason)
128
129 - def ChatMessageStatusToText(self, Status):
130 '''Returns message status as text.
131
132 @param Status: Chat message status.
133 @type Status: L{Chat message status<enums.cmsUnknown>}
134 @return: Text describing the chat message status.
135 @rtype: unicode
136 '''
137 return self._ToText('cms', Status)
138
139 - def ChatMessageTypeToText(self, Type):
140 '''Returns message type as text.
141
142 @param Type: Chat message type.
143 @type Type: L{Chat message type<enums.cmeUnknown>}
144 @return: Text describing the chat message type.
145 @rtype: unicode
146 '''
147 return self._ToText('cme', Type)
148
149 - def ChatStatusToText(self, Status):
150 '''Returns chatr status as text.
151
152 @param Status: Chat status.
153 @type Status: L{Chat status<enums.chsUnknown>}
154 @return: Text describing the chat status.
155 @rtype: unicode
156 '''
157 return self._ToText('chs', Status)
158
159 - def ConnectionStatusToText(self, Status):
160 '''Returns connection status as text.
161
162 @param Status: Connection status.
163 @type Status: L{Connection status<enums.conUnknown>}
164 @return: Text describing the connection status.
165 @rtype: unicode
166 '''
167 return self._ToText('con', Status)
168
169 - def GroupTypeToText(self, Type):
170 '''Returns group type as text.
171
172 @param Type: Group type.
173 @type Type: L{Group type<enums.grpUnknown>}
174 @return: Text describing the group type.
175 @rtype: unicode
176 '''
177 return self._ToText('grp', Type)
178
179 - def OnlineStatusToText(self, Status):
180 '''Returns online status as text.
181
182 @param Status: Online status.
183 @type Status: L{Online status<enums.olsUnknown>}
184 @return: Text describing the online status.
185 @rtype: unicode
186 '''
187 return self._ToText('ols', Status)
188
189 - def SmsMessageStatusToText(self, Status):
190 '''Returns SMS message status as text.
191
192 @param Status: SMS message status.
193 @type Status: L{SMS message status<enums.smsMessageStatusUnknown>}
194 @return: Text describing the SMS message status.
195 @rtype: unicode
196 '''
197 return self._ToText('smsMessageStatus', Status)
198
199 - def SmsMessageTypeToText(self, Type):
200 '''Returns SMS message type as text.
201
202 @param Type: SMS message type.
203 @type Type: L{SMS message type<enums.smsMessageTypeUnknown>}
204 @return: Text describing the SMS message type.
205 @rtype: unicode
206 '''
207 return self._ToText('smsMessageType', Type)
208
209 - def SmsTargetStatusToText(self, Status):
210 '''Returns SMS target status as text.
211
212 @param Status: SMS target status.
213 @type Status: L{SMS target status<enums.smsTargetStatusUnknown>}
214 @return: Text describing the SMS target status.
215 @rtype: unicode
216 '''
217 return self._ToText('smsTargetStatus', Status)
218
220 '''Returns attachment status code.
221
222 @param Text: Text, one of 'UNKNOWN', 'SUCCESS', 'PENDING_AUTHORIZATION', 'REFUSED',
223 'NOT_AVAILABLE', 'AVAILABLE'.
224 @type Text: unicode
225 @return: Attachment status.
226 @rtype: L{Attachment status<enums.apiAttachUnknown>}
227 '''
228 conv = {'UNKNOWN': enums.apiAttachUnknown,
229 'SUCCESS': enums.apiAttachSuccess,
230 'PENDING_AUTHORIZATION': enums.apiAttachPendingAuthorization,
231 'REFUSED': enums.apiAttachRefused,
232 'NOT_AVAILABLE': enums.apiAttachNotAvailable,
233 'AVAILABLE': enums.apiAttachAvailable}
234 try:
235 return self._TextTo('api', conv[Text.upper()])
236 except KeyError:
237 raise ValueError('Bad text')
238
239 - def TextToBuddyStatus(self, Text):
240 '''Returns buddy status code.
241
242 @param Text: Text, one of 'UNKNOWN', 'NEVER_BEEN_FRIEND', 'DELETED_FRIEND',
243 'PENDING_AUTHORIZATION', 'FRIEND'.
244 @type Text: unicode
245 @return: Buddy status.
246 @rtype: L{Buddy status<enums.budUnknown>}
247 '''
248 conv = {'UNKNOWN': enums.budUnknown,
249 'NEVER_BEEN_FRIEND': enums.budNeverBeenFriend,
250 'DELETED_FRIEND': enums.budDeletedFriend,
251 'PENDING_AUTHORIZATION': enums.budPendingAuthorization,
252 'FRIEND': enums.budFriend}
253 try:
254 return self._TextTo('bud', conv[Text.upper()])
255 except KeyError:
256 raise ValueError('Bad text')
257
258 - def TextToCallStatus(self, Text):
259 '''Returns call status code.
260
261 @param Text: Text, one of L{Call status<enums.clsUnknown>}.
262 @type Text: unicode
263 @return: Call status.
264 @rtype: L{Call status<enums.clsUnknown>}
265 @note: Currently, this method only checks if the given string is one of the allowed ones
266 and returns it or raises a C{ValueError}.
267 '''
268 return self._TextTo('cls', Text)
269
270 - def TextToCallType(self, Text):
271 '''Returns call type code.
272
273 @param Text: Text, one of L{Call type<enums.cltUnknown>}.
274 @type Text: unicode
275 @return: Call type.
276 @rtype: L{Call type<enums.cltUnknown>}
277 @note: Currently, this method only checks if the given string is one of the allowed ones
278 and returns it or raises a C{ValueError}.
279 '''
280 return self._TextTo('clt', Text)
281
283 '''Returns message status code.
284
285 @param Text: Text, one of L{Chat message status<enums.cmsUnknown>}.
286 @type Text: unicode
287 @return: Chat message status.
288 @rtype: L{Chat message status<enums.cmsUnknown>}
289 @note: Currently, this method only checks if the given string is one of the allowed ones
290 and returns it or raises a C{ValueError}.
291 '''
292 return self._TextTo('cms', Text)
293
294 - def TextToChatMessageType(self, Text):
295 '''Returns message type code.
296
297 @param Text: Text, one of L{Chat message type<enums.cmeUnknown>}.
298 @type Text: unicode
299 @return: Chat message type.
300 @rtype: L{Chat message type<enums.cmeUnknown>}
301 @note: Currently, this method only checks if the given string is one of the allowed ones
302 and returns it or raises a C{ValueError}.
303 '''
304 return self._TextTo('cme', Text)
305
307 '''Retunes connection status code.
308
309 @param Text: Text, one of L{Connection status<enums.conUnknown>}.
310 @type Text: unicode
311 @return: Connection status.
312 @rtype: L{Connection status<enums.conUnknown>}
313 @note: Currently, this method only checks if the given string is one of the allowed ones
314 and returns it or raises a C{ValueError}.
315 '''
316 return self._TextTo('con', Text)
317
318 - def TextToGroupType(self, Text):
319 '''Returns group type code.
320
321 @param Text: Text, one of L{Group type<enums.grpUnknown>}.
322 @type Text: unicode
323 @return: Group type.
324 @rtype: L{Group type<enums.grpUnknown>}
325 @note: Currently, this method only checks if the given string is one of the allowed ones
326 and returns it or raises a C{ValueError}.
327 '''
328 return self._TextTo('grp', Text)
329
330 - def TextToOnlineStatus(self, Text):
331 '''Returns online status code.
332
333 @param Text: Text, one of L{Online status<enums.olsUnknown>}.
334 @type Text: unicode
335 @return: Online status.
336 @rtype: L{Online status<enums.olsUnknown>}
337 @note: Currently, this method only checks if the given string is one of the allowed ones
338 and returns it or raises a C{ValueError}.
339 '''
340 return self._TextTo('ols', Text)
341
342 - def TextToUserSex(self, Text):
343 '''Returns user sex code.
344
345 @param Text: Text, one of L{User sex<enums.usexUnknown>}.
346 @type Text: unicode
347 @return: User sex.
348 @rtype: L{User sex<enums.usexUnknown>}
349 @note: Currently, this method only checks if the given string is one of the allowed ones
350 and returns it or raises a C{ValueError}.
351 '''
352 return self._TextTo('usex', Text)
353
354 - def TextToUserStatus(self, Text):
355 '''Returns user status code.
356
357 @param Text: Text, one of L{User status<enums.cusUnknown>}.
358 @type Text: unicode
359 @return: User status.
360 @rtype: L{User status<enums.cusUnknown>}
361 @note: Currently, this method only checks if the given string is one of the allowed ones
362 and returns it or raises a C{ValueError}.
363 '''
364 return self._TextTo('cus', Text)
365
366 - def TextToVoicemailStatus(self, Text):
367 '''Returns voicemail status code.
368
369 @param Text: Text, one of L{Voicemail status<enums.vmsUnknown>}.
370 @type Text: unicode
371 @return: Voicemail status.
372 @rtype: L{Voicemail status<enums.vmsUnknown>}
373 @note: Currently, this method only checks if the given string is one of the allowed ones
374 and returns it or raises a C{ValueError}.
375 '''
376 return self._TextTo('vms', Text)
377
378 - def UserSexToText(self, Sex):
379 '''Returns user sex as text.
380
381 @param Sex: User sex.
382 @type Sex: L{User sex<enums.usexUnknown>}
383 @return: Text describing the user sex.
384 @rtype: unicode
385 '''
386 return self._ToText('usex', Sex)
387
388 - def UserStatusToText(self, Status):
389 '''Returns user status as text.
390
391 @param Status: User status.
392 @type Status: L{User status<enums.cusUnknown>}
393 @return: Text describing the user status.
394 @rtype: unicode
395 '''
396 return self._ToText('cus', Status)
397
399 '''Returns voicemail failure reason as text.
400
401 @param Reason: Voicemail failure reason.
402 @type Reason: L{Voicemail failure reason<enums.vmrUnknown>}
403 @return: Text describing the voicemail failure reason.
404 @rtype: unicode
405 '''
406 return self._ToText('vmr', Reason)
407
408 - def VoicemailStatusToText(self, Status):
409 '''Returns voicemail status as text.
410
411 @param Status: Voicemail status.
412 @type Status: L{Voicemail status<enums.vmsUnknown>}
413 @return: Text describing the voicemail status.
414 @rtype: unicode
415 '''
416 return self._ToText('vms', Status)
417
418 - def VoicemailTypeToText(self, Type):
419 '''Returns voicemail type as text.
420
421 @param Type: Voicemail type.
422 @type Type: L{Voicemail type<enums.vmtUnknown>}
423 @return: Text describing the voicemail type.
424 @rtype: unicode
425 '''
426 return self._ToText('vmt', Type)
427
429 return self._Language
430
432 try:
433 self._Module = __import__('Languages.%s' % Language, globals(), locals(), ['Languages'])
434 self._Language = unicode(Language)
435 except ImportError:
436 raise ValueError('Unknown language: %s' % Language)
437
438 Language = property(_GetLanguage, _SetLanguage,
439 doc='''Language used for all "ToText" conversions.
440
441 Currently supported languages: ar, bg, cs, cz, da, de, el, en, es, et, fi, fr, he, hu, it, ja, ko,
442 lt, lv, nl, no, pl, pp, pt, ro, ru, sv, tr, x1.
443
444 @type: unicode
445 ''')
446