#NEWLINE# def convert_to_yaml( cfg , str_or_buffer ) : #NEWLINE# #INDENT# '\n    Convert a dictionary to YAML and return the string or write it out\n    depending on the type of `str_or_buffer`.\n\n    Parameters\n    ----------\n    cfg : dict\n        Dictionary to convert.\n    str_or_buffer : None, str, or buffer\n        If None: the YAML string will be returned.\n        If string: YAML will be saved to a file.\n        If buffer: YAML will be written to buffer using the ``.write`` method.\n\n    Returns\n    -------\n    str or None\n        YAML string if `str_or_buffer` is None, otherwise None since YAML\n        is written out to a separate destination.\n\n    ' #NEWLINE# s = ordered_yaml ( s ) #NEWLINE# if ( not str_or_buffer ) : #NEWLINE# #INDENT# return s #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( str_or_buffer , str ) : #NEWLINE# #INDENT# with open ( str_or_buffer , 'w' ) as f : #NEWLINE# #INDENT# f . write ( s ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# str_or_buffer . write ( s )