docs: def rootAuthority(xri):
      """Return the root authority for an XRI.
  
      Example::
  
          rootAuthority("xri://@example") == "xri://@"
  
      @type xri: unicode
      @returntype: unicode
      """
      if xri.startswith('xri://'):
          xri = xri[6:]
      authority = xri.split('/', 1)[0]
      if authority[0] == '(':
          # Cross-reference.
          # XXX: This is incorrect if someone nests cross-references so there
          #   is another close-paren in there.  Hopefully nobody does that
          #   before we have a real xriparse function.  Hopefully nobody does
          #   that *ever*.
          root = authority[:authority.index(')') + 1]
      elif authority[0] in XRI_AUTHORITIES:
          # Other XRI reference.
          root = authority[0]
      else:
          # IRI reference.  XXX: Can IRI authorities have segments?
          segments = authority.split('!')
          segments = reduce(list.__add__,
              map(lambda s: s.split('*'), segments))
          root = segments[0]
  
      return XRI(root)