Function to parse short_message from deliver_sm#90
Function to parse short_message from deliver_sm#90Lynesth wants to merge 2 commits intopython-smpplib:masterfrom
Conversation
|
Oh this fails on 2.7 because of the |
|
Try Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> br'\n'
'\\n' |
|
@eigenein Thanks that did the trick. |
|
@podshumok @eigenein Could I get some review on this when you have the time ? |
|
I'm a bit 50/50, I mean, it looks good and helpful, but I'd make a utility function outside of @podshumok Did you have a chance to look at this? |
|
@eigenein Even though it is vendor specific it seems to be pretty widely used as is and most of the providers use that format. |
code-of-kpp
left a comment
There was a problem hiding this comment.
I don't think that it should live in PDU class, especially the part with changing class variable in statimethod.
It is OK as external function. It would be nice to provide simple integration with Client.set_message_received_handler
| command = None | ||
| status = None | ||
| _sequence = None | ||
| dlr_regex = None |
|
|
||
| return desc | ||
|
|
||
| @staticmethod |
There was a problem hiding this comment.
What If I work with two SMSCs with different deliver_sm message formats?
| raise ValueError("Invalid PDU command: %s", self.command) | ||
|
|
||
| if PDU.dlr_regex is None: | ||
| PDU.dlr_regex = re.compile(br'^id:(?P<id>\S+)\s+sub:(?P<sub>\S+)\s+dlvrd:(?P<dlvrd>\S+)\s+submit date:(?P<submit_date>\S+)\s+done date:(?P<done_date>\S+)\s+stat:(?P<stat>\S+)\s+err:(?P<err>\S+)\s+Text:(?P<text>.*)$', re.IGNORECASE) |
There was a problem hiding this comment.
Please keep lines at 79 symbols (PEP8). You can split
(
br'your'
br' string' # with some comments
' like' br'this'
)for example
There was a problem hiding this comment.
this default pattern can live in consts
|
Feel free to close it if you want. I won't have time to modify it anytime soon and wouldn't know where to put it anyway. |
Not sure if needed ot if correctly implemented but I've added a function to parse the
short_messageproperty of pdus fromdeliver_smcommands since not all vendors fill in optional parameters likereceipted_message_id.Example:
This returns a dict like this one:
Since it depends on a regex and all vendor surely don't implement the receipt the same way (according to the specs: The format for this Delivery Receipt message is SMSC vendor specific but following is a typical example of Delivery Receipt report.) I've added a way to set the regex manually:
Note that the regex must be bytes.