3 L] @sLddlZddlZddlmZmZmZmZddlmZm Z Gddde Z dS)N) x80000000o700o70 xffffffff)longbc@seZdZdZdZdZdZdZeZ ddZ e dd d Z d d Z e dd dZddZddZddZedddZddZddZdS)SFTPAttributesah 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 `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 ``attr``. Occasionally, the filename is also stored, in ``filename``. cCs4d|_d|_d|_d|_d|_d|_d|_i|_dS)zX Create a new (empty) SFTPAttributes object. All fields will be empty. rN)_flagsst_sizest_uidst_gidst_modest_atimest_mtimeattr)selfr8/tmp/pip-install-wfra5znf/paramiko/paramiko/sftp_attr.py__init__2szSFTPAttributes.__init__NcCsH|}|j|_|j|_|j|_|j|_|j|_|j|_|dk rD||_|S)a` 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. N)rrrrrrfilename)clsobjrrrrr from_stat?s zSFTPAttributes.from_statcCsdj|jS)Nz)format _debug_str)rrrr__repr__TszSFTPAttributes.__repr__cCs0|}|j||dk r||_|dk r,||_|S)N)_unpackrlongname)rmsgrr!rrrr _from_msgXs zSFTPAttributes._from_msgcCs|j|_|j|j@r |j|_|j|j@r@|j|_|j|_|j|j@rV|j|_ |j|j @rv|j|_ |j|_ |j|j @r|j}x"t|D]}|j|j|j<qWdS)N)Zget_intr FLAG_SIZEZ get_int64r FLAG_UIDGIDrrFLAG_PERMISSIONSr FLAG_AMTIMErr FLAG_EXTENDEDrangeZ get_stringr)rr"countirrrr bs            zSFTPAttributes._unpackcCsd|_|jdk r |j|jO_|jdk rD|jdk rD|j|jO_|jdk r^|j|jO_|jdk r|j dk r|j|j O_t |j dkr|j|j O_|j|j|j|j@r|j|j|j|j@r|j|j|j|j|j|j@r|j|j|j|j @r0|jt|j|jt|j |j|j @r||jt |j x,|j jD]\}}|j||j|qZWdS)Nr)r rr$rrr%rr&rrr'lenrr(Zadd_intZ add_int64ritemsZ add_string)rr"keyvalrrr_packss8          zSFTPAttributes._packcCsd}|jdk r|dj|j7}|jdk rF|jdk rF|dj|j|j7}|jdk rf|dt|jd7}|jdk r|jdk r|dj|j|j7}x*|jj D]\}}|djt ||7}qW|d7}|S) Nz[ zsize={} zuid={} gid={} zmode= zatime={} mtime={} z "{}"={!r} ]) rrrrroctrrrr-str)routkvrrrrs  zSFTPAttributes._debug_strFcCsV|rd}d|d?d|d?d@}|r>|d||d@7}n|d||d@7}|S)Nr z-rz-wr z-xTtz-xSsr)nZsuidZstickyr5rrr_rwxszSFTPAttributes._rwxcCs|jdk rtj|j}|tjkr&d}nd|tjkr6d}nT|tjkrFd}nD|tjkrVd}n4|tjkrfd}n$|tjkrvd}n|tj krd}nd }||j |jt @d ?|jtj @7}||j |jt @d ?|jtj@7}||j |jd @|jtj@d 7}nd}|jdks |jtkrd}nBttj|jdkr@tjdtj|j}ntjdtj|j}t|dd }|j}|j}|j}|dkrd}|dkrd}|dkrd}d||||||fS)z=create a unix-style long description of the file (like ls -l)Npcdr-ls?Tz ?---------z(unknown date)iNz%d %b %Yz %d %b %H:%Mrrz%s 1 %-8d %-8d %8d %-12s %s)rstatS_IFMTS_IFIFOS_IFCHRS_IFDIRS_IFBLKS_IFREGS_IFLNKS_IFSOCKr9rS_ISUIDrS_ISGIDS_ISVTXrrabstimestrftime localtimegetattrrrr)rkindksZdatestrruidgidsizerrr__str__s`             zSFTPAttributes.__str__cCs tt|S)N)rr4)rrrrasbytesszSFTPAttributes.asbytes)N)NN)F)__name__ __module__ __qualname____doc__r$r%r&r'rr(r classmethodrrr#r r0r staticmethodr9rZr[rrrrrs&    Fr) rDrQZparamiko.commonrrrrZparamiko.py3compatrrobjectrrrrrs