Did I find the right examples for you? yes no

All Samples(16)  |  Call(14)  |  Derive(0)  |  Import(2)
Filter

:param ava: An attribute value assertion as a dictionary
:param required: list of RequestedAttribute instances defined to be 
    required
:param optional: list of RequestedAttribute instances defined to be
    optional
:return: The modified attribute value assertion

        def filter_on_attributes(ava, required=None, optional=None):
    """ Filter
    
    :param ava: An attribute value assertion as a dictionary
    :param required: list of RequestedAttribute instances defined to be 
        required
    :param optional: list of RequestedAttribute instances defined to be
        optional
    :return: The modified attribute value assertion
    """
    res = {}
    
    if required is None:
        required = []

    for attr in required:
        found = False
        nform = ""
        for nform in ["friendly_name", "name"]:
            try:
                _fn = _match(attr[nform], ava)
            except KeyError:
                pass
            else:
                if _fn:
                    try:
                        values = [av["text"] for av in attr["attribute_value"]]
                    except KeyError:
                        values = []
                    res[_fn] = _filter_values(ava[_fn], values, True)
                    found = True
                    break

        if not found:
            raise MissingValue("Required attribute missing: '%s'" % (
                attr[nform],))

    if optional is None:
        optional = []

    for attr in optional:
        for nform in ["friendly_name", "name"]:
            if nform in attr:
                _fn = _match(attr[nform], ava)
                if _fn:
                    try:
                        values = [av["text"] for av in attr["attribute_value"]]
                    except KeyError:
                        values = []
                    try:
                        res[_fn].extend(_filter_values(ava[_fn], values))
                    except KeyError:
                        res[_fn] = _filter_values(ava[_fn], values)
    
    return res
        


src/p/y/pysaml2-2.0.0/tests/test_20_assertion.py   pysaml2(Download)
from saml2.assertion import Policy
from saml2.assertion import Assertion
from saml2.assertion import filter_on_attributes
from saml2.assertion import filter_attribute_value_assertions
from saml2.assertion import from_local
    ava = {"serialNumber": ["12345"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]
    ava = {"serialNumber": ["12345"], "givenName": ["Lars"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]
    ava = {"serialNumber": ["12345"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]
    ava = {"serialNumber": ["12345", "54321"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]

src/p/y/pysaml2-HEAD/tests/test_20_assertion.py   pysaml2(Download)
from saml2.assertion import Policy
from saml2.assertion import Assertion
from saml2.assertion import filter_on_attributes
from saml2.assertion import filter_attribute_value_assertions
from saml2.assertion import from_local
    ava = {"serialNumber": ["12345"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]
    ava = {"serialNumber": ["12345"], "givenName": ["Lars"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]
    ava = {"serialNumber": ["12345"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]
    ava = {"serialNumber": ["12345", "54321"]}
 
    ava = filter_on_attributes(ava, required)
    assert ava.keys() == ["serialNumber"]
    assert ava["serialNumber"] == ["12345"]