17 from functools import partial |
17 from functools import partial |
18 |
18 |
19 from ..config import Option |
19 from ..config import Option |
20 from ..model.status import Status |
20 from ..model.status import Status |
21 from .provider import Provider, providers |
21 from .provider import Provider, providers |
|
22 from ..error import RejectRecipient, ExternalException |
22 |
23 |
23 import logging |
24 import logging |
24 logger=logging.getLogger("smstrade") |
25 logger=logging.getLogger("smstrade") |
25 |
26 |
26 class UnknownStatusCode(Exception): |
27 class UnknownStatusCode(ExternalException): |
27 def __init__(self,code): |
28 def __init__(self,status): |
28 self.code=code |
29 ExternalException.__init__(self) |
|
30 self.status=status |
29 |
31 |
30 def __str__(self): |
32 def __str__(self): |
31 return "StatusCode %i is unknown"%self.code |
33 return "%s\nStatusCode %i is unknown."%(ExternalException.__str__(self),self.status) |
32 |
34 |
33 |
35 |
34 class StatusCode: |
36 class StatusCode: |
35 statusCodes = {10 : "Empfaengernummer nicht korrekt", |
37 statusCodes = {10 : "Empfaengernummer nicht korrekt", |
36 20 : "Absenderkennung nicht korrekt", |
38 20 : "Absenderkennung nicht korrekt", |
90 """send SMS with $sms to $recipients""" |
92 """send SMS with $sms to $recipients""" |
91 logger.debug('smstrade.sendSMS(%s,%s)'%(sms, recipient)) |
93 logger.debug('smstrade.sendSMS(%s,%s)'%(sms, recipient)) |
92 route = unicode(route) |
94 route = unicode(route) |
93 |
95 |
94 if recipient.land != '49' and route == "basic": |
96 if recipient.land != '49' and route == "basic": |
95 return Exception() |
97 raise RejectRecipient(recipient) |
96 |
98 |
97 to ='00'+recipient.land+recipient.number |
99 to ='00'+recipient.land+recipient.number |
98 try: |
100 |
99 smsSendStatus = self.__send(route, to, sms) |
101 smsSendStatus = self.__send(route, to, sms) |
100 logger.info('smstrade._send(...)=%i(%s)'%(int(smsSendStatus),str(smsSendStatus))) |
102 logger.info('smstrade._send(...)=%i(%s)'%(int(smsSendStatus),str(smsSendStatus))) |
101 if int(smsSendStatus) in (100,): |
103 if int(smsSendStatus) in (100,): |
102 return Status(self,route) |
104 return Status(self,route) |
103 else: |
105 elif int(smsSendStatus) in (70,71,): |
104 raise Exception() |
106 raise RejectRecipient(recipient, status=smsSendStatus) |
105 except UnknownStatusCode: |
107 else: |
106 raise Exception() |
108 raise Exception() |
107 |
109 |
108 def __send(self, route, to, sms): |
110 def __send(self, route, to, sms): |
109 """ This function is the main part of the request to the sms service. |
111 """ This function is the main part of the request to the sms service. |
110 The function has to return a unicode formated string that will represent the answer of the sms service |
112 The function has to return a unicode formated string that will represent the answer of the sms service |