code: def normalize_tag(tag):
      
      if isinstance(tag, str):
          namespace_uri, sep, localname = tag.partition("}")
          if sep:
              if not namespace_uri.startswith("{"):
                  raise ValueError("not a valid etree-format tag")
              namespace_uri = namespace_uri[1:]
          else:
              localname = namespace_uri
              namespace_uri = None
          return (namespace_uri, localname)
      elif len(tag) != 2:
          raise ValueError("not a valid tuple-format tag")
      else:
          if any(part is not None and not isinstance(part, str) for part in tag):
              raise TypeError("tuple-format tags must only contain str and None")
          if tag[1] is None:
              raise ValueError("tuple-format localname must not be None")
      return tag
docs: Normalize an XML element tree `tag` into the tuple format. The following
      input formats are accepted:
  
      * ElementTree namespaced string, e.g. ``{uri:bar}foo``
      * Unnamespaced tags, e.g. ``foo``
      * Two-tuples consisting of `namespace_uri` and `localpart`; `namespace_uri`
        may be :data:`None` if the tag is supposed to be namespaceless. Otherwise
        it must be, like `localpart`, a :class:`str`.
  
      Return a two-tuple consisting the ``(namespace_uri, localpart)`` format.