Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions smpplib/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"""PDU module"""

import re
import struct

from smpplib import command_codes, consts
Expand All @@ -48,6 +49,7 @@ class PDU(object):
command = None
status = None
_sequence = None
dlr_regex = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, avoid abbreviations


def __init__(self, client=default_client(), **kwargs):
"""Singleton dummy client will be used if omitted"""
Expand Down Expand Up @@ -104,6 +106,22 @@ def get_status_desc(self, status=None):

return desc

@staticmethod
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default pattern can live in consts


return PDU.dlr_regex.match(self.short_message).groupdict()

def parse(self, data):
"""Parse raw PDU"""

Expand Down