def filter_attribute_value_assertions(ava, attribute_restrictions=None):
 if (not attribute_restrictions):
  return ava
 for (attr, vals) in ava.items():
  _attr = attr.lower()
  try:
   _rests = attribute_restrictions[_attr]
  except KeyError:
   del ava[attr]
  else:
   if (_rests is None):
    continue
   if isinstance(vals, basestring):
    vals = [vals]
   rvals = []
   for restr in _rests:
    for val in vals:
     if restr.match(val):
      rvals.append(val)
   if rvals:
    ava[attr] = list(set(rvals))
   else:
    del ava[attr]
 return ava

def filter_attribute_value_assertions ( ava , attribute_restrictions = None ) : if ( not attribute_restrictions ) : return ava for ( attr , vals ) in ava . items ( ) : _attr = attr . lower ( ) try : _rests = attribute_restrictions [ _attr ] except KeyError : del ava [ attr ] else : if ( _rests is None ) : continue if isinstance ( vals , basestring ) : vals = [ vals ] rvals = [ ] for restr in _rests : for val in vals : if restr . match ( val ) : rvals . append ( val ) if rvals : ava [ attr ] = list ( set ( rvals ) ) else : del ava [ attr ] return ava
will weed out attribute values and values according to the rules defined in the attribute restrictions .