MCPcopy Create free account
hub / github.com/cdgriffith/Box / dump_yaml

Function dump_yaml

box/comments.py:333–351  ·  view source on GitHub ↗

to_yaml for Box and BoxList: with comments and the ruamel round trip dumper, write them out, otherwise dump `plain` exactly as before.

(obj, plain, filename=None, encoding: str = "utf-8", errors: str = "strict", **yaml_kwargs)

Source from the content-addressed store, hash-verified

331
332
333def dump_yaml(obj, plain, filename=None, encoding: str = "utf-8", errors: str = "strict", **yaml_kwargs):
334 """
335 to_yaml for Box and BoxList: with comments and the ruamel round trip dumper, write them out,
336 otherwise dump `plain` exactly as before.
337 """
338 from box import converters
339
340 use_comments = converters.ruamel_available and yaml_kwargs.get("ruamel_typ", "rt") == "rt" and has_comments(obj)
341 if not use_comments:
342 return converters._to_yaml(plain, filename=filename, encoding=encoding, errors=errors, **yaml_kwargs)
343 body = converters._to_yaml(commented_tree(obj, plain), encoding=encoding, errors=errors, **yaml_kwargs)
344 # Document comments are written as text: ruamel drops a blank line after a start comment
345 text = _document_lines(obj, "start") + body + _document_lines(obj, "end")
346 if not filename:
347 return text
348 converters._exists(filename, create=True)
349 with open(filename, "w", encoding=encoding, errors=errors) as f:
350 f.write(text)
351 return None

Callers

nothing calls this directly

Calls 4

has_commentsFunction · 0.85
commented_treeFunction · 0.85
_document_linesFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected