def write(self, data):
if self._closed:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>if not (self._flags & self.FLAG_WRITE):<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>if not (self._flags & self.FLAG_BUFFERED):<EOL><INDENT>self._write_all(data)<EOL>return<EOL><DEDENT>self._wbuffer.write(data)<EOL>if self._flags & self.FLAG_LINE_BUFFERED:<EOL><INDENT>last_newline_pos = data.rfind('<STR_LIT:\n>')<EOL>if last_newline_pos >= <NUM_LIT:0>:<EOL><INDENT>wbuf = self._wbuffer.getvalue()<EOL>last_newline_pos += len(wbuf) - len(data)<EOL>self._write_all(wbuf[:last_newline_pos + <NUM_LIT:1>])<EOL>self._wbuffer = StringIO()<EOL>self._wbuffer.write(wbuf[last_newline_pos + <NUM_LIT:1>:])<EOL><DEDENT>return<EOL><DEDENT>if self._wbuffer.tell() >= self._bufsize:<EOL><INDENT>self.flush()<EOL><DEDENT>return<EOL>
Write data to the file.  If write buffering is on (C{bufsize} was
specified and non-zero), some or all of the data may not actually be
written yet.  (Use L{flush} or L{close} to force buffered data to be
written out.)

@param data: data to write.
@type data: str