patch from wesley augur: expose the 'longname' field from listdir_attr().
This commit is contained in:
Robey Pointer 2007-05-20 15:56:22 -07:00
parent 920b172360
commit 3229cd0f94
2 changed files with 10 additions and 3 deletions

View File

@ -90,11 +90,13 @@ class SFTPAttributes (object):
### internals... ### internals...
def _from_msg(cls, msg, filename=None): def _from_msg(cls, msg, filename=None, longname=None):
attr = cls() attr = cls()
attr._unpack(msg) attr._unpack(msg)
if filename is not None: if filename is not None:
attr.filename = filename attr.filename = filename
if longname is not None:
attr.longname = longname
return attr return attr
_from_msg = classmethod(_from_msg) _from_msg = classmethod(_from_msg)

View File

@ -114,7 +114,7 @@ class SFTPClient (BaseSFTP):
""" """
self._log(INFO, 'sftp session closed.') self._log(INFO, 'sftp session closed.')
self.sock.close() self.sock.close()
def listdir(self, path='.'): def listdir(self, path='.'):
""" """
Return a list containing the names of the entries in the given C{path}. Return a list containing the names of the entries in the given C{path}.
@ -136,6 +136,11 @@ class SFTPClient (BaseSFTP):
files in the given C{path}. The list is in arbitrary order. It does files in the given C{path}. The list is in arbitrary order. It does
not include the special entries C{'.'} and C{'..'} even if they are not include the special entries C{'.'} and C{'..'} even if they are
present in the folder. present in the folder.
The returned L{SFTPAttributes} objects will each have an additional
field: C{longname}, which may contain a formatted string of the file's
attributes, in unix format. The content of this string will probably
depend on the SFTP server implementation.
@param path: path to list (defaults to C{'.'}) @param path: path to list (defaults to C{'.'})
@type path: str @type path: str
@ -163,7 +168,7 @@ class SFTPClient (BaseSFTP):
for i in range(count): for i in range(count):
filename = _to_unicode(msg.get_string()) filename = _to_unicode(msg.get_string())
longname = _to_unicode(msg.get_string()) longname = _to_unicode(msg.get_string())
attr = SFTPAttributes._from_msg(msg, filename) attr = SFTPAttributes._from_msg(msg, filename, longname)
if (filename != '.') and (filename != '..'): if (filename != '.') and (filename != '..'):
filelist.append(attr) filelist.append(attr)
self._request(CMD_CLOSE, handle) self._request(CMD_CLOSE, handle)