Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# quoting it with 'literal' if lines are too long anyway,
# 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()
def add_representer(*args, **kws):
PrettyYAMLDumper.add_representer(*args, **kws)
UnsafePrettyYAMLDumper.add_representer(*args, **kws)
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:
level = 0
line = line.decode('utf-8')