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

Source Code for Module Skype4Py.sms

  1  """Short messaging system. 
  2  """ 
  3  __docformat__ = 'restructuredtext en' 
  4   
  5   
  6  from utils import * 
  7   
  8   
9 -class SmsMessage(Cached):
10 """Represents an SMS message. 11 """ 12 _ValidateHandle = int 13
14 - def __repr__(self):
15 return Cached.__repr__(self, 'Id')
16
17 - def _Alter(self, AlterName, Args=None):
18 return self._Owner._Alter('SMS', self.Id, AlterName, Args)
19
20 - def _Init(self):
21 self._MakeOwner()
22
23 - def _Property(self, PropName, Set=None, Cache=True):
24 return self._Owner._Property('SMS', self.Id, PropName, Set, Cache)
25
26 - def Delete(self):
27 """Deletes this SMS message. 28 """ 29 self._Owner._DoCommand('DELETE SMS %s' % self.Id)
30
31 - def MarkAsSeen(self):
32 """Marks this SMS message as seen. 33 """ 34 self._Owner._DoCommand('SET SMS %s SEEN' % self.Id)
35
36 - def Send(self):
37 """Sends this SMS message. 38 """ 39 self._Alter('SEND')
40
41 - def _GetBody(self):
42 return self._Property('BODY')
43
44 - def _SetBody(self, Value):
45 self._Property('BODY', Value)
46 47 Body = property(_GetBody, _SetBody, 48 doc="""Text of this SMS message. 49 50 :type: unicode 51 """) 52
53 - def _GetChunks(self):
54 return SmsChunkCollection(self, xrange(int(chop(self._Property('CHUNKING', Cache=False))[0])))
55 56 Chunks = property(_GetChunks, 57 doc="""Chunks of this SMS message. More than one if this is a multi-part message. 58 59 :type: `SmsChunkCollection` 60 """) 61
62 - def _GetDatetime(self):
63 from datetime import datetime 64 return datetime.fromtimestamp(self.Timestamp)
65 66 Datetime = property(_GetDatetime, 67 doc="""Timestamp of this SMS message as datetime object. 68 69 :type: datetime.datetime 70 """) 71
72 - def _GetFailureReason(self):
73 return str(self._Property('FAILUREREASON'))
74 75 FailureReason = property(_GetFailureReason, 76 doc="""Reason an SMS message failed. Read this if `Status` == `enums.smsMessageStatusFailed`. 77 78 :type: `enums`.smsFailureReason* 79 """) 80
81 - def _GetId(self):
82 return self._Handle
83 84 Id = property(_GetId, 85 doc="""Unique SMS message Id. 86 87 :type: int 88 """) 89
90 - def _GetIsFailedUnseen(self):
91 return (self._Property('IS_FAILED_UNSEEN') == 'TRUE')
92 93 IsFailedUnseen = property(_GetIsFailedUnseen, 94 doc="""Tells if a failed SMS message was unseen. 95 96 :type: bool 97 """) 98
99 - def _GetPrice(self):
100 return int(self._Property('PRICE'))
101 102 Price = property(_GetPrice, 103 doc="""SMS price. Expressed using `PricePrecision`. For a value expressed using `PriceCurrency`, use `PriceValue`. 104 105 :type: int 106 107 :see: `PriceCurrency`, `PricePrecision`, `PriceToText`, `PriceValue` 108 """) 109
110 - def _GetPriceCurrency(self):
111 return self._Property('PRICE_CURRENCY')
112 113 PriceCurrency = property(_GetPriceCurrency, 114 doc="""SMS price currency. 115 116 :type: unicode 117 118 :see: `Price`, `PricePrecision`, `PriceToText`, `PriceValue` 119 """) 120
121 - def _GetPricePrecision(self):
122 return int(self._Property('PRICE_PRECISION'))
123 124 PricePrecision = property(_GetPricePrecision, 125 doc="""SMS price precision. 126 127 :type: int 128 129 :see: `Price`, `PriceCurrency`, `PriceToText`, `PriceValue` 130 """) 131
132 - def _GetPriceToText(self):
133 return (u'%s %.3f' % (self.PriceCurrency, self.PriceValue)).strip()
134 135 PriceToText = property(_GetPriceToText, 136 doc="""SMS price as properly formatted text with currency. 137 138 :type: unicode 139 140 :see: `Price`, `PriceCurrency`, `PricePrecision`, `PriceValue` 141 """) 142
143 - def _GetPriceValue(self):
144 if self.Price < 0: 145 return 0.0 146 return float(self.Price) / (10 ** self.PricePrecision)
147 148 PriceValue = property(_GetPriceValue, 149 doc="""SMS price. Expressed in `PriceCurrency`. 150 151 :type: float 152 153 :see: `Price`, `PriceCurrency`, `PricePrecision`, `PriceToText` 154 """) 155
156 - def _GetReplyToNumber(self):
157 return str(self._Property('REPLY_TO_NUMBER'))
158
159 - def _SetReplyToNumber(self, Value):
160 self._Property('REPLY_TO_NUMBER', Value)
161 162 ReplyToNumber = property(_GetReplyToNumber, _SetReplyToNumber, 163 doc="""Reply-to number for this SMS message. 164 165 :type: str 166 """) 167
168 - def _SetSeen(self, Value):
169 from warnings import warn 170 warn('SmsMessage.Seen = x: Use SmsMessage.MarkAsSeen() instead.', DeprecationWarning, stacklevel=2) 171 if Value: 172 self.MarkAsSeen() 173 else: 174 raise SkypeError(0, 'Seen can only be set to True')
175 176 Seen = property(fset=_SetSeen, 177 doc="""Set the read status of the SMS message. Accepts only True value. 178 179 :type: bool 180 181 :deprecated: Extremely unpythonic, use `MarkAsSeen` instead. 182 """) 183
184 - def _GetStatus(self):
185 return str(self._Property('STATUS'))
186 187 Status = property(_GetStatus, 188 doc="""SMS message status. 189 190 :type: `enums`.smsMessageStatus* 191 """) 192
193 - def _GetTargetNumbers(self):
194 return tuple(split(self._Property('TARGET_NUMBERS'), ', '))
195
196 - def _SetTargetNumbers(self, Value):
197 self._Property('TARGET_NUMBERS', ', '.join(Value))
198 199 TargetNumbers = property(_GetTargetNumbers, _SetTargetNumbers, 200 doc="""Target phone numbers. 201 202 :type: tuple of str 203 """) 204
205 - def _GetTargets(self):
206 return SmsTargetCollection(self, split(self._Property('TARGET_NUMBERS'), ', '))
207 208 Targets = property(_GetTargets, 209 doc="""Target objects. 210 211 :type: `SmsTargetCollection` 212 """) 213
214 - def _GetTimestamp(self):
215 return float(self._Property('TIMESTAMP'))
216 217 Timestamp = property(_GetTimestamp, 218 doc="""Timestamp of this SMS message. 219 220 :type: float 221 222 :see: `Datetime` 223 """) 224
225 - def _GetType(self):
226 return str(self._Property('TYPE'))
227 228 Type = property(_GetType, 229 doc="""SMS message type 230 231 :type: `enums`.smsMessageType* 232 """)
233 234
235 -class SmsMessageCollection(CachedCollection):
236 _CachedType = SmsMessage
237 238
239 -class SmsChunk(Cached):
240 """Represents a single chunk of a multi-part SMS message. 241 """ 242 _ValidateHandle = int 243
244 - def __repr__(self):
245 return Cached.__repr__(self, 'Id', 'Message')
246
247 - def _GetCharactersLeft(self):
248 count, left = map(int, chop(self.Message._Property('CHUNKING', Cache=False))) 249 if self.Id == count - 1: 250 return left 251 return 0
252 253 CharactersLeft = property(_GetCharactersLeft, 254 doc="""CharactersLeft. 255 256 :type: int 257 """) 258
259 - def _GetId(self):
260 return self._Handle
261 262 Id = property(_GetId, 263 doc="""SMS chunk Id. 264 265 :type: int 266 """) 267
268 - def _GetMessage(self):
269 return self._Owner
270 271 Message = property(_GetMessage, 272 doc="""SMS message associated with this chunk. 273 274 :type: `SmsMessage` 275 """) 276
277 - def _GetText(self):
278 return self.Message._Property('CHUNK %s' % self.Id)
279 280 Text = property(_GetText, 281 doc="""Text (body) of this SMS chunk. 282 283 :type: unicode 284 """)
285 286
287 -class SmsChunkCollection(CachedCollection):
288 _CachedType = SmsChunk
289 290
291 -class SmsTarget(Cached):
292 """Represents a single target of a multi-target SMS message. 293 """ 294 _ValidateHandle = str 295
296 - def __repr__(self):
297 return Cached.__repr__(self, 'Number', 'Message')
298
299 - def _GetMessage(self):
300 return self._Owner
301 302 Message = property(_GetMessage, 303 doc="""An SMS message object this target refers to. 304 305 :type: `SmsMessage` 306 """) 307
308 - def _GetNumber(self):
309 return self._Handle
310 311 Number = property(_GetNumber, 312 doc="""Target phone number. 313 314 :type: str 315 """) 316
317 - def _GetStatus(self):
318 for t in split(self.Message._Property('TARGET_STATUSES'), ', '): 319 number, status = t.split('=') 320 if number == self.Number: 321 return str(status)
322 323 Status = property(_GetStatus, 324 doc="""Status of this target. 325 326 :type: `enums`.smsTargetStatus* 327 """)
328 329
330 -class SmsTargetCollection(CachedCollection):
331 _CachedType = SmsTarget
332