def filter_on_demands(ava, required=None, optional=None):
 if (required is None):
  required = {}
 lava = dict([(k.lower(), k) for k in ava.keys()])
 for (attr, vals) in required.items():
  attr = attr.lower()
  if (attr in lava):
   if vals:
    for val in vals:
     if (val not in ava[lava[attr]]):
      raise MissingValue(('Required attribute value missing: %s,%s' % (attr, val)))
  else:
   raise MissingValue(('Required attribute missing: %s' % (attr,)))
 if (optional is None):
  optional = {}
 oka = [k.lower() for k in required.keys()]
 oka.extend([k.lower() for k in optional.keys()])
 for attr in lava.keys():
  if (attr not in oka):
   del ava[lava[attr]]
 return ava

def filter_on_demands ( ava , required = None , optional = None ) : if ( required is None ) : required = { } lava = dict ( [ ( k . lower ( ) , k ) for k in ava . keys ( ) ] ) for ( attr , vals ) in required . items ( ) : attr = attr . lower ( ) if ( attr in lava ) : if vals : for val in vals : if ( val not in ava [ lava [ attr ] ] ) : raise MissingValue ( ( 'Required attribute value missing: %s,%s' % ( attr , val ) ) ) else : raise MissingValue ( ( 'Required attribute missing: %s' % ( attr , ) ) ) if ( optional is None ) : optional = { } oka = [ k . lower ( ) for k in required . keys ( ) ] oka . extend ( [ k . lower ( ) for k in optional . keys ( ) ] ) for attr in lava . keys ( ) : if ( attr not in oka ) : del ava [ lava [ attr ] ] return ava
never return more than is needed .