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