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_set_walkable(walkable, value):
'''
Given a walkable location, set should be able to update any value.
'''
(node, (segments, found)) = walkable
api.set(node, segments, value)
assert api.get(node, segments) is value
(node, (segments, found)) = walkable
assume(api.leaf(found))
parent_segments = segments[:-1]
parent = api.get(node, parent_segments)
if isinstance(parent, list):
assume(len(parent) < kint)
destination = parent_segments + (kint,) + tuple(extension)
elif isinstance(parent, dict):
assume(kstr not in parent)
destination = parent_segments + (kstr,) + tuple(extension)
else:
raise Exception('mad mad world')
api.set(node, destination, value)
assert api.get(node, destination) is value
def f(obj, pair, counter):
(segments, found) = pair
# Skip segments if they no longer exist in obj.
if not dpath.segments.has(obj, segments):
return
matched = dpath.segments.match(segments, globlist)
selected = afilter and dpath.segments.leaf(found) and afilter(found)
if (matched and not afilter) or (matched and selected):
dpath.segments.set(obj, segments, value, creator=None)
counter[0] += 1
def new(obj, path, value, separator='/'):
'''
Set the element at the terminus of path to value, and create
it if it does not exist (as opposed to 'set' that can only
change existing keys).
path will NOT be treated like a glob. If it has globbing
characters in it, they will become part of the resulting
keys
'''
segments = __safe_path__(path, separator)
return dpath.segments.set(obj, segments, value)
def f(obj, pair, result):
(segments, found) = pair
if keeper(segments, found):
dpath.segments.set(result, segments, found, hints=dpath.segments.types(obj, segments))
path = separator.join(segments)
raise TypeError("Cannot merge objects of type"
"{0} and {1} at {2}"
"".format(tt, ft, path))
# Path not present in destination, create it.
if not dpath.segments.has(dst, segments):
dpath.segments.set(dst, segments, found)
continue
# Retrieve the value in the destination.
target = dpath.segments.get(dst, segments)
# If the types don't match, replace it.
if type(found) != type(target):
dpath.segments.set(dst, segments, found)
continue
# If target is a leaf, the replace it.
if dpath.segments.leaf(target):
dpath.segments.set(dst, segments, found)
continue
# At this point we know:
#
# * The target exists.
# * The types match.
# * The target isn't a leaf.
#
# Pretend we have a sequence and account for the flags.
try:
if flags & MERGE_ADDITIVE:
# Path not present in destination, create it.
if not dpath.segments.has(dst, segments):
dpath.segments.set(dst, segments, found)
continue
# Retrieve the value in the destination.
target = dpath.segments.get(dst, segments)
# If the types don't match, replace it.
if type(found) != type(target):
dpath.segments.set(dst, segments, found)
continue
# If target is a leaf, the replace it.
if dpath.segments.leaf(target):
dpath.segments.set(dst, segments, found)
continue
# At this point we know:
#
# * The target exists.
# * The types match.
# * The target isn't a leaf.
#
# Pretend we have a sequence and account for the flags.
try:
if flags & MERGE_ADDITIVE:
target += found
continue
if flags & MERGE_REPLACE:
try: