How to use the pyaml.__init__.UnsafePrettyYAMLDumper 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
def dump( data, dst=unicode, safe=False, force_embed=False, vspacing=None,
		string_val_style=None, sort_dicts=True, multiple_docs=False, **pyyaml_kws ):
	buff = io.BytesIO()
	Dumper = PrettyYAMLDumper if safe else UnsafePrettyYAMLDumper
	Dumper = ft.partial( Dumper,
		force_embed=force_embed, string_val_style=string_val_style, sort_dicts=sort_dicts )
	if not multiple_docs: data = [data]
	else: pyyaml_kws.setdefault('explicit_start', True)
	yaml.dump_all( data, buff, Dumper=Dumper,
		default_flow_style=False, allow_unicode=True, encoding='utf-8', **pyyaml_kws )

	if vspacing is not None:
		dump_add_vspacing(buff, vspacing)

	buff = buff.getvalue()
	if dst is bytes: return buff
	elif dst is unicode: return buff.decode('utf-8')
	else:
		try: dst.write(b'') # tests if dst is unicode- or bytestream
		except: dst.write(buff.decode('utf-8'))
github mk-fg / pretty-yaml / pyaml / __init__.py View on Github external
def choose_scalar_style(self):
		is_dict_key = self.states[-1] == self.expect_block_mapping_simple_value
		if is_dict_key:
			# Don't mess-up (replace) styles for dict keys, if possible
			if self.pyaml_string_val_style: self.event.style = 'plain'
		else:
			# Make sure we don't create "key: null" mapping accidentally
			if self.event.value.endswith(':'): self.event.style = "'"
		return super(UnsafePrettyYAMLDumper, self).choose_scalar_style()\
			if self.event.style != 'plain' else ("'" if ' ' in self.event.value else None)