def stream_error(self, name, text=None, exc=None):
        """Send a stream-level error and close the connection.  Errors
        have this basic format:

            <stream:error>
              <{{ name }} xmlns="urn:ietf:params:xml:ns:xmpp-streams" />
              <text xml:lang="en" "urn:ietf:params:xml:ns:xmpp-streams">
                {{ text }}
              </text>
            </stream:error>

        See: <http://xmpp.org/rfcs/rfc3920.html#rfc.section.4.7.3>
        """

        try:
            log.error('Stream Error: %s %r' % (name, text), exc_info=bool(exc))
            with self.state.clear().lock():
                self.open_stream()
                elem = self.E(self.ERROR, self.E(name, xmlns=self.ERROR_NS))
                if text is not None:
                    elem.append(self.E.text(
                        { self.LANG: 'en', 'xmlns': self.ERROR_NS},
                        text
                    ))
                self.write(elem)
        except:
            log.exception('Exception while reporting stream error.')
        try:
            self.close()
        except:
            log.exception('Exception while closing')

        return self
dataset/ETHPy150Open HenryHu/pybbs/xmpp/core.py/Core.stream_error/original