code: def from_dict(val, onts, mdb_safe=False):
      
      if isinstance(val, dict):
          if "__class__" in val:
              ns, typ = val["__class__"].split("&")
              cls = getattr(onts[ns], typ)
              if cls is md.Extensions:
                  lv = []
                  for key, ditems in val.items():
                      if key in EXP_SKIP:
                          continue
                      for item in ditems:
                          ns, typ = item["__class__"].split("&")
                          cls = getattr(onts[ns], typ)
                          kwargs = _kwa(item, onts, mdb_safe)
                          inst = cls(**kwargs)
                          lv.append(element_to_extension_element(inst))
                  return lv
              else:
                  kwargs = _kwa(val, onts, mdb_safe)
                  inst = cls(**kwargs)
              return inst
          else:
              res = {}
              for key, v in val.items():
                  if mdb_safe:
                      key = key.replace("__", ".")
                  res[key] = from_dict(v, onts)
              return res
      elif isinstance(val, six.string_types):
          return val
      elif isinstance(val, list):
          return [from_dict(v, onts) for v in val]
      else:
          return val
docs: Converts a dictionary into a pysaml2 object
      :param val: A dictionary
      :param onts: Dictionary of schemas to use in the conversion
      :return: The pysaml2 object instance