Merge "Fix recursive_keypairs output"

This commit is contained in:
Jenkins
2014-02-20 09:12:26 +00:00
committed by Gerrit Code Review
2 changed files with 8 additions and 2 deletions

View File

@@ -482,7 +482,13 @@ def _flatten_metadata(metadata):
to unicode strings.
"""
if metadata:
return dict((k, unicode(v))
# After changing recursive_keypairs` output we need to keep
# flattening output unchanged.
# Example: recursive_keypairs({'a': {'b':{'c':'d'}}}, '.')
# output before: a.b:c=d
# output now: a.b.c=d
# So to keep the first variant just replace all dots except the first
return dict((k.replace('.', ':').replace(':', '.', 1), unicode(v))
for k, v in utils.recursive_keypairs(metadata,
separator='.')
if type(v) is not set)

View File

@@ -31,7 +31,7 @@ def recursive_keypairs(d, separator=':'):
"""
for name, value in sorted(d.iteritems()):
if isinstance(value, dict):
for subname, subvalue in recursive_keypairs(value):
for subname, subvalue in recursive_keypairs(value, separator):
yield ('%s%s%s' % (name, separator, subname), subvalue)
elif isinstance(value, (tuple, list)):
# When doing a pair of JSON encode/decode operations to the tuple,