U
    7ÓdB   ã                   @   s:   d dl Z d dlZd dlmZmZmZmZ G dd„ dƒZdS )é    N)Ú	x80000000Úo700Úo70Ú	xffffffffc                   @   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 )ÚSFTPAttributesai  
    Representation of the attributes of a file (or proxied file) for SFTP in
    client or server mode.  It attempts 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   úT/var/www/html/alexa-login-pro/venv/lib/python3.8/site-packages/paramiko/sftp_attr.pyÚ__init__1   s    zSFTPAttributes.__init__Nc                 C   sH   | ƒ }|j |_ |j|_|j|_|j|_|j|_|j|_|dk	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__S   s    zSFTPAttributes.__repr__c                 C   s0   | ƒ }|  |¡ |d k	r||_|d k	r,||_|S ©N)Ú_unpackr   Úlongname)r   Úmsgr   r!   r   r   r   r   Ú	_from_msgW   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| ¡ < q’d 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    a   s    






zSFTPAttributes._unpackc                 C   s|  d| _ | jd k	r |  j | jO  _ | jd k	rD| jd k	rD|  j | jO  _ | jd k	r^|  j | jO  _ | jd k	r‚| j	d k	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_int64ÚintÚitemsZ
add_string)r   r"   ÚkeyÚvalr   r   r   Ú_packr   s8    


zSFTPAttributes._packc                 C   sÂ   d}| j d k	r|d | j ¡7 }| jd k	rF| jd k	rF|d | j| j¡7 }| jd k	rf|dt| jƒ d 7 }| jd k	rŽ| jd k	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stickyr6   r   r   r   Ú_rwx    s    zSFTPAttributes._rwxc           	      C   s¬  | j dk	rðt | 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r†d}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ks| jtkrd}n>t | j¡}tt ¡ | j ƒdkrDt d|¡}nt d|¡}t| dd	ƒ}| j}| j}| j}|dkr|d}|dkrŠd}|dkr˜d}d||||||f S )z=create a unix-style long description of the file (like ls -l)NÚpÚcÚdÚbú-Ú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   ÚtimeÚ	localtimeÚabsÚstrftimeÚgetattrr   r   r   )	r   ÚkindÚksZdatestrZ
time_tupler   ÚuidÚgidÚsizer   r   r   Ú__str__«   sn    







 
ÿ 
ÿ 
 ÿ


úzSFTPAttributes.__str__c                 C   s   t | ƒ ¡ S r   )r5   Úencoder   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    r1   r   Ústaticmethodr:   r\   r^   r   r   r   r   r      s&   	
Cr   )rF   rR   Zparamiko.commonr   r   r   r   r   r   r   r   r   Ú<module>   s   