code: def filter_on_demands(ava, required=None, optional=None):
      
  
      # Is all what's required there:
      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()])
  
      # OK, so I can imaging releasing values that are not absolutely necessary
      # but not attributes that are not asked for.
      for attr in lava.keys():
          if attr not in oka:
              del ava[lava[attr]]
  
      return ava
docs: Never return more than is needed. Filters out everything
      the server is prepared to return but the receiver doesn't ask for
  
      :param ava: Attribute value assertion as a dictionary
      :param required: Required attributes
      :param optional: Optional attributes
      :return: The possibly reduced assertion