code: def to_frame(self, data, state):
          
  
          # Find the next packet start
          if not state.frame_start:
              # Find the begin sequence
              idx = data.find(self.begin)
              if idx < 0:
                  # Couldn't find one
                  raise exc.NoFrames()
  
              # Excise the begin sequence
              del data[:idx + len(self.begin)]
  
          # Now see if we can find the end sequence
          idx = data.find(self.end)
          if idx < 0:
              # We've found the start, but don't have the end yet
              state.frame_start = True
              raise exc.NoFrames()
  
          # Extract the frame
          frame = six.binary_type(data[:idx])
          del data[:idx + len(self.end)]
  
          # Update the state
          state.frame_start = False
  
          # Unstuff the frame and return it
          return self.prefix.join(frame.split(self.nop))
docs: Extract a single frame from the data buffer.  The consumed
          data should be removed from the buffer.  If no complete frame
          can be read, must raise a ``NoFrames`` exception.
  
          :param data: A ``bytearray`` instance containing the data so
                       far read.
          :param state: An instance of ``FramerState``.  If the buffer
                        contains a partial frame, this object can be
                        used to store state information to allow the
                        remainder of the frame to be read.
  
          :returns: A frame.  The frame may be any object.  The stock
                    framers always return bytes.