#NEWLINE# def analyze( self , fieldMappings = None ) : #NEWLINE# #INDENT# if ( fieldMappings is None ) : #NEWLINE# #INDENT# fieldMappings = defaultFieldMappings #NEWLINE# #UNINDENT# retval = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for field in fieldMappings : #NEWLINE# #INDENT# value = getattr ( self , field [ 1 ] ) ( ) #NEWLINE# worklist = [ ( retval , field [ 0 ] , value ) ] #NEWLINE# while ( len ( worklist ) > 0 ) : #NEWLINE# #INDENT# workItem = worklist . pop ( ) #NEWLINE# obj = workItem [ 0 ] #NEWLINE# keyPath = workItem [ 1 ] #NEWLINE# value = workItem [ 2 ] #NEWLINE# key = keyPath [ 0 ] #NEWLINE# isArray = isinstance ( key , ( int , long ) ) #NEWLINE# if ( isArray and ( key >= len ( obj ) ) ) : #NEWLINE# #INDENT# obj . extend ( ( [ None ] * ( ( key + 1 ) - len ( obj ) ) ) ) #NEWLINE# #UNINDENT# if ( len ( keyPath ) == 1 ) : #NEWLINE# #INDENT# obj [ key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( keyPath [ 1 ] , basestring ) : #NEWLINE# #INDENT# if isArray : #NEWLINE# #INDENT# if ( obj [ key ] is None ) : #NEWLINE# #INDENT# obj [ key ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# obj = obj [ key ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj = obj . setdefault ( key , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# worklist . append ( ( obj , keyPath [ 1 : ] , value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( keyPath [ 1 ] , list ) : #NEWLINE# #INDENT# if isArray : #NEWLINE# #INDENT# if ( obj [ key ] is None ) : #NEWLINE# #INDENT# obj [ key ] = [ ] #NEWLINE# #UNINDENT# obj = obj [ key ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj = obj . setdefault ( key , [ ] ) #NEWLINE# #UNINDENT# for ( index , element ) in enumerate ( value ) : #NEWLINE# #INDENT# worklist . append ( ( obj , ( [ index ] + keyPath [ 2 : ] ) , element ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( keyPath [ 1 ] , dict ) : #NEWLINE# #INDENT# if isArray : #NEWLINE# #INDENT# if ( obj [ key ] is None ) : #NEWLINE# #INDENT# obj [ key ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# obj = obj [ key ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj = obj . setdefault ( key , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# for dictKey in value : #NEWLINE# #INDENT# if ( 0 == len ( keyPath [ 1 ] ) ) : #NEWLINE# #INDENT# keyToWrite = dictKey #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if keyPath [ 1 ] . has_key ( dictKey ) : #NEWLINE# #INDENT# keyToWrite = keyPath [ 1 ] [ dictKey ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# worklist . append ( ( obj , ( [ keyToWrite ] + keyPath [ 2 : ] ) , value [ dictKey ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( ( 'Key of invalid type: %s' % str ( key ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return retval