def write(self, data):
    assert isinstance(data, text_type)
    self._buffer.append(data.encode(self._encoding))
    self.flush()
def write(self, data):
    assert isinstance(data, text_type)
    self._buffer.append(data.encode(self._encoding))
    self.flush()