diff options
author | Jeremy T. Bouse <jbouse@debian.org> | 2014-05-11 22:30:26 -0400 |
---|---|---|
committer | Jeremy T. Bouse <jbouse@debian.org> | 2014-05-11 22:30:26 -0400 |
commit | 56d4b9be3ecb1f4dc6fd6c081d58286e323955b7 (patch) | |
tree | 4929cbf73c8bb4f4d896f67f23afdcd4463c784e /paramiko/sftp_attr.py | |
parent | 5552efae3b0075cca67430a0be5b352f3a256475 (diff) | |
parent | 4e426087436d01fe00a120e5e7ce7a5e0a1e0970 (diff) | |
download | python-paramiko-56d4b9be3ecb1f4dc6fd6c081d58286e323955b7.tar python-paramiko-56d4b9be3ecb1f4dc6fd6c081d58286e323955b7.tar.gz |
Merge tag 'upstream/1.14.0'
Upstream version 1.14.0
Diffstat (limited to 'paramiko/sftp_attr.py')
-rw-r--r-- | paramiko/sftp_attr.py | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/paramiko/sftp_attr.py b/paramiko/sftp_attr.py index b459b04..d12eff8 100644 --- a/paramiko/sftp_attr.py +++ b/paramiko/sftp_attr.py @@ -18,33 +18,34 @@ import stat import time -from paramiko.common import * -from paramiko.sftp import * +from paramiko.common import x80000000, o700, o70, xffffffff +from paramiko.py3compat import long, b class SFTPAttributes (object): """ Representation of the attributes of a file (or proxied file) for SFTP in client or server mode. It attemps to mirror the object returned by - C{os.stat} as closely as possible, so it may have the following fields, - with the same meanings as those returned by an C{os.stat} object: - - st_size - - st_uid - - st_gid - - st_mode - - st_atime - - st_mtime + `os.stat` as closely as possible, so it may have the following fields, + with the same meanings as those returned by an `os.stat` object: + + - ``st_size`` + - ``st_uid`` + - ``st_gid`` + - ``st_mode`` + - ``st_atime`` + - ``st_mtime`` Because SFTP allows flags to have other arbitrary named attributes, these - are stored in a dict named C{attr}. Occasionally, the filename is also - stored, in C{filename}. + are stored in a dict named ``attr``. Occasionally, the filename is also + stored, in ``filename``. """ FLAG_SIZE = 1 FLAG_UIDGID = 2 FLAG_PERMISSIONS = 4 FLAG_AMTIME = 8 - FLAG_EXTENDED = 0x80000000L + FLAG_EXTENDED = x80000000 def __init__(self): """ @@ -61,15 +62,12 @@ class SFTPAttributes (object): def from_stat(cls, obj, filename=None): """ - Create an SFTPAttributes object from an existing C{stat} object (an - object returned by C{os.stat}). - - @param obj: an object returned by C{os.stat} (or equivalent). - @type obj: object - @param filename: the filename associated with this file. - @type filename: str - @return: new L{SFTPAttributes} object with the same attribute fields. - @rtype: L{SFTPAttributes} + Create an `.SFTPAttributes` object from an existing ``stat`` object (an + object returned by `os.stat`). + + :param object obj: an object returned by `os.stat` (or equivalent). + :param str filename: the filename associated with this file. + :return: new `.SFTPAttributes` object with the same attribute fields. """ attr = cls() attr.st_size = obj.st_size @@ -86,10 +84,8 @@ class SFTPAttributes (object): def __repr__(self): return '<SFTPAttributes: %s>' % self._debug_str() - ### internals... - def _from_msg(cls, msg, filename=None, longname=None): attr = cls() attr._unpack(msg) @@ -143,7 +139,7 @@ class SFTPAttributes (object): msg.add_int(long(self.st_mtime)) if self._flags & self.FLAG_EXTENDED: msg.add_int(len(self.attr)) - for key, val in self.attr.iteritems(): + for key, val in self.attr.items(): msg.add_string(key) msg.add_string(val) return @@ -158,7 +154,7 @@ class SFTPAttributes (object): out += 'mode=' + oct(self.st_mode) + ' ' if (self.st_atime is not None) and (self.st_mtime is not None): out += 'atime=%d mtime=%d ' % (self.st_atime, self.st_mtime) - for k, v in self.attr.iteritems(): + for k, v in self.attr.items(): out += '"%s"=%r ' % (str(k), v) out += ']' return out @@ -175,7 +171,7 @@ class SFTPAttributes (object): _rwx = staticmethod(_rwx) def __str__(self): - "create a unix-style long description of the file (like ls -l)" + """create a unix-style long description of the file (like ls -l)""" if self.st_mode is not None: kind = stat.S_IFMT(self.st_mode) if kind == stat.S_IFIFO: @@ -194,13 +190,13 @@ class SFTPAttributes (object): ks = 's' else: ks = '?' - ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID) - ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID) + ks += self._rwx((self.st_mode & o700) >> 6, self.st_mode & stat.S_ISUID) + ks += self._rwx((self.st_mode & o70) >> 3, self.st_mode & stat.S_ISGID) ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) else: ks = '?---------' # compute display date - if (self.st_mtime is None) or (self.st_mtime == 0xffffffffL): + if (self.st_mtime is None) or (self.st_mtime == xffffffff): # shouldn't really happen datestr = '(unknown date)' else: @@ -221,3 +217,5 @@ class SFTPAttributes (object): return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, self.st_size, datestr, filename) + def asbytes(self): + return b(str(self)) |