def get_outbound_pdus(text, recipient):
 encoding = 'ucs2'
 try:
  encoded_text = text.encode('gsm')
  encoding = 'gsm'
 except:
  encoded_text = text
 csm_max = MSG_LIMITS[encoding][1]
 if (len(encoded_text) > (MAX_CSM_SEGMENTS * csm_max)):
  raise ValueError('Message text too long')
 if (len(encoded_text) <= MSG_LIMITS[encoding][0]):
  return [OutboundGsmPdu(text, recipient)]
 with __ref_lock:
  if (recipient not in __csm_refs):
   __csm_refs[recipient] = 0
  csm_ref = (__csm_refs[recipient] % 256)
  __csm_refs[recipient] += 1
 num = int(math.ceil((len(encoded_text) / float(MSG_LIMITS[encoding][0]))))
 pdus = []
 for seq in range(num):
  i = (seq * csm_max)
  seg_txt = encoded_text[i:(i + csm_max)]
  if (encoding == 'gsm'):
   seg_txt = seg_txt.decode('gsm')
  pdus.append(OutboundGsmPdu(seg_txt, recipient, csm_ref=csm_ref, csm_seq=(seq + 1), csm_total=num))
 return pdus

def get_outbound_pdus ( text , recipient ) : encoding = 'ucs2' try : encoded_text = text . encode ( 'gsm' ) encoding = 'gsm' except : encoded_text = text csm_max = MSG_LIMITS [ encoding ] [ 1 ] if ( len ( encoded_text ) > ( MAX_CSM_SEGMENTS * csm_max ) ) : raise ValueError ( 'Message text too long' ) if ( len ( encoded_text ) <= MSG_LIMITS [ encoding ] [ 0 ] ) : return [ OutboundGsmPdu ( text , recipient ) ] with __ref_lock : if ( recipient not in __csm_refs ) : __csm_refs [ recipient ] = 0 csm_ref = ( __csm_refs [ recipient ] % 256 ) __csm_refs [ recipient ] += 1 num = int ( math . ceil ( ( len ( encoded_text ) / float ( MSG_LIMITS [ encoding ] [ 0 ] ) ) ) ) pdus = [ ] for seq in range ( num ) : i = ( seq * csm_max ) seg_txt = encoded_text [ i : ( i + csm_max ) ] if ( encoding == 'gsm' ) : seg_txt = seg_txt . decode ( 'gsm' ) pdus . append ( OutboundGsmPdu ( seg_txt , recipient , csm_ref = csm_ref , csm_seq = ( seq + 1 ) , csm_total = num ) ) return pdus
returns a list of pdus to send the provided text to the given recipient .