'Read and return \'n\' bytes from the buffer.
If \'n\' is negative, read and return the whole buffer.
If \'n\' is larger than the size of the buffer, read and return
the whole buffer.'

def read(self, n=(-1)):

    with self.data_lock:
        if ((n < 0) or (n > len(self.buffer))):
            the_whole_buffer = self.buffer
            self.buffer = bytes('')
            return the_whole_buffer
        data = self.buffer[:n]
        self.buffer = self.buffer[n:]
        return data
