
import copy

class Message(object):
    def __init__(self, backend, caller=None, text=None):
        self._backend = backend
        self.caller = caller
        self.text = text
        
        # initialize some empty attributes
        self.received = None
        self.sent = None
        self.responses = []
    
    def __unicode__(self):
        return self.text

    @property
    def backend(self):
        # backend is read-only, since it's an
        # immutable property of this object
        return self._backend
    
    def send(self):
        """Send this message via self.backend, returning
           True if the message was sent successfully."""
        return self.backend.router.outgoing(self)

    def flush_responses (self):
        for response in self.responses:
            response.send()

    def respond(self, text):
        """Send the given text back to the original caller of this
           message on the same route that it came in on"""
        if self.caller: 
            response = copy.copy(self)
            response.text = text
            self.responses.append(response)
            return True
        else: 
            return False


import copy

class Message(object):
    def __init__(self, backend, caller=None, text=None):
        self._backend = backend
        self.caller = caller
        self.text = text
        self.responses = []
    
    def __unicode__(self):
        return self.text

    @property
    def backend(self):
        # backend is read-only, since it's an
        # immutable property of this object
        return self._backend
    
    def send(self):
        """Send this message via self.backend, returning
           True if the message was sent successfully."""
        return self.backend.router.outgoing(self)

    def flush_responses (self):
        for response in self.responses:
            response.send()
            self.responses.remove(response)

    def respond(self, text):
        """Send the given text back to the original caller of this
           message on the same route that it came in on"""
        if self.caller: 
            response = copy.copy(self)
            response.text = text
            self.responses.append(response)
            return True
        else: 
            return False

Remove unused attributes; also, empty responses after it's flushed.
Remove unused attributes; also, empty responses after it's flushed.

  
  import copy
  
  class Message(object):
      def __init__(self, backend, caller=None, text=None):
          self._backend = backend
          self.caller = caller
          self.text = text
-         
-         # initialize some empty attributes
-         self.received = None
-         self.sent = None
          self.responses = []
      
      def __unicode__(self):
          return self.text
  
      @property
      def backend(self):
          # backend is read-only, since it's an
          # immutable property of this object
          return self._backend
      
      def send(self):
          """Send this message via self.backend, returning
             True if the message was sent successfully."""
          return self.backend.router.outgoing(self)
  
      def flush_responses (self):
          for response in self.responses:
              response.send()
+             self.responses.remove(response)
  
      def respond(self, text):
          """Send the given text back to the original caller of this
             message on the same route that it came in on"""
          if self.caller: 
              response = copy.copy(self)
              response.text = text
              self.responses.append(response)
              return True
          else: 
              return False
  
Remove unused attributes; also, empty responses after it's flushed.
## Code Before:

import copy

class Message(object):
    def __init__(self, backend, caller=None, text=None):
        self._backend = backend
        self.caller = caller
        self.text = text
        
        # initialize some empty attributes
        self.received = None
        self.sent = None
        self.responses = []
    
    def __unicode__(self):
        return self.text

    @property
    def backend(self):
        # backend is read-only, since it's an
        # immutable property of this object
        return self._backend
    
    def send(self):
        """Send this message via self.backend, returning
           True if the message was sent successfully."""
        return self.backend.router.outgoing(self)

    def flush_responses (self):
        for response in self.responses:
            response.send()

    def respond(self, text):
        """Send the given text back to the original caller of this
           message on the same route that it came in on"""
        if self.caller: 
            response = copy.copy(self)
            response.text = text
            self.responses.append(response)
            return True
        else: 
            return False

## Instruction:
Remove unused attributes; also, empty responses after it's flushed.
## Code After:

import copy

class Message(object):
    def __init__(self, backend, caller=None, text=None):
        self._backend = backend
        self.caller = caller
        self.text = text
        self.responses = []
    
    def __unicode__(self):
        return self.text

    @property
    def backend(self):
        # backend is read-only, since it's an
        # immutable property of this object
        return self._backend
    
    def send(self):
        """Send this message via self.backend, returning
           True if the message was sent successfully."""
        return self.backend.router.outgoing(self)

    def flush_responses (self):
        for response in self.responses:
            response.send()
            self.responses.remove(response)

    def respond(self, text):
        """Send the given text back to the original caller of this
           message on the same route that it came in on"""
        if self.caller: 
            response = copy.copy(self)
            response.text = text
            self.responses.append(response)
            return True
        else: 
            return False
