def open(self, filename, mode="<STR_LIT:r>", bufsize=-<NUM_LIT:1>):
filename = self._adjust_cwd(filename)<EOL>self._log(DEBUG, "<STR_LIT>".format(filename, mode))<EOL>imode = <NUM_LIT:0><EOL>if ("<STR_LIT:r>" in mode) or ("<STR_LIT:+>" in mode):<EOL><INDENT>imode |= SFTP_FLAG_READ<EOL><DEDENT>if ("<STR_LIT:w>" in mode) or ("<STR_LIT:+>" in mode) or ("<STR_LIT:a>" in mode):<EOL><INDENT>imode |= SFTP_FLAG_WRITE<EOL><DEDENT>if "<STR_LIT:w>" in mode:<EOL><INDENT>imode |= SFTP_FLAG_CREATE | SFTP_FLAG_TRUNC<EOL><DEDENT>if "<STR_LIT:a>" in mode:<EOL><INDENT>imode |= SFTP_FLAG_CREATE | SFTP_FLAG_APPEND<EOL><DEDENT>if "<STR_LIT:x>" in mode:<EOL><INDENT>imode |= SFTP_FLAG_CREATE | SFTP_FLAG_EXCL<EOL><DEDENT>attrblock = SFTPAttributes()<EOL>t, msg = self._request(CMD_OPEN, filename, imode, attrblock)<EOL>if t != CMD_HANDLE:<EOL><INDENT>raise SFTPError("<STR_LIT>")<EOL><DEDENT>handle = msg.get_binary()<EOL>self._log(<EOL>DEBUG,<EOL>"<STR_LIT>".format(<EOL>filename, mode, u(hexlify(handle))<EOL>),<EOL>)<EOL>return SFTPFile(self, handle, mode, bufsize)<EOL>
Open a file on the remote server.  The arguments are the same as for
Python's built-in `python:file` (aka `python:open`).  A file-like
object is returned, which closely mimics the behavior of a normal
Python file object, including the ability to be used as a context
manager.

The mode indicates how the file is to be opened: ``'r'`` for reading,
``'w'`` for writing (truncating an existing file), ``'a'`` for
appending, ``'r+'`` for reading/writing, ``'w+'`` for reading/writing
(truncating an existing file), ``'a+'`` for reading/appending.  The
Python ``'b'`` flag is ignored, since SSH treats all files as binary.
The ``'U'`` flag is supported in a compatible way.

Since 1.5.2, an ``'x'`` flag indicates that the operation should only
succeed if the file was created and did not previously exist.  This has
no direct mapping to Python's file flags, but is commonly known as the
``O_EXCL`` flag in posix.

The file will be buffered in standard Python style by default, but
can be altered with the ``bufsize`` parameter.  ``0`` turns off
buffering, ``1`` uses line buffering, and any number greater than 1
(``>1``) uses that specific buffer size.

:param str filename: name of the file to open
:param str mode: mode (Python-style) to open in
:param int bufsize: desired buffering (-1 = default buffer size)
:return: an `.SFTPFile` object representing the open file

:raises: ``IOError`` -- if the file could not be opened.