Skip to content

Commit

Permalink
fix string standards and use yaml.safe_load
Browse files Browse the repository at this point in the history
  • Loading branch information
thatch45 committed Mar 28, 2012
1 parent e3fe0c0 commit 12a0f44
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions salt/utils/yaml.py
Expand Up @@ -11,33 +11,41 @@
except:
pass

load = yaml.load
load = yaml.safe_load


class DuplicateKeyWarning(RuntimeWarning):
"""Warned when duplicate keys exist"""
'''
Warned when duplicate keys exist
'''

warnings.simplefilter('always', category=DuplicateKeyWarning)


class CustomeConstructor(yaml.constructor.SafeConstructor):
'''
Create a custom constructor for manageging YAML
'''
def construct_mapping(self, node, deep=False):
'''
Build the mapping for yaml
'''
if not isinstance(node, MappingNode):
raise ConstructorError(None, None,
"expected a mapping node, but found %s" % node.id,
'expected a mapping node, but found {0}'.format(node.id),
node.start_mark)
mapping = {}
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError, exc:
raise ConstructorError("while constructing a mapping", node.start_mark,
"found unacceptable key (%s)" % exc, key_node.start_mark)
raise ConstructorError('while constructing a mapping', node.start_mark,
'found unacceptable key (%s)' % exc, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
if key in mapping:
warnings.warn(
"Duplicate Key: '{0}'".format(key), DuplicateKeyWarning)
'Duplicate Key: "{0}"'.format(key), DuplicateKeyWarning)
mapping[key] = value
return mapping

Expand Down

0 comments on commit 12a0f44

Please sign in to comment.