[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-103]

rename sftp constants
replace oddly named sftp constants (FX_OK for example) with names that make
a bit more sense when sober (SFTP_OK).
This commit is contained in:
Robey Pointer 2004-11-07 02:17:18 +00:00
parent 0ab2735dd4
commit 1c32fcd99a
3 changed files with 58 additions and 33 deletions

View File

@ -68,7 +68,6 @@ __license__ = "GNU Lesser General Public License (LGPL)"
import transport, auth_transport, channel, rsakey, dsskey, message, ssh_exception, file
import sftp, sftp_client, sftp_attr, sftp_file
# import sftp_server, sftp_si
randpool = transport.randpool
Transport = auth_transport.Transport
@ -80,10 +79,8 @@ Message = message.Message
PasswordRequiredException = ssh_exception.PasswordRequiredException
SFTP = sftp_client.SFTP
SFTPClient = sftp_client.SFTPClient
# SFTPServer = sftp_server.SFTPServer
SFTPError = sftp_client.SFTPError
SFTPAttributes = sftp_attr.SFTPAttributes
# SFTPServerInterface = sftp_si.SFTPServerInterface
ServerInterface = server.ServerInterface
SubsystemHandler = server.SubsystemHandler
SecurityOptions = transport.SecurityOptions
@ -93,8 +90,8 @@ from common import AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED, \
OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, OPEN_FAILED_CONNECT_FAILED, \
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE, OPEN_FAILED_RESOURCE_SHORTAGE
from sftp import FX_OK, FX_EOF, FX_NO_SUCH_FILE, FX_PERMISSION_DENIED, FX_FAILURE, \
FX_BAD_MESSAGE, FX_NO_CONNECTION, FX_CONNECTION_LOST, FX_OP_UNSUPPORTED
from sftp import SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, \
SFTP_BAD_MESSAGE, SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED
__all__ = [ 'Transport',
'SecurityOptions',
@ -107,10 +104,8 @@ __all__ = [ 'Transport',
'PasswordRequiredException',
'SFTP',
'SFTPClient',
# 'SFTPServer',
'SFTPError',
'SFTPAttributes',
# 'SFTPServerInterface',
'ServerInterface',
'BufferedFile',
'transport',
@ -122,10 +117,8 @@ __all__ = [ 'Transport',
'message',
'ssh_exception',
'sftp_client',
# 'sftp_server',
'sftp_attr',
'sftp_file',
# 'sftp_si',
'server',
'file',
'util' ]

View File

@ -31,30 +31,62 @@ CMD_INIT, CMD_VERSION, CMD_OPEN, CMD_CLOSE, CMD_READ, CMD_WRITE, CMD_LSTAT, CMD_
CMD_STATUS, CMD_HANDLE, CMD_DATA, CMD_NAME, CMD_ATTRS = range(101, 106)
CMD_EXTENDED, CMD_EXTENDED_REPLY = range(200, 202)
FX_OK = 0
FX_EOF, FX_NO_SUCH_FILE, FX_PERMISSION_DENIED, FX_FAILURE, FX_BAD_MESSAGE, \
FX_NO_CONNECTION, FX_CONNECTION_LOST, FX_OP_UNSUPPORTED = range(1, 9)
SFTP_OK = 0
SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, SFTP_BAD_MESSAGE, \
SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED = range(1, 9)
FX_DESC = [ 'Success',
'End of file',
'No such file',
'Permission denied',
'Failure',
'Bad message',
'No connection',
'Connection lost',
'Operation unsupported' ]
SFTP_DESC = [ 'Success',
'End of file',
'No such file',
'Permission denied',
'Failure',
'Bad message',
'No connection',
'Connection lost',
'Operation unsupported' ]
FXF_READ = 0x1
FXF_WRITE = 0x2
FXF_APPEND = 0x4
FXF_CREATE = 0x8
FXF_TRUNC = 0x10
FXF_EXCL = 0x20
SFTP_FLAG_READ = 0x1
SFTP_FLAG_WRITE = 0x2
SFTP_FLAG_APPEND = 0x4
SFTP_FLAG_CREATE = 0x8
SFTP_FLAG_TRUNC = 0x10
SFTP_FLAG_EXCL = 0x20
_VERSION = 3
# for debugging
CMD_NAMES = {
CMD_INIT: 'init',
CMD_VERSION: 'version',
CMD_OPEN: 'open',
CMD_CLOSE: 'close',
CMD_READ: 'read',
CMD_WRITE: 'write',
CMD_LSTAT: 'lstat',
CMD_FSTAT: 'fstat',
CMD_SETSTAT: 'setstat',
CMD_FSETSTAT: 'fsetstat',
CMD_OPENDIR: 'opendir',
CMD_READDIR: 'readdir',
CMD_REMOVE: 'remove',
CMD_MKDIR: 'mkdir',
CMD_RMDIR: 'rmdir',
CMD_REALPATH: 'realpath',
CMD_STAT: 'stat',
CMD_RENAME: 'rename',
CMD_READLINK: 'readlink',
CMD_SYMLINK: 'symlink',
CMD_STATUS: 'status',
CMD_HANDLE: 'handle',
CMD_DATA: 'data',
CMD_NAME: 'name',
CMD_ATTRS: 'attrs',
CMD_EXTENDED: 'extended',
CMD_EXTENDED_REPLY: 'extended_reply'
}
class SFTPError (Exception):
pass

View File

@ -134,13 +134,13 @@ class SFTPClient (BaseSFTP):
"""
imode = 0
if ('r' in mode) or ('+' in mode):
imode |= FXF_READ
imode |= SFTP_FLAG_READ
if ('w' in mode) or ('+' in mode):
imode |= FXF_WRITE
imode |= SFTP_FLAG_WRITE
if ('w' in mode):
imode |= FXF_CREATE | FXF_TRUNC
imode |= SFTP_FLAG_CREATE | SFTP_FLAG_TRUNC
if ('a' in mode):
imode |= FXF_APPEND
imode |= SFTP_FLAG_APPEND
attrblock = SFTPAttributes()
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
if t != CMD_HANDLE:
@ -382,9 +382,9 @@ class SFTPClient (BaseSFTP):
"""
code = msg.get_int()
text = msg.get_string()
if code == FX_OK:
if code == SFTP_OK:
return
elif code == FX_EOF:
elif code == SFTP_EOF:
raise EOFError(text)
else:
raise IOError(text)