@@ -78,52 +78,53 @@ def filter_on_attributes(ava, required=None, optional=None, acs=None,
78
78
:return: The modified attribute value assertion
79
79
"""
80
80
81
- def _attr_name (attr ):
82
- """Get the friendly name of an attribute name"""
81
+ def _match_attr_name (attr , ava ):
83
82
try :
84
- return attr ["friendly_name" ]
83
+ friendly_name = attr ["friendly_name" ]
85
84
except KeyError :
86
- return get_local_name (acs , attr ["name" ], attr ["name_format" ])
85
+ friendly_name = get_local_name (acs , attr ["name" ], attr ["name_format" ])
86
+
87
+ _fn = _match (friendly_name , ava )
88
+ if not _fn : # In the unlikely case that someone has provided us with URIs as attribute names
89
+ _fn = _match (attr ["name" ], ava )
90
+
91
+ return _fn
92
+
93
+ def _apply_attr_value_restrictions (attr , res , must = False ):
94
+ try :
95
+ values = [av ["text" ] for av in attr ["attribute_value" ]]
96
+ except KeyError :
97
+ values = []
98
+
99
+ try :
100
+ res [_fn ].extend (_filter_values (ava [_fn ], values ))
101
+ except KeyError :
102
+ res [_fn ] = _filter_values (ava [_fn ], values )
103
+
104
+ return _filter_values (ava [_fn ], values , must )
87
105
88
106
res = {}
89
107
90
108
if required is None :
91
109
required = []
92
110
93
111
for attr in required :
94
- _name = _attr_name (attr )
95
- _fn = _match (_name , ava )
96
- if not _fn : # In the unlikely case that someone has provided us
97
- # with URIs as attribute names
98
- _fn = _match (attr ["name" ], ava )
112
+ _fn = _match_attr_name (attr , ava )
99
113
100
114
if _fn :
101
- try :
102
- values = [av ["text" ] for av in attr ["attribute_value" ]]
103
- except KeyError :
104
- values = []
105
- res [_fn ] = _filter_values (ava [_fn ], values , True )
106
- continue
115
+ _apply_attr_value_restrictions (attr , res , True )
107
116
elif fail_on_unfulfilled_requirements :
108
117
desc = "Required attribute missing: '%s' (%s)" % (attr ["name" ],
109
- _name )
118
+ _fn )
110
119
raise MissingValue (desc )
111
120
112
121
if optional is None :
113
122
optional = []
114
123
115
124
for attr in optional :
116
- _name = _attr_name (attr )
117
- _fn = _match (_name , ava )
125
+ _fn = _match_attr_name (attr , ava )
118
126
if _fn :
119
- try :
120
- values = [av ["text" ] for av in attr ["attribute_value" ]]
121
- except KeyError :
122
- values = []
123
- try :
124
- res [_fn ].extend (_filter_values (ava [_fn ], values ))
125
- except KeyError :
126
- res [_fn ] = _filter_values (ava [_fn ], values )
127
+ _apply_attr_value_restrictions (attr , res , False )
127
128
128
129
return res
129
130
0 commit comments