code: def serialize_md_inst(self, md_inst, md_class):
          
          valid_insts = tuple(
              chain((etree._ElementTree, etree._Element), six.string_types)
          )
          if isinstance(md_inst, valid_insts):
              return md_inst
          if not isinstance(md_inst, md_class):
              raise TypeError(
                  "Instance {!r} must be instance of {!r}".format(md_inst, md_class)
              )
          return md_inst.serialize()
docs: Serialize object ``md_inst`` by transforming it into an
          ``lxml.etree._ElementTree``. If it already is such, return it. If not,
          make sure it is the correct type and return the output of calling
          ``seriaize()`` on it.