Package Skype4Py :: Module conversion
[frames] | no frames]

Source Code for Module Skype4Py.conversion

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