def parse_tls(message, throw_on_incomplete=False):
 extra_fragment_data = ''
 original_message = message
 try:
  while message:
   try:
    (record, size) = types.TlsRecord.from_stream(message, previous_fragment_data=extra_fragment_data)
    return (record, message[size:])
   except types.TlsMessageFragmentedError as e:
    extra_fragment_data += e.fragment_data
    message = message[e.data_consumed:]
    if (not message):
     if throw_on_incomplete:
      raise e
     else:
      return (None, original_message)
 except (IndexError, ValueError, struct.error):
  return (None, original_message)
 except types.TlsRecordIncompleteError as e:
  if throw_on_incomplete:
   raise e
  else:
   return (None, original_message)
 return (None, original_message)

def parse_tls ( message , throw_on_incomplete = False ) : extra_fragment_data = '' original_message = message try : while message : try : ( record , size ) = types . TlsRecord . from_stream ( message , previous_fragment_data = extra_fragment_data ) return ( record , message [ size : ] ) except types . TlsMessageFragmentedError as e : extra_fragment_data += e . fragment_data message = message [ e . data_consumed : ] if ( not message ) : if throw_on_incomplete : raise e else : return ( None , original_message ) except ( IndexError , ValueError , struct . error ) : return ( None , original_message ) except types . TlsRecordIncompleteError as e : if throw_on_incomplete : raise e else : return ( None , original_message ) return ( None , original_message )
try and parse a tls record .