o
    r¨Êhh,  ã                	   @   sè   d dl mZ G dd„ dƒZd dlZd dlZd dlZdd„ ZG dd„ dƒZejd	kr9G d
d„ deƒZ	G dd„ deƒZ
G dd„ deƒZG dd„ dƒZdd„ Zdd„ Zg d¢ZdddddddddœZd dlZd d!„ Zd"d#„ ZG d$d%„ d%ƒZdS )&é    )Úlongc                   @   s^   e Zd Zdd„ Zdd„ Zddd„Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )Úabstract_filesystemc                 C   ó   d S ©N© ©Úselfr   r   úK/var/www/html/env/lib/python3.10/site-packages/supervisor/medusa/filesys.pyÚ__init__   ó   zabstract_filesystem.__init__c                 C   ó   dS )z3Return a string representing the current directory.Nr   r   r   r   r	   Úcurrent_directory   ó   z%abstract_filesystem.current_directoryr   c                 C   r   )z»Return a listing of the directory at 'path' The empty string
        indicates the current directory.  If 'long' is set, instead
        return a list of (name, stat_info) tuples
        Nr   ©r   Úpathr   r   r   r	   Úlistdir   s   zabstract_filesystem.listdirc                 C   r   )zReturn an open file objectNr   )r   r   Úmoder   r   r	   Úopen"   r   zabstract_filesystem.openc                 C   r   )z5Return the equivalent of os.stat() on the given path.Nr   ©r   r   r   r   r	   Ústat&   r   zabstract_filesystem.statc                 C   r   )z$Does the path represent a directory?Nr   r   r   r   r	   Úisdir*   r   zabstract_filesystem.isdirc                 C   r   )z%Does the path represent a plain file?Nr   r   r   r   r	   Úisfile.   r   zabstract_filesystem.isfilec                 C   r   )zChange the working directory.Nr   r   r   r   r	   Úcwd2   r   zabstract_filesystem.cwdc                 C   r   )z.Change to the parent of the current directory.Nr   r   r   r   r	   Úcdup6   r   zabstract_filesystem.cdupc                 C   r   )z[Return a 'long' representation of the filename
        [for the output of the LIST command]Nr   r   r   r   r	   Úlongify;   s   zabstract_filesystem.longifyN©r   )Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r   r   r   r   r   r   r   r   r   r	   r      s    
r   Nc                 C   s   z| t  | ¡fW S    Y d S r   )Úosr   )r   r   r   r	   Ú	safe_statN   s   r    c                   @   s¢   e Zd ZejZdZd'dd„Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ Zd(dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&S ))Úos_filesystemé   ú/c                 C   ó   || _ || _d S r   ©ÚrootÚwd)r   r&   r'   r   r   r	   r
   [   ó   
zos_filesystem.__init__c                 C   s   | j S r   )r'   r   r   r   r	   r   _   s   zos_filesystem.current_directoryc                 C   ó(   |   | j | j|¡¡}| j |  |¡¡S r   )Ú	normalizeÚpath_moduleÚjoinr'   r   Ú	translate©r   r   Úpr   r   r	   r   b   ó   zos_filesystem.isfilec                 C   r)   r   )r*   r+   r,   r'   r   r-   r.   r   r   r	   r   f   r0   zos_filesystem.isdirc              	   C   s†   |   | j | j|¡¡}|  |¡}| j |¡sdS t ¡ }d}zzt |¡ d}|| _W n   Y W |r8t |¡ |S |rBt |¡ w w )Nr   r"   )	r*   r+   r,   r'   r-   r   r   ÚgetcwdÚchdir)r   r   r/   Útranslated_pathÚold_dirÚcanr   r   r	   r   j   s(   


€
þÿzos_filesystem.cwdc                 C   s
   |   d¡S )Nz..)r   r   r   r   r	   r   €   s   
zos_filesystem.cdupr   c              	   C   sp   |   |¡}t |¡}|st|d ƒS t ¡ }zt |¡ dd„ tt|ƒD ƒ}W t |¡ nt |¡ w t|| jƒS )Nc                 S   s   g | ]}|r|‘qS r   r   )Ú.0Ú_fr   r   r	   Ú
<listcomp>�   ó    z)os_filesystem.listdir.<locals>.<listcomp>)	r-   r   r   Úlist_producerr1   r2   Úmapr    r   )r   r   r   r/   Úldr4   Úresultr   r   r	   r   ƒ   s   



zos_filesystem.listdirc                 C   ó   |   |¡}t |¡S r   )r-   r   r   r.   r   r   r	   r   •   ó   

zos_filesystem.statc                 C   s   |   |¡}t||ƒS r   )r-   r   )r   r   r   r/   r   r   r	   r   ™   r?   zos_filesystem.openc                 C   r>   r   )r-   r   Úunlinkr.   r   r   r	   r@   �   r?   zos_filesystem.unlinkc                 C   r>   r   )r-   r   Úmkdirr.   r   r   r	   rA   ¡   r?   zos_filesystem.mkdirc                 C   r>   r   )r-   r   Úrmdirr.   r   r   r	   rB   ¥   r?   zos_filesystem.rmdirc                 C   s   t  |  |¡|  |¡¡S r   )r   Úrenamer-   )r   ÚsrcÚdstr   r   r	   rC   ©   s   zos_filesystem.renamec                 C   s>   t  dd|¡}| j |¡}t|ƒdkr|d d… dkrd}|S )Nz/+r#   é   é   z/..)ÚreÚsubr+   ÚnormpathÚlenr.   r   r   r	   r*   ­   s
   zos_filesystem.normalizec                 C   sJ   t j | d¡¡}|  | j | j|¡¡}|  | j | j|dd … ¡¡}|S )Nr#   r"   )r   Úsepr,   Úsplitr*   r+   r'   r&   r.   r   r   r	   r-   ¶   s   zos_filesystem.translatec                 C   ó   |\}}t ||ƒS r   )Úunix_longify©r   Úpath_stat_info_tupler   Ú	stat_infor   r   r	   r   À   ó   
zos_filesystem.longifyc                 C   s   d| j | jf S )Nz<unix-style fs root:%s wd:%s>r%   r   r   r   r	   Ú__repr__Ä   s   þzos_filesystem.__repr__N)r#   r   )r   r   r   r   r   r+   Údo_globbingr
   r   r   r   r   r   r   r   r   r@   rA   rB   rC   r*   r-   r   rT   r   r   r   r	   r!   T   s(    

	
r!   Úposixc                   @   s   e Zd ZdS )Úunix_filesystemN)r   r   r   r   r   r   r	   rW   Ì   s    rW   c                   @   sh   e Zd Ze ¡ Ze ¡ Ze ¡ Z	e 
¡ Zddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zddd„ZdS )Úschizophrenic_unix_filesystemr#   ©NNc                 C   s   t  | ||¡ || _d S r   )r!   r
   Úpersona)r   r&   r'   rZ   r   r   r	   r
   Õ   s   
z&schizophrenic_unix_filesystem.__init__c                 C   s0   | j dkr| j \}}t |¡ t |¡ d S d S ©NrY   )rZ   r   ÚsetegidÚseteuid)r   ÚuidÚgidr   r   r	   Úbecome_personaÙ   s
   


üz,schizophrenic_unix_filesystem.become_personac                 C   s*   | j dkrt | j¡ t | j¡ d S d S r[   )rZ   r   r]   ÚPROCESS_UIDr\   ÚPROCESS_GIDr   r   r   r	   Úbecome_nobodyà   s   
þz+schizophrenic_unix_filesystem.become_nobodyc                 C   s*   z|   ¡  t | |¡W |  ¡  S |  ¡  w r   )r`   r!   r   rc   r   r   r   r	   r   æ   s   z!schizophrenic_unix_filesystem.cwdc                 C   s(   z|   ¡  t | ¡W |  ¡  S |  ¡  w r   )r`   r!   r   rc   r   r   r   r	   r   í   s   
z"schizophrenic_unix_filesystem.cdupc                 C   ó,   z|   ¡  t | ||¡W |  ¡  S |  ¡  w r   )r`   r!   r   rc   )r   Úfilenamer   r   r   r	   r   ô   ó   z"schizophrenic_unix_filesystem.openr   c                 C   rd   r   )r`   r!   r   rc   r   r   r   r	   r   û   rf   z%schizophrenic_unix_filesystem.listdirN)r#   rY   r   )r   r   r   r   Úgetuidra   ÚgeteuidÚPROCESS_EUIDÚgetgidrb   ÚgetegidÚPROCESS_EGIDr
   r`   rc   r   r   r   r   r   r   r   r	   rX   Ï   s    
rX   c                   @   ó   e Zd Zdd„ ZdS )Úmsdos_filesystemc                 C   rN   r   )Úmsdos_longifyrP   r   r   r	   r     rS   zmsdos_filesystem.longifyN)r   r   r   r   r   r   r   r	   rn     ó    rn   c                   @   rm   )Úmerged_filesystemc                 G   r   r   r   )r   Úfsysr   r   r	   r
     r   zmerged_filesystem.__init__N)r   r   r   r
   r   r   r   r	   rq     rp   rq   c                 C   s>   t  |t j ¡rd}nd}t|t j ƒ}d|||t j | f S )Nz<DIR>z     z%s       %s %8d %s)r   ÚS_ISDIRÚST_MODEÚ
msdos_dateÚST_MTIMEÚST_SIZE)ÚfilerR   ÚdirÚdater   r   r	   ro     s   üro   c                 C   sl   zt  | ¡}W n	   t  d¡}Y |d }|dkr d}|d8 }nd}d|d |d	 |d d
 ||d |f S )Nr   rG   é   ÚPMé   ÚAMz%02d-%02d-%02d  %02d:%02d%sr"   rF   éd   é   )ÚtimeÚgmtime)ÚtÚinfoÚhourÚmeridr   r   r	   ru   '  s"   

úru   )ÚJanÚFebÚMarÚAprÚMayÚJunÚJulÚAugÚSepÚOctÚNovÚDecz---z--xz-w-z-wxzr--zr-xzrw-Úrwx)Ú0Ú1Ú2Ú3Ú4Ú5Ú6Ú7c              	   C   sŒ   d|t j  dd … }d dd„ |D ƒ¡}t  |t j ¡r d}nd}ttt ¡ ƒ|t j ƒ}d|||t j |t j	 |t j
 |t j || f S )	Nz%oéýÿÿÿÚ c                 S   s   g | ]}t | ‘qS r   )Ú
mode_table)r6   Úxr   r   r	   r8   O  r9   z unix_longify.<locals>.<listcomp>Údú-z%s%s %3d %-8d %-8d %8d %s %s)r   rt   r,   rs   Úls_dater   r�   rv   ÚST_NLINKÚST_UIDÚST_GIDrw   )rx   rR   r   Údircharrz   r   r   r	   rO   L  s    ørO   c                 C   sx   zt  |¡}W n	   t  d¡}Y | | dkr(dt|d d  |d |d f S dt|d d  |d |d |d f S )	Nr   i€	î z
%s %2d  %dr"   rF   z%s %2d %02d:%02drG   r€   )r�   r‚   Úmonths)Únowrƒ   r„   r   r   r	   r¢   g  s    ýür¢   c                   @   s   e Zd Zddd„Zdd„ ZdS )r:   Nc                 C   r$   r   )ÚlistÚfunc)r   r©   rª   r   r   r	   r
   €  r(   zlist_producer.__init__c                 C   sL   | j sdS | j d d… }| jd urt| j|ƒ}| j dd … | _ d |¡d S )Nr�   é2   z
)r©   rª   r;   r,   )r   Úbunchr   r   r	   Úmore…  s   
zlist_producer.morer   )r   r   r   r
   r­   r   r   r   r	   r:     s    
r:   )Úsupervisor.compatr   r   r   r   rH   r    r!   ÚnamerW   rX   rn   rq   ro   ru   r§   rž   r�   rO   r¢   r:   r   r   r   r	   Ú<module>   s8   7
v7ø