def write(self, offset, data):
writefile = getattr(self, "<STR_LIT>", None)<EOL>if writefile is None:<EOL><INDENT>return SFTP_OP_UNSUPPORTED<EOL><DEDENT>try:<EOL><INDENT>if (self.__flags & os.O_APPEND) == <NUM_LIT:0>:<EOL><INDENT>if self.__tell is None:<EOL><INDENT>self.__tell = writefile.tell()<EOL><DEDENT>if offset != self.__tell:<EOL><INDENT>writefile.seek(offset)<EOL>self.__tell = offset<EOL><DEDENT><DEDENT>writefile.write(data)<EOL>writefile.flush()<EOL><DEDENT>except IOError as e:<EOL><INDENT>self.__tell = None<EOL>return SFTPServer.convert_errno(e.errno)<EOL><DEDENT>if self.__tell is not None:<EOL><INDENT>self.__tell += len(data)<EOL><DEDENT>return SFTP_OK<EOL>
Write ``data`` into this file at position ``offset``.  Extending the
file past its original end is expected.  Unlike Python's normal
``write()`` methods, this method cannot do a partial write: it must
write all of ``data`` or else return an error.

The default implementation checks for an attribute on ``self`` named
``writefile``, and if present, performs the write operation on the
Python file-like object found there.  The attribute is named
differently from ``readfile`` to make it easy to implement read-only
(or write-only) files, but if both attributes are present, they should
refer to the same file.

:param offset: position in the file to start reading from.
:param str data: data to write into the file.
:return: an SFTP error code like ``SFTP_OK``.