#NEWLINE# def parse( self , ofx ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# for line in ofx . splitlines ( ) : #NEWLINE# #INDENT# if ( line . strip ( ) == '' ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# ( header , value ) = line . split ( ':' ) #NEWLINE# self . headers [ header ] = value #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if ( 'OFXHEADER' not in self . headers ) : #NEWLINE# #INDENT# self . headers [ 'OFXHEADER' ] = '100' #NEWLINE# #UNINDENT# if ( 'VERSION' not in self . headers ) : #NEWLINE# #INDENT# self . headers [ 'VERSION' ] = '102' #NEWLINE# #UNINDENT# if ( 'SECURITY' not in self . headers ) : #NEWLINE# #INDENT# self . headers [ 'SECURITY' ] = 'NONE' #NEWLINE# #UNINDENT# if ( 'OLDFILEUID' not in self . headers ) : #NEWLINE# #INDENT# self . headers [ 'OLDFILEUID' ] = 'NONE' #NEWLINE# #UNINDENT# if ( 'NEWFILEUID' not in self . headers ) : #NEWLINE# #INDENT# self . headers [ 'NEWFILEUID' ] = 'NONE' #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# tags = ofx . split ( '<' ) #NEWLINE# if ( len ( tags ) > 1 ) : #NEWLINE# #INDENT# tags = [ ( '<' + t . strip ( ) ) for t in tags [ 1 : ] ] #NEWLINE# #UNINDENT# heirarchy = [ ] #NEWLINE# can_open = True #NEWLINE# for ( i , tag ) in enumerate ( tags ) : #NEWLINE# #INDENT# gt = tag . index ( '>' ) #NEWLINE# if ( tag [ 1 ] != '/' ) : #NEWLINE# #INDENT# if ( not can_open ) : #NEWLINE# #INDENT# tags [ ( i - 1 ) ] = ( ( ( tags [ ( i - 1 ) ] + '</' ) + heirarchy . pop ( ) ) + '>' ) #NEWLINE# can_open = True #NEWLINE# #UNINDENT# tag_name = tag [ 1 : gt ] . split ( ) [ 0 ] #NEWLINE# heirarchy . append ( tag_name ) #NEWLINE# if ( len ( tag ) > ( gt + 1 ) ) : #NEWLINE# #INDENT# can_open = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# tag_name = tag [ 2 : gt ] . split ( ) [ 0 ] #NEWLINE# if ( tag_name not in heirarchy ) : #NEWLINE# #INDENT# tags [ i ] = tag [ ( gt + 1 ) : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# while ( tag_name != heirarchy [ ( - 1 ) ] ) : #NEWLINE# #INDENT# tags [ ( i - 1 ) ] = ( ( ( tags [ ( i - 1 ) ] + '</' ) + heirarchy . pop ( ) ) + '>' ) #NEWLINE# #UNINDENT# can_open = True #NEWLINE# heirarchy . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . xml = ET . fromstringlist ( tags ) #NEWLINE# self . load_from_xml ( self , self . xml ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# raise InvalidOFXStructureException