#NEWLINE# def build_param_structure( params , target , value , index = None ) : #NEWLINE# #INDENT# "\n    This method provides a basic reverse JMESPath implementation that\n    lets you go from a JMESPath-like string to a possibly deeply nested\n    object. The ``params`` are mutated in-place, so subsequent calls\n    can modify the same element by its index.\n\n        >>> build_param_structure(params, 'test[0]', 1)\n        >>> print(params)\n        {'test': [1]}\n\n        >>> build_param_structure(params, 'foo.bar[0].baz', 'hello world')\n        >>> print(params)\n        {'test': [1], 'foo': {'bar': [{'baz': 'hello, world'}]}}\n\n    " #NEWLINE# pos = params #NEWLINE# parts = target . split ( '.' ) #NEWLINE# for ( i , part ) in enumerate ( parts ) : #NEWLINE# #INDENT# result = INDEX_RE . search ( part ) #NEWLINE# if result : #NEWLINE# #INDENT# if result . group ( 1 ) : #NEWLINE# #INDENT# if ( result . group ( 1 ) == '*' ) : #NEWLINE# #INDENT# part = part [ : ( - 3 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# index = int ( result . group ( 1 ) ) #NEWLINE# part = part [ : ( - len ( ( str ( index ) + '[]' ) ) ) ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# index = None #NEWLINE# part = part [ : ( - 2 ) ] #NEWLINE# #UNINDENT# if ( ( part not in pos ) or ( not isinstance ( pos [ part ] , list ) ) ) : #NEWLINE# #INDENT# pos [ part ] = [ ] #NEWLINE# #UNINDENT# if ( index is None ) : #NEWLINE# #INDENT# index = len ( pos [ part ] ) #NEWLINE# #UNINDENT# while ( len ( pos [ part ] ) <= index ) : #NEWLINE# #INDENT# pos [ part ] . append ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( i == ( len ( parts ) - 1 ) ) : #NEWLINE# #INDENT# pos [ part ] [ index ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pos = pos [ part ] [ index ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( part not in pos ) : #NEWLINE# #INDENT# pos [ part ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( i == ( len ( parts ) - 1 ) ) : #NEWLINE# #INDENT# pos [ part ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pos = pos [ part ]