Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_delete_missing():
dict = {
"a": {
}
}
dpath.util.delete(dict, '/a/b')
def test_delete_filter():
def afilter(x):
if int(x) == 31:
return True
return False
data = TestMapping({
"a": TestMapping({
"b": 0,
"c": 1,
"d": 31
})
})
dpath.util.delete(data, '/a/*', afilter=afilter)
assert (data['a']['b'] == 0)
assert (data['a']['c'] == 1)
assert ('d' not in data['a'])
def test_delete_separator():
dict = {
"a": {
"b": 0
}
}
dpath.util.delete(dict, ';a;b', separator=";")
assert(not 'b' in dict['a'])
def test_delete_filter():
def afilter(x):
if int(x) == 31:
return True
return False
dict = {
"a": {
"b": 0,
"c": 1,
"d": 31
}
}
dpath.util.delete(dict, '/a/*', afilter=afilter)
assert (dict['a']['b'] == 0)
assert (dict['a']['c'] == 1)
assert ('d' not in dict['a'])
def durable_hash(self, item, ephemeral_paths):
"""
Remove all ephemeral paths from the item and return the hash of the new structure.
:param item: dictionary, representing an item tracked in security_monkey
:return: hash of the sorted json dump of the item with all ephemeral paths removed.
"""
durable_item = deepcopy(item)
if ephemeral_paths:
for path in ephemeral_paths:
try:
dpath.util.delete(durable_item, path, separator='$')
except PathNotFound:
pass
return self.hash_config(durable_item)
def durable_hash(item, ephemeral_paths):
"""
Remove all ephemeral paths from the item and return the hash of the new structure.
:param item: dictionary, representing an item tracked in security_monkey
:return: hash of the sorted json dump of the item with all ephemeral paths removed.
"""
durable_item = deepcopy(item)
for path in ephemeral_paths:
try:
dpath.util.delete(durable_item, path, separator='$')
except PathNotFound:
pass
return hash_config(durable_item)
path = element[0]
self.set(manifest, x, path, {})
for element in self.elements.get('set', []):
path, value = element
self.set(manifest, x, path, args.interpolate(value))
for element in self.elements.get('setint', []):
path, value = element
self.set(manifest, x, path, int(value))
for element in self.elements.get('delete', []):
path = element[0]
qualified = '/%d/%s' % (x, path)
logging.debug("DEL %s" % qualified)
dpath.util.delete(manifest, qualified)
return True