Convert YAML keys and values back to strings

I hadn't quite realized before that the user could also change the *keys* to
be non-strings too! This also prevents against that by just reinterpreting
everything as strings.
This commit is contained in:
Adrian Sampson 2015-11-19 15:38:20 -08:00
parent 0873d31419
commit 0e20770cc3

View file

@ -52,7 +52,8 @@ def dump(arg):
def load(s):
"""Read a sequence of YAML documents back to a list of dictionaries.
"""Read a sequence of YAML documents back to a list of dictionaries
with string keys and values.
Can raise a `ParseError`.
"""
@ -65,7 +66,12 @@ def load(s):
type(d).__name__
)
)
out.append(d)
# Convert all keys and values to strings. They started out
# as strings, but the user may have inadvertently messed
# this up.
out.append({unicode(k): unicode(v) for k, v in d.items()})
except yaml.YAMLError as e:
raise ParseError('invalid YAML: {}'.format(e))
return out