#NEWLINE# def main( self , folder , field_name , value , as_json = False ) : #NEWLINE# #INDENT# fields = folder . get_fields ( ) #NEWLINE# if last_key : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# value = json . loads ( value ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise JirafsError ( ( "Value '%s' could not be decoded as JSON." % ( value , ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# key_dotpath = None #NEWLINE# if ( '.' in field_name ) : #NEWLINE# #INDENT# ( field_name , key_dotpath ) = field_name . split ( '.' , 1 ) #NEWLINE# #UNINDENT# if ( field_name not in fields ) : #NEWLINE# #INDENT# raise JirafsError ( ( "Field '%s' does not exist." % field_name ) ) #NEWLINE# #UNINDENT# if key_dotpath : #NEWLINE# #INDENT# data = fields [ field_name ] #NEWLINE# try : #NEWLINE# #INDENT# cursor = data #NEWLINE# dotpath_parts = key_dotpath . split ( '.' ) #NEWLINE# last_key = ( len ( dotpath_parts ) - 1 ) #NEWLINE# for ( idx , component ) in enumerate ( dotpath_parts ) : #NEWLINE# #INDENT# if ( idx == last_key ) : #NEWLINE# #INDENT# cursor [ component ] = value #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( cursor . get ( component ) , dict ) ) : #NEWLINE# #INDENT# raise JirafsError ( ( "Key '%s' (of dotpath '%s') is not an object in field '%s'." % ( component , key_dotpath , field_name ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( component not in data ) : #NEWLINE# #INDENT# raise JirafsError ( ( "Key '%s' (of dotpath '%s') could not be found in field '%s'." % ( component , key_dotpath , field_name ) ) ) #NEWLINE# #UNINDENT# cursor = cursor [ component ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# raise JirafsError ( ( "Field '%s' could not be parsed as JSON for retrieving dotpath '%s'." % ( field_name , key_dotpath ) ) ) #NEWLINE# #UNINDENT# value = data #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data = value #NEWLINE# #UNINDENT# fields [ field_name ] = data #NEWLINE# fields . write ( )