o
    ÞÜgB   ã                   @   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   úL/var/www/html/api-tag/env/lib/python3.10/site-packages/paramiko/sftp_attr.pyÚ__init__1   s   
zSFTPAttributes.__init__Nc                 C   sH   | ƒ }|j |_ |j|_|j|_|j|_|j|_|j|_|dur"||_|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 ur||_|d u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@ r+|  ¡ | _	| j| j
@ r;|  ¡ | _|  ¡ | _| j| j@ rU|  ¡ }t|ƒD ]}| ¡ | j| ¡ < qId S d S r   )Úget_intr   Ú	FLAG_SIZEÚ	get_int64r   ÚFLAG_UIDGIDr   r   ÚFLAG_PERMISSIONSr   ÚFLAG_AMTIMEr   r   ÚFLAG_EXTENDEDÚrangeÚ
get_stringr   )r   r"   ÚcountÚir   r   r   r    a   s"   






ýzSFTPAttributes._unpackc                 C   st  d| _ | jd ur|  j | jO  _ | jd ur"| jd ur"|  j | jO  _ | jd ur/|  j | jO  _ | jd urA| j	d urA|  j | j
O  _ t| jƒdkrP|  j | jO  _ | | j ¡ | j | j@ rb| | j¡ | j | j@ rt| | j¡ | | j¡ | j | j@ r€| | j¡ | j | j
@ r–| t| jƒ¡ | t| j	ƒ¡ | j | j@ r¸| t| jƒ¡ | j ¡ D ]\}}| |¡ | |¡ q©d S )Nr   )r   r   r%   r   r   r'   r   r(   r   r   r)   Úlenr   r*   Úadd_intÚ	add_int64ÚintÚitemsÚ
add_string)r   r"   ÚkeyÚvalr   r   r   Ú_packr   s8   


zSFTPAttributes._packc                 C   sÂ   d}| j d ur|d | j ¡7 }| jd ur#| jd ur#|d | j| j¡7 }| jd ur3|dt| jƒ d 7 }| jd urG| jd urG|d | j| j¡7 }| j 	¡ D ]\}}|d t
|ƒ|¡7 }qL|d7 }|S )	Nz[ zsize={} zuid={} gid={} zmode=ú zatime={} mtime={} z
"{}"={!r} ú])r   r   r   r   r   Úoctr   r   r   r3   Ústr)r   ÚoutÚkÚvr   r   r   r   ‘   s   

zSFTPAttributes._debug_strFc                 C   sX   |rd}d| d?  d| d? d@   }|r |d|| d@   7 }|S |d|| d@   7 }|S )Nr   z-rz-wr   z-xTtz-xSsr   )ÚnÚsuidÚstickyr<   r   r   r   Ú_rwx    s   ÿzSFTPAttributes._rwxc           	      C   s   | j durxt | j ¡}|tjkrd}n2|tjkrd}n*|tjkr#d}n"|tjkr+d}n|tjkr3d}n|tjkr;d}n
|tj	krCd}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}nt | j¡}tt ¡ | j ƒdkrŸt d|¡}nt d|¡}t| dd	ƒ}| j}| j}| j}|du rºd}|du rÀd}|du 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_IFSOCKrB   r   ÚS_ISUIDr   ÚS_ISGIDÚS_ISVTXr   r   ÚtimeÚ	localtimeÚabsÚstrftimeÚgetattrr   r   r   )	r   ÚkindÚksÚdatestrÚ
time_tupler   ÚuidÚgidÚsizer   r   r   Ú__str__«   sf   







ÿÿÿúzSFTPAttributes.__str__c                 C   s   t | ƒ ¡ S r   )r;   Úencoder   r   r   r   Úasbytesî   s   zSFTPAttributes.asbytesr   )NN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r'   r(   r)   r   r*   r   Úclassmethodr   r   r#   r    r7   r   ÚstaticmethodrB   rf   rh   r   r   r   r   r      s(    	
Cr   )rN   rZ   Úparamiko.commonr   r   r   r   r   r   r   r   r   Ú<module>   s   