How to use the pyaml.__init__.UnsafePrettyYAMLDumper.represent_stringish function in pyaml

To help you get started, we’ve selected a few pyaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mk-fg / pretty-yaml / pyaml / __init__.py View on Github external
#  not sure if Emitter.analyze_scalar can also provide useful info here
		style = dumper.pyaml_string_val_style
		if not style:
			style = 'plain'
			if '\n' in data or not data or data == '-' or data[0] in '!&*[':
				style = 'literal'
				if '\n' in data[:-1]:
					for line in data.splitlines():
						if len(line) > dumper.best_width: break
					else: style = '|'

		return yaml.representer.ScalarNode('tag:yaml.org,2002:str', data, style=style)

for str_type in {bytes, unicode}:
	UnsafePrettyYAMLDumper.add_representer(
		str_type, UnsafePrettyYAMLDumper.represent_stringish )

UnsafePrettyYAMLDumper.add_representer(
	type(None), lambda s,o: s.represent_scalar('tag:yaml.org,2002:null', '') )

def add_representer(*args, **kws):
	PrettyYAMLDumper.add_representer(*args, **kws)
	UnsafePrettyYAMLDumper.add_representer(*args, **kws)


def dump_add_vspacing(buff, vspacing):
	'Post-processing to add some nice-ish spacing for deeper map/list levels.'
	if isinstance(vspacing, int):
		vspacing = ['\n']*(vspacing+1)
	buff.seek(0)
	result = list()
	for line in buff: