#NEWLINE# def get_records( self ) : #NEWLINE# #INDENT# 'Extract the DMARC records as defined here: \n\t\thttp://www.dmarc.org/draft-dmarc-base-00-02.txt in Appendix C\n\t\tIf no data is found, return NA\n\t\t' #NEWLINE# container = self . doc . findall ( 'record' ) #NEWLINE# for elem in container : #NEWLINE# #INDENT# source_ip = elem . findtext ( 'row/source_ip' , default = 'NA' ) #NEWLINE# count = elem . findtext ( 'row/count' , default = 'NA' ) #NEWLINE# count = int ( count ) #NEWLINE# disposition = elem . findtext ( 'row/policy_evaluated/disposition' , default = 'NA' ) #NEWLINE# dkim = elem . findtext ( 'row/policy_evaluated/dkim' , default = 'NA' ) #NEWLINE# spf = elem . findtext ( 'row/policy_evaluated/spf' , default = 'NA' ) #NEWLINE# type = elem . findtext ( 'row/policy_evaluated/reason/type' , default = 'NA' ) #NEWLINE# comment = elem . findtext ( 'row/policy_evaluated/reason/comment' , default = 'NA' ) #NEWLINE# header_from = elem . findtext ( 'identifiers/header_from' , default = 'NA' ) #NEWLINE# dkim_domain = elem . findtext ( 'auth_results/dkim/domain' , default = 'NA' ) #NEWLINE# dkim_result = elem . findtext ( 'auth_results/dkim/result' , default = 'NA' ) #NEWLINE# dkim_hresult = elem . findtext ( 'auth_results/dkim/human_result' , default = 'NA' ) #NEWLINE# spf_domain = elem . findtext ( 'auth_results/spf/domain' , default = 'NA' ) #NEWLINE# spf_result = elem . findtext ( 'auth_results/spf/result' , default = 'NA' ) #NEWLINE# sql = ( 'INSERT INTO records(source_ip, count, disposition, dkim, spf, type, comment, header_from, dkim_domain, dkim_result, dkim_hresult, spf_domain, spf_result, metadata_fk, published_fk) \n\t\t\t\t\t\tVALUES("%s", %d, "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", %d, %d)' % ( source_ip , count , disposition , dkim , spf , type , comment , header_from , dkim_domain , dkim_result , dkim_hresult , spf_domain , spf_result , self . metadata_fk , self . policy_fk ) ) #NEWLINE# try : #NEWLINE# #INDENT# self . cursor . execute ( sql ) #NEWLINE# self . db . commit ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# self . db . rollback ( ) #NEWLINE# #UNINDENT# #UNINDENT# self . db . close ( )