-
-
Notifications
You must be signed in to change notification settings - Fork 143
Function to parse short_message from deliver_sm #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
|
|
||
| """PDU module""" | ||
|
|
||
| import re | ||
| import struct | ||
|
|
||
| from smpplib import command_codes, consts | ||
|
|
@@ -48,6 +49,7 @@ class PDU(object): | |
| command = None | ||
| status = None | ||
| _sequence = None | ||
| dlr_regex = None | ||
|
|
||
| def __init__(self, client=default_client(), **kwargs): | ||
| """Singleton dummy client will be used if omitted""" | ||
|
|
@@ -104,6 +106,22 @@ def get_status_desc(self, status=None): | |
|
|
||
| return desc | ||
|
|
||
| @staticmethod | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What If I work with two SMSCs with different deliver_sm message formats? |
||
| def set_delivey_receipt_regex(regex): | ||
| """To replace the regex used if SMSC uses a different format""" | ||
| PDU.dlr_regex = re.compile(regex, re.IGNORECASE) | ||
|
|
||
| def parse_deliver_receipt(self): | ||
| """Parses the short_message property to retrieve deliver_sm infos""" | ||
|
|
||
| if self.command != 'deliver_sm': | ||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep lines at 79 symbols (PEP8). You can split (
br'your'
br' string' # with some comments
' like' br'this'
)for example
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
|
|
||
| return PDU.dlr_regex.match(self.short_message).groupdict() | ||
|
|
||
| def parse(self, data): | ||
| """Parse raw PDU""" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, avoid abbreviations