a
   IsZ@                   @   sL   d dl Z d dlZd dlmZmZmZmZ d dlmZm	Z	 G dd de
ZdS )    N)	x80000000o700o70	xffffffff)longbc                   @   s   e Zd ZdZdZdZdZdZeZ	dd Z
edd	d
Zdd ZedddZdd Zdd Zdd ZedddZdd Zdd ZdS )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``.
                c                 C   s4   d| _ d| _d| _d| _d| _d| _d| _i | _dS )zX
        Create a new (empty) SFTPAttributes object.  All fields will be empty.
        r   N)_flagsst_sizest_uidst_gidst_modest_atimest_mtimeattrself r   6/usr/lib/python3.9/site-packages/paramiko/sftp_attr.py__init__2   s    zSFTPAttributes.__init__Nc                 C   sH   |  }|j |_ |j|_|j|_|j|_|j|_|j|_|du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)r   r   r   r   r   r   filename)clsobjr   r   r   r   r   	from_stat?   s    
zSFTPAttributes.from_statc                 C   s   d |  S )Nz<SFTPAttributes: {}>)format
_debug_strr   r   r   r   __repr__T   s    zSFTPAttributes.__repr__c                 C   s0   |  }| | |d ur||_|d ur,||_|S N)_unpackr   longname)r   msgr   r#   r   r   r   r   	_from_msgX   s    
zSFTPAttributes._from_msgc                 C   s   |  | _| j| j@ r | | _| j| j@ r@|  | _|  | _| j| j@ rV|  | _	| j| j
@ rv|  | _|  | _| j| j@ r|  }t|D ]}| | j| < qd S r!   )Zget_intr   	FLAG_SIZEZ	get_int64r   FLAG_UIDGIDr   r   FLAG_PERMISSIONSr   FLAG_AMTIMEr   r   FLAG_EXTENDEDrangeZ
get_stringr   )r   r$   countir   r   r   r"   b   s    






zSFTPAttributes._unpackc                 C   s|  d| _ | jd ur |  j | jO  _ | jd urD| jd urD|  j | jO  _ | jd ur^|  j | jO  _ | jd ur| j	d ur|  j | j
O  _ t| jdkr|  j | jO  _ || j  | j | j@ r|| j | j | j@ r|| j || j | j | j@ r|| j | j | j
@ r0|t| j |t| j	 | j | j@ rx|t| j | j D ]\}}|| || qXd S )Nr   )r   r   r&   r   r   r'   r   r(   r   r   r)   lenr   r*   Zadd_intZ	add_int64r   itemsZ
add_string)r   r$   keyvalr   r   r   _packs   s8    


zSFTPAttributes._packc                 C   s   d}| j d ur|d| j 7 }| jd urF| jd urF|d| j| j7 }| jd urf|dt| j d 7 }| jd ur| jd ur|d| j| j7 }| j	 D ]\}}|dt
||7 }q|d7 }|S )	Nz[ zsize={} zuid={} gid={} zmode= zatime={} mtime={} z
"{}"={!r} ])r   r   r   r   r   octr   r   r   r/   str)r   outkvr   r   r   r      s    

zSFTPAttributes._debug_strFc                 C   sV   |rd}d| d?  d| d? d@   }|r>|d|| d@   7 }n|d|| d@   7 }|S )Nr
   z-rz-wr	   z-xTtz-xSsr   )nZsuidZstickyr7   r   r   r   _rwx   s    zSFTPAttributes._rwxc                 C   s  | j durt| j }|tjkr&d}nd|tjkr6d}nT|tjkrFd}nD|tjkrVd}n4|tjkrfd}n$|tjkrvd}n|tj	krd}nd	}|| 
| j t@ d
? | j tj@ 7 }|| 
| j t@ d? | j tj@ 7 }|| 
| j d@ | j tj@ d7 }nd}| jdu s| jtkrd}nBtt | j dkr@tdt| j}ntdt| j}t| dd	}| j}| j}| j}|du rd}|du rd}|du rd}d||||||f S )z=create a unix-style long description of the file (like ls -l)Npcdr   -ls?         Tz
?---------z(unknown date)i N z%d %b %Yz%d %b %H:%Mr   r   z%s   1 %-8d %-8d %8d %-12s %s)r   statS_IFMTS_IFIFOS_IFCHRS_IFDIRS_IFBLKS_IFREGS_IFLNKS_IFSOCKr;   r   S_ISUIDr   S_ISGIDS_ISVTXr   r   abstimestrftime	localtimegetattrr   r   r   )r   kindksZdatestrr   uidgidsizer   r   r   __str__   sl    










zSFTPAttributes.__str__c                 C   s   t t| S r!   )r   r6   r   r   r   r   asbytes   s    zSFTPAttributes.asbytes)N)NN)F)__name__
__module____qualname____doc__r&   r'   r(   r)   r   r*   r   classmethodr   r    r%   r"   r2   r   staticmethodr;   r\   r]   r   r   r   r   r      s&   	
Fr   )rF   rS   Zparamiko.commonr   r   r   r   Zparamiko.py3compatr   r   objectr   r   r   r   r   <module>   s   