#NEWLINE# def repack_dictlist( data ) : #NEWLINE# #INDENT# '\n    Takes a list of one-element dicts (as found in many SLS schemas) and\n    repacks into a single dictionary.\n    ' #NEWLINE# if isinstance ( data , six . string_types ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import yaml #NEWLINE# data = yaml . safe_load ( data ) #NEWLINE# #UNINDENT# except yaml . parser . ParserError as err : #NEWLINE# #INDENT# log . error ( element ) #NEWLINE# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not isinstance ( data , list ) ) or [ x for x in data if ( not isinstance ( x , ( six . string_types , int , float , dict ) ) ) ] ) : #NEWLINE# #INDENT# log . error ( 'Invalid input: {0}' . format ( pprint . pformat ( data ) ) ) #NEWLINE# log . error ( 'Input must be a list of strings/dicts' ) #NEWLINE# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for element in data : #NEWLINE# #INDENT# if isinstance ( element , ( six . string_types , int , float ) ) : #NEWLINE# #INDENT# ret [ element ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( element ) != 1 ) : #NEWLINE# #INDENT# log . error ( 'Invalid input: key/value pairs must contain only one element (data passed: {0}).' . format ( element ) ) #NEWLINE# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ret . update ( element ) #NEWLINE# #UNINDENT# #UNINDENT# return ret