Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: DBUS client to talk to ofono |
| 2 | # |
| 3 | # Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH |
| 4 | # |
| 5 | # Author: Neels Hofmeyr <neels@hofmeyr.de> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU Affero General Public License as |
| 9 | # published by the Free Software Foundation, either version 3 of the |
| 10 | # License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU Affero General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU Affero General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
Pau Espin Pedrol | 927344b | 2017-05-22 16:38:49 +0200 | [diff] [blame] | 20 | from . import log, test, util, event_loop |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 21 | |
| 22 | from pydbus import SystemBus, Variant |
| 23 | import time |
| 24 | import pprint |
| 25 | |
| 26 | from gi.repository import GLib |
| 27 | glib_main_loop = GLib.MainLoop() |
| 28 | glib_main_ctx = glib_main_loop.get_context() |
| 29 | bus = SystemBus() |
| 30 | |
Pau Espin Pedrol | 504a664 | 2017-05-04 11:38:23 +0200 | [diff] [blame] | 31 | I_MODEM = 'org.ofono.Modem' |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 32 | I_NETREG = 'org.ofono.NetworkRegistration' |
| 33 | I_SMS = 'org.ofono.MessageManager' |
| 34 | |
Neels Hofmeyr | 035cda8 | 2017-05-05 17:52:45 +0200 | [diff] [blame] | 35 | class DeferredHandling: |
| 36 | defer_queue = [] |
| 37 | |
| 38 | def __init__(self, dbus_iface, handler): |
| 39 | self.handler = handler |
Neels Hofmeyr | 47de6b0 | 2017-05-10 13:24:05 +0200 | [diff] [blame] | 40 | self.subscription_id = dbus_iface.connect(self.receive_signal) |
Neels Hofmeyr | 035cda8 | 2017-05-05 17:52:45 +0200 | [diff] [blame] | 41 | |
| 42 | def receive_signal(self, *args, **kwargs): |
| 43 | DeferredHandling.defer_queue.append((self.handler, args, kwargs)) |
| 44 | |
| 45 | @staticmethod |
| 46 | def handle_queue(): |
| 47 | while DeferredHandling.defer_queue: |
| 48 | handler, args, kwargs = DeferredHandling.defer_queue.pop(0) |
| 49 | handler(*args, **kwargs) |
| 50 | |
| 51 | def dbus_connect(dbus_iface, handler): |
| 52 | '''This function shall be used instead of directly connecting DBus signals. |
| 53 | It ensures that we don't nest a glib main loop within another, and also |
| 54 | that we receive exceptions raised within the signal handlers. This makes it |
| 55 | so that a signal handler is invoked only after the DBus polling is through |
| 56 | by enlisting signals that should be handled in the |
| 57 | DeferredHandling.defer_queue.''' |
Neels Hofmeyr | 47de6b0 | 2017-05-10 13:24:05 +0200 | [diff] [blame] | 58 | return DeferredHandling(dbus_iface, handler).subscription_id |
Neels Hofmeyr | 035cda8 | 2017-05-05 17:52:45 +0200 | [diff] [blame] | 59 | |
Pau Espin Pedrol | 927344b | 2017-05-22 16:38:49 +0200 | [diff] [blame] | 60 | def poll_glib(): |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 61 | global glib_main_ctx |
| 62 | while glib_main_ctx.pending(): |
| 63 | glib_main_ctx.iteration() |
Neels Hofmeyr | 035cda8 | 2017-05-05 17:52:45 +0200 | [diff] [blame] | 64 | DeferredHandling.handle_queue() |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 65 | |
Pau Espin Pedrol | 927344b | 2017-05-22 16:38:49 +0200 | [diff] [blame] | 66 | event_loop.register_poll_func(poll_glib) |
| 67 | |
Neels Hofmeyr | 93f5866 | 2017-05-03 16:32:16 +0200 | [diff] [blame] | 68 | def systembus_get(path): |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 69 | global bus |
| 70 | return bus.get('org.ofono', path) |
| 71 | |
| 72 | def list_modems(): |
Neels Hofmeyr | 93f5866 | 2017-05-03 16:32:16 +0200 | [diff] [blame] | 73 | root = systembus_get('/') |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 74 | return sorted(root.GetModems()) |
| 75 | |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 76 | class ModemDbusInteraction(log.Origin): |
| 77 | '''Work around inconveniences specific to pydbus and ofono. |
| 78 | ofono adds and removes DBus interfaces and notifies about them. |
| 79 | Upon changes we need a fresh pydbus object to benefit from that. |
| 80 | Watching the interfaces change is optional; be sure to call |
| 81 | watch_interfaces() if you'd like to have signals subscribed. |
| 82 | Related: https://github.com/LEW21/pydbus/issues/56 |
| 83 | ''' |
| 84 | |
| 85 | def __init__(self, modem_path): |
| 86 | self.modem_path = modem_path |
| 87 | self.set_name(self.modem_path) |
| 88 | self.set_log_category(log.C_BUS) |
| 89 | self.watch_props_subscription = None |
| 90 | self._dbus_obj = None |
| 91 | self.interfaces = set() |
| 92 | |
| 93 | # A dict listing signal handlers to connect, e.g. |
| 94 | # { I_SMS: ( ('IncomingMessage', self._on_incoming_message), ), } |
| 95 | self.required_signals = {} |
| 96 | |
| 97 | # A dict collecting subscription tokens for connected signal handlers. |
| 98 | # { I_SMS: ( token1, token2, ... ), } |
| 99 | self.connected_signals = util.listdict() |
| 100 | |
Neels Hofmeyr | 4d688c2 | 2017-05-29 04:13:58 +0200 | [diff] [blame] | 101 | def cleanup(self): |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 102 | self.unwatch_interfaces() |
| 103 | for interface_name in list(self.connected_signals.keys()): |
| 104 | self.remove_signals(interface_name) |
| 105 | |
Neels Hofmeyr | 4d688c2 | 2017-05-29 04:13:58 +0200 | [diff] [blame] | 106 | def __del__(self): |
| 107 | self.cleanup() |
| 108 | |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 109 | def get_new_dbus_obj(self): |
| 110 | return systembus_get(self.modem_path) |
| 111 | |
| 112 | def dbus_obj(self): |
| 113 | if self._dbus_obj is None: |
| 114 | self._dbus_obj = self.get_new_dbus_obj() |
| 115 | return self._dbus_obj |
| 116 | |
| 117 | def interface(self, interface_name): |
| 118 | try: |
| 119 | return self.dbus_obj()[interface_name] |
| 120 | except KeyError: |
| 121 | self.raise_exn('Modem interface is not available:', interface_name) |
| 122 | |
| 123 | def signal(self, interface_name, signal): |
| 124 | return getattr(self.interface(interface_name), signal) |
| 125 | |
| 126 | def watch_interfaces(self): |
| 127 | self.unwatch_interfaces() |
| 128 | # Note: we are watching the properties on a get_new_dbus_obj() that is |
| 129 | # separate from the one used to interact with interfaces. We need to |
| 130 | # refresh the pydbus object to interact with Interfaces that have newly |
| 131 | # appeared, but exchanging the DBus object to watch Interfaces being |
| 132 | # enabled and disabled is racy: we may skip some removals and |
| 133 | # additions. Hence do not exchange this DBus object. We don't even |
| 134 | # need to store the dbus object used for this, we will not touch it |
| 135 | # again. We only store the signal subscription. |
| 136 | self.watch_props_subscription = dbus_connect(self.get_new_dbus_obj().PropertyChanged, |
| 137 | self.on_property_change) |
| 138 | self.on_interfaces_change(self.properties().get('Interfaces')) |
| 139 | |
| 140 | def unwatch_interfaces(self): |
| 141 | if self.watch_props_subscription is None: |
| 142 | return |
| 143 | self.watch_props_subscription.disconnect() |
| 144 | self.watch_props_subscription = None |
| 145 | |
| 146 | def on_property_change(self, name, value): |
| 147 | if name == 'Interfaces': |
| 148 | self.on_interfaces_change(value) |
| 149 | |
| 150 | def on_interfaces_change(self, interfaces_now): |
| 151 | # First some logging. |
| 152 | now = set(interfaces_now) |
| 153 | additions = now - self.interfaces |
| 154 | removals = self.interfaces - now |
| 155 | self.interfaces = now |
| 156 | if not (additions or removals): |
| 157 | # nothing changed. |
| 158 | return |
| 159 | |
| 160 | if additions: |
| 161 | self.dbg('interface enabled:', ', '.join(sorted(additions))) |
| 162 | |
| 163 | if removals: |
| 164 | self.dbg('interface disabled:', ', '.join(sorted(removals))) |
| 165 | |
| 166 | # The dbus object is now stale and needs refreshing before we |
| 167 | # access the next interface function. |
| 168 | self._dbus_obj = None |
| 169 | |
| 170 | # If an interface disappeared, disconnect the signal handlers for it. |
| 171 | # Even though we're going to use a fresh dbus object for new |
| 172 | # subscriptions, we will still keep active subscriptions alive on the |
| 173 | # old dbus object which will linger, associated with the respective |
| 174 | # signal subscription. |
| 175 | for removed in removals: |
| 176 | self.remove_signals(removed) |
| 177 | |
| 178 | # Connect signals for added interfaces. |
| 179 | for interface_name in additions: |
| 180 | self.connect_signals(interface_name) |
| 181 | |
| 182 | def remove_signals(self, interface_name): |
| 183 | got = self.connected_signals.pop(interface_name, []) |
| 184 | |
| 185 | if not got: |
| 186 | return |
| 187 | |
| 188 | self.dbg('Disconnecting', len(got), 'signals for', interface_name) |
| 189 | for subscription in got: |
| 190 | subscription.disconnect() |
| 191 | |
| 192 | def connect_signals(self, interface_name): |
| 193 | # If an interface was added, it must not have existed before. For |
| 194 | # paranoia, make sure we have no handlers for those. |
| 195 | self.remove_signals(interface_name) |
| 196 | |
| 197 | want = self.required_signals.get(interface_name, []) |
| 198 | if not want: |
| 199 | return |
| 200 | |
| 201 | self.dbg('Connecting', len(want), 'signals for', interface_name) |
| 202 | for signal, cb in self.required_signals.get(interface_name, []): |
| 203 | subscription = dbus_connect(self.signal(interface_name, signal), cb) |
| 204 | self.connected_signals.add(interface_name, subscription) |
| 205 | |
| 206 | def has_interface(self, *interface_names): |
| 207 | try: |
| 208 | for interface_name in interface_names: |
| 209 | self.dbus_obj()[interface_name] |
| 210 | result = True |
| 211 | except KeyError: |
| 212 | result = False |
| 213 | self.dbg('has_interface(%s) ==' % (', '.join(interface_names)), result) |
| 214 | return result |
| 215 | |
| 216 | def properties(self, iface=I_MODEM): |
| 217 | return self.dbus_obj()[iface].GetProperties() |
| 218 | |
| 219 | def property_is(self, name, val, iface=I_MODEM): |
| 220 | is_val = self.properties(iface).get(name) |
| 221 | self.dbg(name, '==', is_val) |
| 222 | return is_val is not None and is_val == val |
| 223 | |
| 224 | def set_bool(self, name, bool_val, iface=I_MODEM): |
| 225 | # to make sure any pending signals are received before we send out more DBus requests |
| 226 | event_loop.poll() |
| 227 | |
| 228 | val = bool(bool_val) |
| 229 | self.log('Setting', name, val) |
| 230 | self.interface(iface).SetProperty(name, Variant('b', val)) |
| 231 | |
| 232 | event_loop.wait(self, self.property_is, name, bool_val) |
| 233 | |
| 234 | def set_powered(self, powered=True): |
| 235 | self.set_bool('Powered', powered) |
| 236 | |
| 237 | def set_online(self, online=True): |
| 238 | self.set_bool('Online', online) |
| 239 | |
| 240 | def is_powered(self): |
| 241 | return self.property_is('Powered', True) |
| 242 | |
| 243 | def is_online(self): |
| 244 | return self.property_is('Online', True) |
| 245 | |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 246 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 247 | |
| 248 | class Modem(log.Origin): |
| 249 | 'convenience for ofono Modem interaction' |
| 250 | msisdn = None |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 251 | sms_received_list = None |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 252 | |
| 253 | def __init__(self, conf): |
| 254 | self.conf = conf |
| 255 | self.path = conf.get('path') |
| 256 | self.set_name(self.path) |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 257 | self.set_log_category(log.C_TST) |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 258 | self.sms_received_list = [] |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 259 | self.dbus = ModemDbusInteraction(self.path) |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 260 | self.dbus.required_signals = { |
| 261 | I_SMS: ( ('IncomingMessage', self._on_incoming_message), ), |
| 262 | } |
| 263 | self.dbus.watch_interfaces() |
| 264 | |
Neels Hofmeyr | 4d688c2 | 2017-05-29 04:13:58 +0200 | [diff] [blame] | 265 | def cleanup(self): |
| 266 | self.dbus.cleanup() |
| 267 | self.dbus = None |
| 268 | |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 269 | def properties(self, *args, **kwargs): |
| 270 | '''Return a dict of properties on this modem. For the actual arguments, |
| 271 | see ModemDbusInteraction.properties(), which this function calls. The |
| 272 | returned dict is defined by ofono. An example is: |
| 273 | {'Lockdown': False, |
| 274 | 'Powered': True, |
| 275 | 'Model': 'MC7304', |
| 276 | 'Revision': 'SWI9X15C_05.05.66.00 r29972 CARMD-EV-FRMWR1 2015/10/08 08:36:28', |
| 277 | 'Manufacturer': 'Sierra Wireless, Incorporated', |
| 278 | 'Emergency': False, |
| 279 | 'Interfaces': ['org.ofono.SmartMessaging', |
| 280 | 'org.ofono.PushNotification', |
| 281 | 'org.ofono.MessageManager', |
| 282 | 'org.ofono.NetworkRegistration', |
| 283 | 'org.ofono.ConnectionManager', |
| 284 | 'org.ofono.SupplementaryServices', |
| 285 | 'org.ofono.RadioSettings', |
| 286 | 'org.ofono.AllowedAccessPoints', |
| 287 | 'org.ofono.SimManager', |
| 288 | 'org.ofono.LocationReporting', |
| 289 | 'org.ofono.VoiceCallManager'], |
| 290 | 'Serial': '356853054230919', |
| 291 | 'Features': ['sms', 'net', 'gprs', 'ussd', 'rat', 'sim', 'gps'], |
| 292 | 'Type': 'hardware', |
| 293 | 'Online': True} |
| 294 | ''' |
| 295 | return self.dbus.properties(*args, **kwargs) |
| 296 | |
| 297 | def set_powered(self, powered=True): |
| 298 | return self.dbus.set_powered(powered=powered) |
| 299 | |
| 300 | def set_online(self, online=True): |
| 301 | return self.dbus.set_online(online=online) |
| 302 | |
| 303 | def is_powered(self): |
| 304 | return self.dbus.is_powered() |
| 305 | |
| 306 | def is_online(self): |
| 307 | return self.dbus.is_online() |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 308 | |
| 309 | def set_msisdn(self, msisdn): |
| 310 | self.msisdn = msisdn |
| 311 | |
| 312 | def imsi(self): |
Neels Hofmeyr | b02c211 | 2017-04-09 18:46:48 +0200 | [diff] [blame] | 313 | imsi = self.conf.get('imsi') |
| 314 | if not imsi: |
| 315 | with self: |
| 316 | raise RuntimeError('No IMSI') |
| 317 | return imsi |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 318 | |
| 319 | def ki(self): |
| 320 | return self.conf.get('ki') |
| 321 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 322 | def connect(self, nitb): |
| 323 | 'set the modem up to connect to MCC+MNC from NITB config' |
| 324 | self.log('connect to', nitb) |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 325 | if self.is_powered(): |
| 326 | self.dbg('is powered') |
Pau Espin Pedrol | 107f275 | 2017-05-04 11:37:16 +0200 | [diff] [blame] | 327 | self.set_online(False) |
| 328 | self.set_powered(False) |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 329 | event_loop.wait(self, lambda: not self.dbus.has_interface(I_NETREG, I_SMS), timeout=10) |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 330 | self.set_powered() |
Pau Espin Pedrol | b995576 | 2017-05-02 09:39:27 +0200 | [diff] [blame] | 331 | self.set_online() |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 332 | event_loop.wait(self, self.dbus.has_interface, I_NETREG, I_SMS, timeout=10) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 333 | |
Neels Hofmeyr | 8c7477f | 2017-05-25 04:33:53 +0200 | [diff] [blame] | 334 | def sms_send(self, to_msisdn_or_modem, *tokens): |
| 335 | if isinstance(to_msisdn_or_modem, Modem): |
| 336 | to_msisdn = to_msisdn_or_modem.msisdn |
| 337 | tokens = list(tokens) |
| 338 | tokens.append('to ' + to_msisdn_or_modem.name()) |
| 339 | else: |
| 340 | to_msisdn = str(to_msisdn_or_modem) |
Neels Hofmeyr | 8d8b03e | 2017-05-06 18:19:46 +0200 | [diff] [blame] | 341 | sms = Sms(self.msisdn, to_msisdn, 'from ' + self.name(), *tokens) |
Neels Hofmeyr | 1ea59ea | 2017-05-02 14:41:54 +0200 | [diff] [blame] | 342 | self.log('sending sms to MSISDN', to_msisdn, sms=sms) |
Neels Hofmeyr | 896f08f | 2017-05-24 20:17:26 +0200 | [diff] [blame] | 343 | mm = self.dbus.interface(I_SMS) |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 344 | mm.SendMessage(to_msisdn, str(sms)) |
| 345 | return sms |
| 346 | |
| 347 | def _on_incoming_message(self, message, info): |
Neels Hofmeyr | 2e41def | 2017-05-06 22:42:57 +0200 | [diff] [blame] | 348 | self.log('Incoming SMS:', repr(message)) |
Neels Hofmeyr | f49c7da | 2017-05-06 22:43:32 +0200 | [diff] [blame] | 349 | self.dbg(info=info) |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 350 | self.sms_received_list.append((message, info)) |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 351 | |
Neels Hofmeyr | 863cb56 | 2017-05-02 16:27:59 +0200 | [diff] [blame] | 352 | def sms_was_received(self, sms): |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 353 | for msg, info in self.sms_received_list: |
| 354 | if sms.matches(msg): |
Neels Hofmeyr | 2e41def | 2017-05-06 22:42:57 +0200 | [diff] [blame] | 355 | self.log('SMS received as expected:', repr(msg)) |
Neels Hofmeyr | f49c7da | 2017-05-06 22:43:32 +0200 | [diff] [blame] | 356 | self.dbg(info=info) |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 357 | return True |
| 358 | return False |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 359 | |
Neels Hofmeyr | b801169 | 2017-05-29 03:45:24 +0200 | [diff] [blame^] | 360 | def info(self, keys=('Manufacturer', 'Model', 'Revision')): |
| 361 | props = self.properties() |
| 362 | return ', '.join(['%s: %r'%(k,props.get(k)) for k in keys]) |
| 363 | |
| 364 | def log_info(self, *args, **kwargs): |
| 365 | self.log(self.info(*args, **kwargs)) |
| 366 | |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 367 | class Sms: |
| 368 | _last_sms_idx = 0 |
| 369 | msg = None |
| 370 | |
Neels Hofmeyr | 8d8b03e | 2017-05-06 18:19:46 +0200 | [diff] [blame] | 371 | def __init__(self, from_msisdn=None, to_msisdn=None, *tokens): |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 372 | Sms._last_sms_idx += 1 |
| 373 | msgs = ['message nr. %d' % Sms._last_sms_idx] |
Neels Hofmeyr | 8d8b03e | 2017-05-06 18:19:46 +0200 | [diff] [blame] | 374 | msgs.extend(tokens) |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 375 | if from_msisdn: |
Neels Hofmeyr | 8d8b03e | 2017-05-06 18:19:46 +0200 | [diff] [blame] | 376 | msgs.append('from %s' % from_msisdn) |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 377 | if to_msisdn: |
Neels Hofmeyr | 8d8b03e | 2017-05-06 18:19:46 +0200 | [diff] [blame] | 378 | msgs.append('to %s' % to_msisdn) |
| 379 | self.msg = ', '.join(msgs) |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 380 | |
| 381 | def __str__(self): |
| 382 | return self.msg |
| 383 | |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 384 | def __repr__(self): |
| 385 | return repr(self.msg) |
| 386 | |
Neels Hofmeyr | b3daaea | 2017-04-09 14:18:34 +0200 | [diff] [blame] | 387 | def __eq__(self, other): |
| 388 | if isinstance(other, Sms): |
| 389 | return self.msg == other.msg |
| 390 | return inself.msg == other |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 391 | |
Neels Hofmeyr | fec7d16 | 2017-05-02 16:29:09 +0200 | [diff] [blame] | 392 | def matches(self, msg): |
| 393 | return self.msg == msg |
| 394 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 395 | # vim: expandtab tabstop=4 shiftwidth=4 |