def yaml_encode(data):
 yrepr = yaml.representer.SafeRepresenter()
 ynode = yrepr.represent_data(data)
 if (not isinstance(ynode, yaml.ScalarNode)):
  raise TypeError('yaml_encode() only works with YAML scalar data; failed for {0}'.format(type(data)))
 tag = ynode.tag.rsplit(':', 1)[(-1)]
 ret = ynode.value
 if (tag == 'str'):
  ret = yaml_dquote(ynode.value)
 return ret

def yaml_encode ( data ) : yrepr = yaml . representer . SafeRepresenter ( ) ynode = yrepr . represent_data ( data ) if ( not isinstance ( ynode , yaml . ScalarNode ) ) : raise TypeError ( 'yaml_encode() only works with YAML scalar data; failed for {0}' . format ( type ( data ) ) ) tag = ynode . tag . rsplit ( ':' , 1 ) [ ( - 1 ) ] ret = ynode . value if ( tag == 'str' ) : ret = yaml_dquote ( ynode . value ) return ret
a simple yaml encode that can take a single-element datatype and return a string representation .