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_fold(thing):
'''
Given a thing, count paths with fold.
'''
def f(o, p, a):
a[0] += 1
[count] = api.fold(thing, f, [0])
assert count == len(tuple(api.walk(thing)))
return (matched and not afilter) or (matched and selected)
if yielded:
def yielder():
for segments, found in dpath.segments.walk(obj):
if keeper(segments, found):
yield (separator.join(map(dpath.segments.int_str, segments)), found)
return yielder()
else:
def f(obj, pair, result):
(segments, found) = pair
if keeper(segments, found):
dpath.segments.set(result, segments, found, hints=dpath.segments.types(obj, segments))
return dpath.segments.fold(obj, f, {})
not found, KeyError is raised.
'''
if glob == '/':
return obj
globlist = __safe_path__(glob, separator)
def f(obj, pair, results):
(segments, found) = pair
if dpath.segments.match(segments, globlist):
results.append(found)
if len(results) > 1:
return False
results = dpath.segments.fold(obj, f, [])
if len(results) == 0:
raise KeyError(glob)
elif len(results) > 1:
raise ValueError("dpath.util.get() globs must match only one leaf : %s" % glob)
return results[0]