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

Source Code for Module Skype4Py.user

  1  """Users and groups. 
  2  """ 
  3  __docformat__ = 'restructuredtext en' 
  4   
  5   
  6  from utils import * 
  7  from enums import * 
  8   
  9   
10 -class User(Cached):
11 """Represents a Skype user. 12 """ 13 _ValidateHandle = str 14
15 - def __repr__(self):
16 return Cached.__repr__(self, 'Handle')
17
18 - def _Property(self, PropName, Set=None, Cache=True):
19 return self._Owner._Property('USER', self.Handle, PropName, Set, Cache)
20
21 - def SaveAvatarToFile(self, Filename, AvatarId=1):
22 """Saves user avatar to a file. 23 24 :Parameters: 25 Filename : str 26 Destination path. 27 AvatarId : int 28 Avatar Id. 29 """ 30 s = 'USER %s AVATAR %s %s' % (self.Handle, AvatarId, path2unicode(Filename)) 31 self._Owner._DoCommand('GET %s' % s, s)
32
33 - def SetBuddyStatusPendingAuthorization(self, Text=u''):
34 """Sets the BuddyStaus property to `enums.budPendingAuthorization` 35 additionally specifying the authorization text. 36 37 :Parameters: 38 Text : unicode 39 The authorization text. 40 41 :see: `BuddyStatus` 42 """ 43 self._Property('BUDDYSTATUS', '%d %s' % (budPendingAuthorization, tounicode(Text)), Cache=False)
44
45 - def _GetAbout(self):
46 return self._Property('ABOUT')
47 48 About = property(_GetAbout, 49 doc="""About text of the user. 50 51 :type: unicode 52 """) 53
54 - def _GetAliases(self):
55 return split(self._Property('ALIASES'))
56 57 Aliases = property(_GetAliases, 58 doc="""Aliases of the user. 59 60 :type: list of str 61 """) 62
63 - def _GetBirthday(self):
64 value = self._Property('BIRTHDAY') 65 if len(value) == 8: 66 from datetime import date 67 from time import strptime 68 return date(*strptime(value, '%Y%m%d')[:3])
69 70 Birthday = property(_GetBirthday, 71 doc="""Birthday of the user. None if not set. 72 73 :type: datetime.date or None 74 """) 75
76 - def _GetBuddyStatus(self):
77 return int(self._Property('BUDDYSTATUS'))
78
79 - def _SetBuddyStatus(self, Value):
80 self._Property('BUDDYSTATUS', int(Value), Cache=False)
81 82 BuddyStatus = property(_GetBuddyStatus, _SetBuddyStatus, 83 doc="""Buddy status of the user. 84 85 :type: `enums`.bud* 86 """) 87
88 - def _GetCanLeaveVoicemail(self):
89 return (self._Property('CAN_LEAVE_VM') == 'TRUE')
90 91 CanLeaveVoicemail = property(_GetCanLeaveVoicemail, 92 doc="""Tells if it is possible to send voicemail to the user. 93 94 :type: bool 95 """) 96
97 - def _GetCity(self):
98 return self._Property('CITY')
99 100 City = property(_GetCity, 101 doc="""City of the user. 102 103 :type: unicode 104 """) 105
106 - def _GetCountry(self):
107 value = self._Property('COUNTRY') 108 if value: 109 if self._Owner.Protocol >= 4: 110 value = chop(value)[-1] 111 return value
112 113 Country = property(_GetCountry, 114 doc="""Country of the user. 115 116 :type: unicode 117 """) 118
119 - def _GetCountryCode(self):
120 if self._Owner.Protocol < 4: 121 return '' 122 value = self._Property('COUNTRY') 123 if value: 124 value = chop(value)[0] 125 return str(value)
126 127 CountryCode = property(_GetCountryCode, 128 doc="""ISO country code of the user. 129 130 :type: str 131 """) 132
133 - def _GetDisplayName(self):
134 return self._Property('DISPLAYNAME')
135
136 - def _SetDisplayName(self, Value):
137 self._Property('DISPLAYNAME', Value)
138 139 DisplayName = property(_GetDisplayName, _SetDisplayName, 140 doc="""Display name of the user. 141 142 :type: unicode 143 """) 144
145 - def _GetHandle(self):
146 return self._Handle
147 148 Handle = property(_GetHandle, 149 doc="""Skypename of the user. 150 151 :type: str 152 """) 153
154 - def _GetFullName(self):
155 return self._Property('FULLNAME')
156 157 FullName = property(_GetFullName, 158 doc="""Full name of the user. 159 160 :type: unicode 161 """) 162
163 - def _GetHasCallEquipment(self):
164 return self._Property('HASCALLEQUIPMENT') == 'TRUE'
165 166 HasCallEquipment = property(_GetHasCallEquipment, 167 doc="""Tells if the user has call equipment. 168 169 :type: bool 170 """) 171
172 - def _GetHomepage(self):
173 return self._Property('HOMEPAGE')
174 175 Homepage = property(_GetHomepage, 176 doc="""Homepage URL of the user. 177 178 :type: unicode 179 """) 180
181 - def _GetIsAuthorized(self):
182 return (self._Property('ISAUTHORIZED') == 'TRUE')
183
184 - def _SetIsAuthorized(self, Value):
185 self._Property('ISAUTHORIZED', cndexp(Value, 'TRUE', 'FALSE'))
186 187 IsAuthorized = property(_GetIsAuthorized, _SetIsAuthorized, 188 doc="""Tells if the user is authorized to contact us. 189 190 :type: bool 191 """) 192
193 - def _GetIsBlocked(self):
194 return (self._Property('ISBLOCKED') == 'TRUE')
195
196 - def _SetIsBlocked(self, Value):
197 self._Property('ISBLOCKED', cndexp(Value, 'TRUE', 'FALSE'))
198 199 IsBlocked = property(_GetIsBlocked, _SetIsBlocked, 200 doc="""Tells whether this user is blocked or not. 201 202 :type: bool 203 """) 204
205 - def _GetIsCallForwardActive(self):
206 return (self._Property('IS_CF_ACTIVE') == 'TRUE')
207 208 IsCallForwardActive = property(_GetIsCallForwardActive, 209 doc="""Tells whether the user has Call Forwarding activated or not. 210 211 :type: bool 212 """) 213
214 - def _GetIsSkypeOutContact(self):
215 return (self.OnlineStatus == olsSkypeOut)
216 217 IsSkypeOutContact = property(_GetIsSkypeOutContact, 218 doc="""Tells whether a user is a SkypeOut contact. 219 220 :type: bool 221 """) 222
223 - def _GetIsVideoCapable(self):
224 return (self._Property('IS_VIDEO_CAPABLE') == 'TRUE')
225 226 IsVideoCapable = property(_GetIsVideoCapable, 227 doc="""Tells if the user has video capability. 228 229 :type: bool 230 """) 231
232 - def _GetIsVoicemailCapable(self):
233 return (self._Property('IS_VOICEMAIL_CAPABLE') == 'TRUE')
234 235 IsVoicemailCapable = property(_GetIsVoicemailCapable, 236 doc="""Tells if the user has voicemail capability. 237 238 :type: bool 239 """) 240
241 - def _GetLanguage(self):
242 value = self._Property('LANGUAGE') 243 if value: 244 if self._Owner.Protocol >= 4: 245 value = chop(value)[-1] 246 return value
247 248 Language = property(_GetLanguage, 249 doc="""The language of the user. 250 251 :type: unicode 252 """) 253
254 - def _GetLanguageCode(self):
255 if self._Owner.Protocol < 4: 256 return u'' 257 value = self._Property('LANGUAGE') 258 if value: 259 value = chop(value)[0] 260 return str(value)
261 262 LanguageCode = property(_GetLanguageCode, 263 doc="""The ISO language code of the user. 264 265 :type: str 266 """) 267
268 - def _GetLastOnline(self):
269 return float(self._Property('LASTONLINETIMESTAMP'))
270 271 LastOnline = property(_GetLastOnline, 272 doc="""The time when a user was last online as a timestamp. 273 274 :type: float 275 276 :see: `LastOnlineDatetime` 277 """) 278
279 - def _GetLastOnlineDatetime(self):
280 from datetime import datetime 281 return datetime.fromtimestamp(self.LastOnline)
282 283 LastOnlineDatetime = property(_GetLastOnlineDatetime, 284 doc="""The time when a user was last online as a datetime. 285 286 :type: datetime.datetime 287 288 :see: `LastOnline` 289 """) 290
291 - def _GetMoodText(self):
292 return self._Property('MOOD_TEXT')
293 294 MoodText = property(_GetMoodText, 295 doc="""Mood text of the user. 296 297 :type: unicode 298 """) 299
300 - def _GetNumberOfAuthBuddies(self):
301 return int(self._Property('NROF_AUTHED_BUDDIES'))
302 303 NumberOfAuthBuddies = property(_GetNumberOfAuthBuddies, 304 doc="""Number of authenticated buddies in user's contact list. 305 306 :type: int 307 """) 308
309 - def _GetOnlineStatus(self):
310 return str(self._Property('ONLINESTATUS'))
311 312 OnlineStatus = property(_GetOnlineStatus, 313 doc="""Online status of the user. 314 315 :type: `enums`.ols* 316 """) 317
318 - def _GetPhoneHome(self):
319 return self._Property('PHONE_HOME')
320 321 PhoneHome = property(_GetPhoneHome, 322 doc="""Home telephone number of the user. 323 324 :type: unicode 325 """) 326
327 - def _GetPhoneMobile(self):
328 return self._Property('PHONE_MOBILE')
329 330 PhoneMobile = property(_GetPhoneMobile, 331 doc="""Mobile telephone number of the user. 332 333 :type: unicode 334 """) 335
336 - def _GetPhoneOffice(self):
337 return self._Property('PHONE_OFFICE')
338 339 PhoneOffice = property(_GetPhoneOffice, 340 doc="""Office telephone number of the user. 341 342 :type: unicode 343 """) 344
345 - def _GetProvince(self):
346 return self._Property('PROVINCE')
347 348 Province = property(_GetProvince, 349 doc="""Province of the user. 350 351 :type: unicode 352 """) 353
354 - def _GetReceivedAuthRequest(self):
355 return self._Property('RECEIVEDAUTHREQUEST')
356 357 ReceivedAuthRequest = property(_GetReceivedAuthRequest, 358 doc="""Text message for authorization request. Available only when user asks for authorization. 359 360 :type: unicode 361 """) 362
363 - def _GetRichMoodText(self):
364 return self._Property('RICH_MOOD_TEXT')
365 366 RichMoodText = property(_GetRichMoodText, 367 doc="""Advanced version of `MoodText`. 368 369 :type: unicode 370 371 :see: https://developer.skype.com/Docs/ApiDoc/SET_PROFILE_RICH_MOOD_TEXT 372 """) 373
374 - def _GetSex(self):
375 return str(self._Property('SEX'))
376 377 Sex = property(_GetSex, 378 doc="""Sex of the user. 379 380 :type: `enums`.usex* 381 """) 382
383 - def _GetSpeedDial(self):
384 return self._Property('SPEEDDIAL')
385
386 - def _SetSpeedDial(self, Value):
387 self._Property('SPEEDDIAL', Value)
388 389 SpeedDial = property(_GetSpeedDial, _SetSpeedDial, 390 doc="""Speed-dial code assigned to the user. 391 392 :type: unicode 393 """) 394
395 - def _GetTimezone(self):
396 return int(self._Property('TIMEZONE'))
397 398 Timezone = property(_GetTimezone, 399 doc="""Timezone of the user in minutes from GMT. 400 401 :type: int 402 """)
403 404
405 -class UserCollection(CachedCollection):
406 _CachedType = User
407 408
409 -class Group(Cached):
410 """Represents a group of Skype users. 411 """ 412 _ValidateHandle = int 413
414 - def __repr__(self):
415 return Cached.__repr__(self, 'Id')
416
417 - def _Alter(self, AlterName, Args=None):
418 return self._Owner._Alter('GROUP', self.Id, AlterName, Args)
419
420 - def _Property(self, PropName, Value=None, Cache=True):
421 return self._Owner._Property('GROUP', self.Id, PropName, Value, Cache)
422
423 - def Accept(self):
424 """Accepts an invitation to join a shared contact group. 425 """ 426 self._Alter('ACCEPT')
427
428 - def AddUser(self, Username):
429 """Adds new a user to the group. 430 431 :Parameters: 432 Username : str 433 Skypename of the new user. 434 """ 435 self._Alter('ADDUSER', Username)
436
437 - def Decline(self):
438 """Declines an invitation to join a shared contact group. 439 """ 440 self._Alter('DECLINE')
441
442 - def RemoveUser(self, Username):
443 """Removes a user from the group. 444 445 :Parameters: 446 Username : str 447 Skypename of the user. 448 """ 449 self._Alter('REMOVEUSER', Username)
450
451 - def Share(self, MessageText=''):
452 """Shares a contact group. 453 454 :Parameters: 455 MessageText : unicode 456 Message text for group members. 457 """ 458 self._Alter('SHARE', MessageText)
459
460 - def _GetCustomGroupId(self):
461 return str(self._Property('CUSTOM_GROUP_ID'))
462 463 CustomGroupId = property(_GetCustomGroupId, 464 doc="""Persistent group ID. The custom group ID is a persistent value that does not change. 465 466 :type: str 467 """) 468
469 - def _GetDisplayName(self):
470 return self._Property('DISPLAYNAME')
471
472 - def _SetDisplayName(self, Value):
473 self._Property('DISPLAYNAME', Value)
474 475 DisplayName = property(_GetDisplayName, _SetDisplayName, 476 doc="""Display name of the group. 477 478 :type: unicode 479 """) 480
481 - def _GetId(self):
482 return self._Handle
483 484 Id = property(_GetId, 485 doc="""Group Id. 486 487 :type: int 488 """) 489
490 - def _GetIsExpanded(self):
491 return self._Property('EXPANDED') == 'TRUE'
492 493 IsExpanded = property(_GetIsExpanded, 494 doc="""Tells if the group is expanded in the client. 495 496 :type: bool 497 """) 498
499 - def _GetIsVisible(self):
500 return self._Property('VISIBLE') == 'TRUE'
501 502 IsVisible = property(_GetIsVisible, 503 doc="""Tells if the group is visible in the client. 504 505 :type: bool 506 """) 507
508 - def _GetOnlineUsers(self):
509 return UserCollection(self._Owner, (x.Handle for x in self.Users if x.OnlineStatus == olsOnline))
510 511 OnlineUsers = property(_GetOnlineUsers, 512 doc="""Users of the group that are online 513 514 :type: `UserCollection` 515 """) 516
517 - def _GetType(self):
518 return str(self._Property('TYPE'))
519 520 Type = property(_GetType, 521 doc="""Group type. 522 523 :type: `enums`.grp* 524 """) 525
526 - def _GetUsers(self):
527 return UserCollection(self._Owner, split(self._Property('USERS', Cache=False), ', '))
528 529 Users = property(_GetUsers, 530 doc="""Users in this group. 531 532 :type: `UserCollection` 533 """)
534 535
536 -class GroupCollection(CachedCollection):
537 _CachedType = Group
538