1 '''Short messaging to cell phones.
2 '''
3
4 from utils import *
5
6
8 '''Represents a single chunk of a multi-part SMS message.
9 '''
10
13
14 - def _Init(self, Id_Message):
18
20 count, left = map(int, chop(self._Message._Property('CHUNKING', Cache=False)))
21 if self._Id == count - 1:
22 return left
23 return 0
24
25 CharactersLeft = property(_GetCharactersLeft,
26 doc='''CharactersLeft.
27
28 @type: int
29 ''')
30
33
34 Id = property(_GetId,
35 doc='''SMS chunk Id.
36
37 @type: int
38 ''')
39
42
43 Message = property(_GetMessage,
44 doc='''SMS message associated with this chunk.
45
46 @type: L{ISmsMessage}
47 ''')
48
50 return self._Message._Property('CHUNK %s' % self._Id)
51
52 Text = property(_GetText,
53 doc='''Text (body) of this SMS chunk.
54
55 @type: unicode
56 ''')
57
58
60 '''Represents an SMS message.
61 '''
62
65
66 - def _Alter(self, AlterName, Args=None):
67 return self._Skype._Alter('SMS', self._Id, AlterName, Args)
68
69 - def _Init(self, Id, Skype):
70 self._Id = int(Id)
71 self._Skype = Skype
72
73 - def _Property(self, PropName, Set=None, Cache=True):
74 return self._Skype._Property('SMS', self._Id, PropName, Set, Cache)
75
77 '''Deletes this SMS message.
78 '''
79 self._Skype._DoCommand('DELETE SMS %s' % self._Id)
80
82 '''Sends this SMS message.
83 '''
84 self._Alter('SEND')
85
87 return self._Property('BODY')
88
89 - def _SetBody(self, value):
90 self._Property('BODY', value)
91
92 Body = property(_GetBody, _SetBody,
93 doc='''Text of this SMS message.
94
95 @type: unicode
96 ''')
97
99 return tuple([ISmsChunk((x, self)) for x in range(int(chop(self._Property('CHUNKING', Cache=False))[0]))])
100
101 Chunks = property(_GetChunks,
102 doc='''Chunks of this SMS message. More than one if this is a multi-part message.
103
104 @type: tuple of L{ISmsChunk}
105 ''')
106
108 from datetime import datetime
109 return datetime.fromtimestamp(self.Timestamp)
110
111 Datetime = property(_GetDatetime,
112 doc='''Timestamp of this SMS message as datetime object.
113
114 @type: datetime.datetime
115 ''')
116
118 return self._Property('FAILUREREASON')
119
120 FailureReason = property(_GetFailureReason,
121 doc='''Reason an SMS message failed. Read this if L{Status} == L{smsMessageStatusFailed<enums.smsMessageStatusFailed>}.
122
123 @type: L{SMS failure reason<enums.smsFailureReasonUnknown>}
124 ''')
125
128
129 Id = property(_GetId,
130 doc='''Unique SMS message Id.
131
132 @type: int
133 ''')
134
136 return self._Property('IS_FAILED_UNSEEN') == 'TRUE'
137
138 IsFailedUnseen = property(_GetIsFailedUnseen,
139 doc='''Tells if a failed SMS message was unseen.
140
141 @type: bool
142 ''')
143
145 return int(self._Property('PRICE'))
146
147 Price = property(_GetPrice,
148 doc='''SMS price. Expressed using L{PricePrecision}. For a value expressed using L{PriceCurrency}, use L{PriceValue}.
149
150 @type: int
151 @see: L{PriceCurrency}, L{PricePrecision}, L{PriceToText}, L{PriceValue}
152 ''')
153
155 return self._Property('PRICE_CURRENCY')
156
157 PriceCurrency = property(_GetPriceCurrency,
158 doc='''SMS price currency.
159
160 @type: unicode
161 @see: L{Price}, L{PricePrecision}, L{PriceToText}, L{PriceValue}
162 ''')
163
165 return int(self._Property('PRICE_PRECISION'))
166
167 PricePrecision = property(_GetPricePrecision,
168 doc='''SMS price precision.
169
170 @type: int
171 @see: L{Price}, L{PriceCurrency}, L{PriceToText}, L{PriceValue}
172 ''')
173
174 - def _GetPriceToText(self):
175 return (u'%s %.3f' % (self.PriceCurrency, self.PriceValue)).strip()
176
177 PriceToText = property(_GetPriceToText,
178 doc='''SMS price as properly formatted text with currency.
179
180 @type: unicode
181 @see: L{Price}, L{PriceCurrency}, L{PricePrecision}, L{PriceValue}
182 ''')
183
188
189 PriceValue = property(_GetPriceValue,
190 doc='''SMS price. Expressed in L{PriceCurrency}.
191
192 @type: float
193 @see: L{Price}, L{PriceCurrency}, L{PricePrecision}, L{PriceToText}
194 ''')
195
197 return self._Property('REPLY_TO_NUMBER')
198
200 self._Property('REPLY_TO_NUMBER', value)
201
202 ReplyToNumber = property(_GetReplyToNumber, _SetReplyToNumber,
203 doc='''Reply-to number for this SMS message.
204
205 @type: unicode
206 ''')
207
209 self._Property('SEEN', cndexp(value, 'TRUE', 'FALSE'))
210
211 Seen = property(fset=_SetSeen,
212 doc='''Read status of the SMS message.
213
214 @type: bool
215 ''')
216
218 return self._Property('STATUS')
219
220 Status = property(_GetStatus,
221 doc='''SMS message status.
222
223 @type: L{SMS message status<enums.smsMessageStatusUnknown>}
224 ''')
225
227 return tuple(esplit(self._Property('TARGET_NUMBERS'), ', '))
228
230 self._Property('TARGET_NUMBERS', ', '.join(value))
231
232 TargetNumbers = property(_GetTargetNumbers, _SetTargetNumbers,
233 doc='''Target phone numbers.
234
235 @type: tuple of unicode
236 ''')
237
239 return tuple([ISmsTarget((x, self)) for x in esplit(self._Property('TARGET_NUMBERS'), ', ')])
240
241 Targets = property(_GetTargets,
242 doc='''Target objects.
243
244 @type: tuple of L{ISmsTarget}
245 ''')
246
248 return float(self._Property('TIMESTAMP'))
249
250 Timestamp = property(_GetTimestamp,
251 doc='''Timestamp of this SMS message.
252
253 @type: float
254 @see: L{Datetime}
255 ''')
256
258 return self._Property('TYPE')
259
260 Type = property(_GetType,
261 doc='''SMS message type
262
263 @type: L{SMS message type<enums.smsMessageTypeUnknown>}
264 ''')
265
266
268 '''Represents a single target of a multi-target SMS message.
269 '''
270
273
274 - def _Init(self, Number_Message):
278
281
282 Message = property(_GetMessage,
283 doc='''An SMS message object this target refers to.
284
285 @type: L{ISmsMessage}
286 ''')
287
290
291 Number = property(_GetNumber,
292 doc='''Target phone number.
293
294 @type: unicode
295 ''')
296
298 for t in esplit(self._Message._Property('TARGET_STATUSES'), ', '):
299 number, status = t.split('=')
300 if number == self._Number:
301 return status
302
303 Status = property(_GetStatus,
304 doc='''Status of this target.
305
306 @type: L{SMS target status<enums.smsTargetStatusUnknown>}
307 ''')
308