<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def resume_sm(self, xmlstream):
 """ Resume an SM-enabled stream using the given `xmlstream`. If the server rejects the attempt to resume stream management, a :class:`.errors.StreamNegotiationFailure` is raised. The stream is then in stopped state and stream management has been stopped. .. warning:: This method cannot and does not check whether the server advertised support for stream management. Attempting to negotiate stream management without server support might lead to termination of the stream. If the XML stream dies at any point during the negotiation, the SM state is left unchanged. If no response has been received yet, the exception which caused the stream to die is re-raised. The state of the stream depends on whether the main task already noticed the dead stream. If negotiation succeeds, this coroutine resumes the stream management session and initiates the retransmission of any unacked stanzas. The stream is then in running state. .. versionchanged:: 0.11 Support for using the counter value provided some servers on a failed resumption was added. Stanzas which are covered by the counter will be marked as :attr:`~StanzaState.ACKED`; other stanzas will be marked as :attr:`~StanzaState.DISCONNECTED`. This is in contrast to the behaviour when resumption fails *without* a counter given. In that case, stanzas which have not been acked are marked as :attr:`~StanzaState.SENT_WITHOUT_SM`. """


        if self.running:
            raise RuntimeError("Cannot resume Stream Management while"
                               " StanzaStream is running")

        self._start_prepare(xmlstream, self.recv_stanza)
        try:
            response = yield from protocol.send_and_wait_for(
                xmlstream,
                [
                    nonza.SMResume(previd=self.sm_id,
                                   counter=self._sm_inbound_ctr)
                ],
                [
                    nonza.SMResumed,
                    nonza.SMFailed
                ]
            )

            if isinstance(response, nonza.SMFailed):
                exc = errors.StreamNegotiationFailure(
                    "Server rejected SM resumption"
                )

                if response.counter is not None:
                    self.sm_ack(response.counter)
                    self._clear_unacked(StanzaState.DISCONNECTED)

                xmlstream.stanza_parser.remove_class(
                    nonza.SMRequest)
                xmlstream.stanza_parser.remove_class(
                    nonza.SMAcknowledgement)
                self.stop_sm()
                raise exc

            self._resume_sm(response.counter)
        except:  # NOQA
            self._start_rollback(xmlstream)
            raise
        self._start_commit(xmlstream)