code: def parseXRDS(text):
      
      try:
          # lxml prefers to parse bytestrings, and occasionally chokes on a
          # combination of text strings and declared XML encodings -- see
          # https://github.com/necaris/python3-openid/issues/19
          # To avoid this, we ensure that the 'text' we're parsing is actually
          # a bytestring
          bytestring = text.encode('utf8') if isinstance(text, str) else text
          element = SafeElementTree.XML(bytestring)
      except (SystemExit, MemoryError, AssertionError, ImportError):
          raise
      except Exception as why:
          exc = XRDSError('Error parsing document as XML')
          exc.reason = why
          raise exc
      else:
          tree = ElementTree.ElementTree(element)
          if not isXRDS(tree):
              raise XRDSError('Not an XRDS document')
  
          return tree
docs: Parse the given text as an XRDS document.
  
      @return: ElementTree containing an XRDS document
  
      @raises XRDSError: When there is a parse error or the document does
          not contain an XRDS.