How to use the dpath.segments.match function in dpath

To help you get started, we’ve selected a few dpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akesterson / dpath-python / tests / test_segments.py View on Github external
def test_match_nonmatching(pair):
    '''
    Given segments and a known bad glob, match should be False.
    '''
    (segments, glob) = pair
    assert api.match(segments, glob) is False
github akesterson / dpath-python / tests / test_segments.py View on Github external
def test_match(pair):
    '''
    Given segments and a known good glob, match should be True.
    '''
    (segments, glob) = pair
    assert api.match(segments, glob) is True
github akesterson / dpath-python / dpath / util.py View on Github external
def keeper(segments, found):
        '''
        Generalized test for use in both yielded and folded cases.
        Returns True if we want this result. Otherwise returns False.
        '''
        if not dirs and not dpath.segments.leaf(found):
            return False

        matched = dpath.segments.match(segments, globlist)
        selected = afilter and afilter(found)

        return (matched and not afilter) or (matched and selected)
github akesterson / dpath-python / dpath / util.py View on Github external
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
github akesterson / dpath-python / dpath / util.py View on Github external
def f(obj, pair, results):
        (segments, found) = pair

        if dpath.segments.match(segments, globlist):
            results.append(found)
        if len(results) > 1:
            return False
github akesterson / dpath-python / dpath / util.py View on Github external
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
                    # remaining items.
                    #
                    # Note: In order to achieve proper behavior we are