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_has(node):
'''
Given a node, has should return True for all paths, False otherwise.
'''
for k, v in api.walk(node):
assert api.has(node, k) is True
# If we are at a leaf, then we can create a value that isn't
# present easily.
if api.leaf(v):
assert api.has(node, k + (0,)) is False
def test_has(node):
'''
Given a node, has should return True for all paths, False otherwise.
'''
for k, v in api.walk(node):
assert api.has(node, k) is True
# If we are at a leaf, then we can create a value that isn't
# present easily.
if api.leaf(v):
assert api.has(node, k + (0,)) is False
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 merger(dst, src, _segments=()):
for key, found in dpath.segments.kvs(src):
# Our current path in the source.
segments = _segments + (key,)
if len(key) == 0 and not options.ALLOW_EMPTY_STRING_KEYS:
raise InvalidKeyName("Empty string keys not allowed without "
"dpath.options.ALLOW_EMPTY_STRING_KEYS=True: "
"{}".format(segments))
# Validate src and dst types match.
if flags & MERGE_TYPESAFE:
if dpath.segments.has(dst, segments):
target = dpath.segments.get(dst, segments)
tt = type(target)
ft = type(found)
if tt != ft:
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)
def f(obj, pair, counter):
(segments, value) = 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(value) and afilter(value)
if (matched and not afilter) or selected:
key = segments[-1]
parent = dpath.segments.get(obj, segments[:-1])
try:
# Attempt to treat parent like a sequence.
parent[0]
if len(parent) - 1 == key:
# Removing the last element of a sequence. It can be
# truly removed without affecting the ordering of