#NEWLINE# def isDeliveryReceipt( self , pdu ) : #NEWLINE# #INDENT# "Check whether pdu is a DLR or not, will return None if not\n        or a dict with the DLR elements.\n        It'll proceed through 2 steps:\n         1. looking for receipted_message_id and message_state\n         2. then parsing the message content for extra fields\n        " #NEWLINE# if ( ( not isinstance ( pdu , DeliverSM ) ) and ( not isinstance ( pdu , DataSM ) ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# ret = { #NEWLINE# #INDENT# 'dlvrd' : 'ND' , #NEWLINE# 'sub' : 'ND' , #NEWLINE# 'sdate' : 'ND' , #NEWLINE# 'ddate' : 'ND' , #NEWLINE# 'err' : 'ND' , #NEWLINE# 'text' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( ( 'receipted_message_id' in pdu . params ) and ( 'message_state' in pdu . params ) ) : #NEWLINE# #INDENT# ret [ 'id' ] = pdu . params [ 'receipted_message_id' ] #NEWLINE# if ( pdu . params [ 'message_state' ] in message_state_map ) : #NEWLINE# #INDENT# ret [ 'stat' ] = message_state_map [ pdu . params [ 'message_state' ] ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'stat' ] = 'UNKNOWN' #NEWLINE# #UNINDENT# #UNINDENT# if ( 'short_message' in pdu . params ) : #NEWLINE# #INDENT# patterns = [ 'id:(?P<id>[\\dA-Za-z-_]+)' , 'sub:(?P<sub>\\d{3})' , 'dlvrd:(?P<dlvrd>\\d{3})' , 'submit date:(?P<sdate>\\d+)' , 'done date:(?P<ddate>\\d+)' , 'stat:(?P<stat>\\w{7})' , 'err:(?P<err>\\w{3})' , 'text:(?P<text>.*)' ] #NEWLINE# for pattern in patterns : #NEWLINE# #INDENT# m = re . search ( pattern , pattern . params [ 'short_message' ] ) #NEWLINE# if m : #NEWLINE# #INDENT# ret . update ( m . groupdict ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( 'id' in ret ) and ( 'stat' in ret ) ) : #NEWLINE# #INDENT# return ret #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None