def open(self, filename, mode='<STR_LIT:r>', bufsize=-<NUM_LIT:1>):
filename = self._adjust_cwd(filename)<EOL>self._log(DEBUG, '<STR_LIT>' % (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_string()<EOL>self._log(DEBUG, '<STR_LIT>' % (filename, mode, hexlify(handle)))<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 C{file} (aka C{open}).  A file-like object is
returned, which closely mimics the behavior of a normal python file
object.

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

Since 1.5.2, an C{'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
C{O_EXCL} flag in posix.

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

@param filename: name of the file to open
@type filename: str
@param mode: mode (python-style) to open in
@type mode: str
@param bufsize: desired buffering (-1 = default buffer size)
@type bufsize: int
@return: a file object representing the open file
@rtype: SFTPFile

@raise IOError: if the file could not be opened.