Exemplo n.º 1
0
def json_matching_statuses(json_file_or_str, statuses):
    """
    Filter statuses by json dict in file or fragment; return list of
    matching statuses.  json_file_or_str must be a file containing
    json or json in a string.
    """
    try:
        open(json_file_or_str, 'r')
    except IOError:
        query = json.loads(json_file_or_str)
    else:
        query = json.load(json_file_or_str)

    if not isinstance(query, dict):
        raise RuntimeError('--json-query must be a dict')

    return_statuses = list()
    for status in statuses:
        for k, v in query.iteritems():
            if not misc.is_in_dict(k, v, status):
                break
        else:
            return_statuses.append(status)

    return return_statuses
Exemplo n.º 2
0
def json_matching_statuses(json_file_or_str, statuses):
    """
    Filter statuses by json dict in file or fragment; return list of
    matching statuses.  json_file_or_str must be a file containing
    json or json in a string.
    """
    try:
        open(json_file_or_str, 'r')
    except IOError:
        query = json.loads(json_file_or_str)
    else:
        query = json.load(json_file_or_str)

    if not isinstance(query, dict):
        raise RuntimeError('--json-query must be a dict')

    return_statuses = list()
    for status in statuses:
        for k, v in query.items():
            if not misc.is_in_dict(k, v, status):
                break
        else:
            return_statuses.append(status)

    return return_statuses
Exemplo n.º 3
0
 def test_dict_membership(self):
     assert misc.is_in_dict('a', {
         'sub1': 'key1',
         'sub2': 'key2'
     }, {'a': {
         'sub1': 'key1',
         'sub2': 'key2',
         'sub3': 'key3'
     }})
Exemplo n.º 4
0
 def test_nonmembership_with_presence_at_lower_level(self):
     assert not misc.is_in_dict('a', 'foo', {'a': {'a': 'foo'}})
Exemplo n.º 5
0
 def test_simple_nonmembership(self):
     assert not misc.is_in_dict('a', 'foo', {'a': 'bar', 'b': 'foo'})