How to use the pyaml.__init__.PrettyYAMLDumper 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 __init__(self, *args, **kws):
		self.pyaml_force_embed = kws.pop('force_embed', False)
		self.pyaml_string_val_style = kws.pop('string_val_style', None)
		self.pyaml_sort_dicts = kws.pop('sort_dicts', True)
		return super(PrettyYAMLDumper, self).__init__(*args, **kws)
github mk-fg / pretty-yaml / pyaml / __init__.py View on Github external
PrettyYAMLDumper.add_representer(dict, PrettyYAMLDumper.represent_dict)
PrettyYAMLDumper.add_representer(defaultdict, PrettyYAMLDumper.represent_dict)
PrettyYAMLDumper.add_representer(OrderedDict, PrettyYAMLDumper.represent_odict)
PrettyYAMLDumper.add_representer(set, PrettyYAMLDumper.represent_list)
PrettyYAMLDumper.add_representer(None, PrettyYAMLDumper.represent_undefined)

if sys.version_info.major >= 3:
	try: import pathlib
	except ImportError: pass
	else:
		PrettyYAMLDumper.add_representer(
			type(pathlib.Path('')), lambda cls,o: cls.represent_data(str(o)) )


class UnsafePrettyYAMLDumper(PrettyYAMLDumper):

	def expect_block_sequence(self):
		self.increase_indent(flow=False, indentless=False)
		self.state = self.expect_first_block_sequence_item

	def expect_block_sequence_item(self, first=False):
		if not first and isinstance(self.event, yaml.events.SequenceEndEvent):
			self.indent = self.indents.pop()
			self.state = self.states.pop()
		else:
			self.write_indent()
			self.write_indicator('-', True, indention=True)
			self.states.append(self.expect_block_sequence_item)
			self.expect_node(sequence=True)

	def choose_scalar_style(self):