o
    Óó·iü/  ã                   @  s*  d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZmZmZm Z m!Z!m"Z" d
Z#ede$e%ƒZ&ede$e%ƒZ'eddd�Z(eeeƒG dd„ dee'e&f ee' ƒƒƒZ)G dd„ de)e
e
f ƒZ*ddgZ+dS )zt
This module contains implementations of L{IFilePath} for zip files.

See the constructor of L{ZipArchive} for use.
é    )ÚannotationsN)ÚIOÚTYPE_CHECKINGÚAnyÚAnyStrÚDictÚGenericÚIterableÚListÚTupleÚTypeVarÚUnion)ÚZipFile)Úimplementer)ÚLiteralÚSelf)ÚcmpÚ
comparable)ÚAbstractFilePathÚFilePathÚ	IFilePathÚOtherAnyStrÚUnlistableErrorÚ_coerceToFilesystemEncodingú/Ú_ArchiveStrÚ_ZipStrÚ_ZipSelfzZipPath[Any, Any])Úboundc                   @  s
  e Zd ZU dZded< dId	d
„ZdJdd„ZdKdd„ZedLdd„ƒZ	dMdd„Z
dNdd„Zer2dOdd„ZdPd d!„ZdPd"d#„ZdQd%d&„ZdQd'd(„ZdQd)d*„ZdQd+d,„ZdRd.d/„ZdSd1d2„ZdLd3d4„ZdLd5d6„ZdTdUd;d<„ZdVd=d>„ZdWd?d@„ZdXdBdC„ZdXdDdE„ZdXdFdG„ZdHS )YÚZipPathzF
    I represent a file or directory contained within a zip file.
    r   ÚpathÚarchiveúZipArchive[_ArchiveStr]ÚpathInArchiveÚreturnÚNonec                 C  sZ   || _ || _t|j|ƒ| _t|tƒ}t||jƒ}| j |¡}tjj	|g|¢R Ž }|| _dS )z½
        Don't construct me directly.  Use C{ZipArchive.child()}.

        @param archive: a L{ZipArchive} instance.

        @param pathInArchive: a ZIP_PATH_SEP-separated string.
        N)
r!   r#   r   Ú_zipfileFilenameZ_nativePathInArchiveÚZIP_PATH_SEPÚsplitÚosr    Újoin)Úselfr!   r#   ÚsepZarchiveFilenameÚsegmentsZfakePath© r.   ú\C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/python/zippath.pyÚ__init__=   s   
ÿ
ÿ
zZipPath.__init__ÚotherÚobjectÚintc                 C  s(   t |tƒstS t| j| jf|j|jfƒS ©N)Ú
isinstancer   ÚNotImplementedr   r!   r#   ©r+   r1   r.   r.   r/   Ú__cmp__W   s
   
ÿzZipPath.__cmp__Ústrc                 C  sN   t | jtj | jj¡ƒg}| | j | j¡¡ t | jtjƒ}d| 	|¡›d�S )NzZipPath(ú))
r   r,   r)   r    Úabspathr!   Úextendr#   r(   r*   )r+   ÚpartsZossepr.   r.   r/   Ú__repr__^   s
   ÿzZipPath.__repr__c                 C  s   t | jtƒS )z–
        Return a zip directory separator.

        @return: The zip directory separator.
        @returntype: The same type as C{self.path}.
        N)r   r    r'   ©r+   r.   r.   r/   r,   g   s   zZipPath.sepú=Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ArchiveStr]]c                 C  s<   | j  | j¡}t|ƒdkr| jS t| j| j |dd… ¡ƒS )zk
        Return parent, discarding our own encoding in favor of whatever the
        archive's is.
        é   Néÿÿÿÿ)r#   r(   r,   Úlenr!   r   r*   )r+   Zsplitupr.   r.   r/   Ú_nativeParentq   s   zZipPath._nativeParentú9Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ZipStr]]c                 C  s*   |   ¡ }t|tƒrtt| j| jjƒƒS |S r4   )rD   r5   Ú
ZipArchiver   r    r!   r&   )r+   Úparentr.   r.   r/   rG   }   s   
ÿzZipPath.parentúCIterable[Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ZipStr]]]c                 C  ó   d S r4   r.   r?   r.   r.   r/   Úparents‡   s   zZipPath.parentsr   ú!ZipPath[OtherAnyStr, _ArchiveStr]c                 C  s,   t |tƒ}t || jƒ}t| j| ||g¡ƒS )a&  
        Return a new ZipPath representing a path in C{self.archive} which is
        a child of this path.

        @note: Requesting the C{".."} (or other special name) child will not
            cause L{InsecurePath} to be raised since these names do not have
            any special meaning inside a zip archive.  Be particularly
            careful with the C{path} attribute (if you absolutely must use
            it) as this means it may include special names with special
            meaning outside of the context of a zip archive.
        N)r   r'   r#   r   r!   r*   )r+   r    Zjoinerr#   r.   r.   r/   ÚchildŒ   s   
zZipPath.childc                 C  s*   |   ¡ }t|tƒr| jn|}| |¡}|S r4   )rG   r5   rF   r!   rL   )r+   r    rG   ZrightTypedParentrL   r.   r.   r/   Úsiblingœ   s   
zZipPath.siblingÚboolc                 C  s   |   ¡ p|  ¡ S r4   )ÚisdirÚisfiler?   r.   r.   r/   Úexists¥   ó   zZipPath.existsc                 C  s   | j | jjv S r4   )r#   r!   Úchildmapr?   r.   r.   r/   rO   ¨   s   zZipPath.isdirc                 C  s   | j | jjjv S r4   )r#   r!   ÚzipfileÚ
NameToInfor?   r.   r.   r/   rP   «   rR   zZipPath.isfilec                 C  s   dS )NFr.   r?   r.   r.   r/   Úislink®   ó   zZipPath.islinkúList[_ZipStr]c                   s^   ˆ   ¡ r'ˆ  ¡ rtˆ jjˆ jƒ}‡ fdd„ˆ jj|  ¡ D ƒS tt	t
jdƒƒ‚tt	t
jdƒƒ‚)Nc                   s   g | ]}t ˆ j|ƒ‘qS r.   )r   r    )Ú.0Zeachr?   r.   r/   Ú
<listcomp>·   s    
ÿÿz#ZipPath.listdir.<locals>.<listcomp>zLeaf zip entry listedzNon-existent zip entry listed)rQ   rO   r   r!   r&   r#   rS   Úkeysr   ÚOSErrorÚerrnoÚENOTDIRÚENOENT)r+   ZparentArchivePathr.   r?   r/   Úlistdir±   s   
ÿ
þ
ÿzZipPath.listdirúTuple[_ZipStr, _ZipStr]c                 C  s   t j | j¡S )zQ
        Return a value similar to that returned by C{os.path.splitext}.
        N)r)   r    Úsplitextr?   r.   r.   r/   rb   Â   s   zZipPath.splitextc                 C  s   | j  | j¡d S )NrB   )r#   r(   r,   r?   r.   r.   r/   ÚbasenameË   s   zZipPath.basenamec                 C  s
   |   ¡ jS r4   )rG   r    r?   r.   r.   r/   ÚdirnameÎ   s   
zZipPath.dirnameÚrÚmodeúLiteral['r', 'w']ú	IO[bytes]c                 C  s   t d| jƒ}| jjj||d�S )NÚ )rf   )r   r#   r!   rT   Úopen)r+   rf   r#   r.   r.   r/   rj   Ó   s   zZipPath.openc                 C  rI   r4   r.   r?   r.   r.   r/   ÚchangedÚ   rW   zZipPath.changedc                 C  s   t d| jƒ}| jjj| jS )zR
        Retrieve this file's size.

        @return: file size, in bytes
        ri   N)r   r#   r!   rT   rU   Ú	file_size©r+   r#   r.   r.   r/   ÚgetsizeÝ   s   zZipPath.getsizeÚfloatc                 C  s
   | j  ¡ S )z±
        Retrieve this file's last access-time.  This is the same as the last access
        time for the archive.

        @return: a number of seconds since the epoch
        N)r!   ÚgetAccessTimer?   r.   r.   r/   rp   æ   ó   
zZipPath.getAccessTimec                 C  s&   t d| jƒ}t | jjj| jd ¡S )z¸
        Retrieve this file's last modification time.  This is the time of
        modification recorded in the zipfile.

        @return: a number of seconds since the epoch.
        ri   )r   r   r   N)r   r#   ÚtimeÚmktimer!   rT   rU   Ú	date_timerm   r.   r.   r/   ÚgetModificationTimeï   s   ÿzZipPath.getModificationTimec                 C  s   |   ¡ S )zÏ
        Retrieve this file's last modification time.  This name is provided for
        compatibility, and returns the same value as getmtime.

        @return: a number of seconds since the epoch.
        N)ru   r?   r.   r.   r/   ÚgetStatusChangeTimeû   s   zZipPath.getStatusChangeTimeN)r!   r"   r#   r   r$   r%   ©r1   r2   r$   r3   ©r$   r9   )r$   r   )r$   r@   )r$   rE   )r$   rH   )r    r   r$   rK   ©r$   rN   )r$   rX   )r$   ra   )re   )rf   rg   r$   rh   )r$   r%   )r$   r3   ©r$   ro   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r0   r8   r>   Úpropertyr,   rD   rG   r   rJ   rL   rM   rQ   rO   rP   rV   r`   rb   rc   rd   rj   rk   rn   rp   ru   rv   r.   r.   r.   r/   r   4   s8   
 


	
	




	





	



	
	r   c                   @  sx   e Zd ZU dZded< ed$dd„ƒZd%d
d„Zd&dd„Zd'dd„Z	d(dd„Z
d)dd„Zd)dd„Zd)dd„Zd*d!d"„Zd#S )+rF   aì  
    I am a L{FilePath}-like object which can wrap a zip archive as if it were a
    directory.

    It works similarly to L{FilePath} in L{bytes} and L{unicode} handling --
    instantiating with a L{bytes} will return a "bytes mode" L{ZipArchive},
    and instantiating with a L{unicode} will return a "text mode"
    L{ZipArchive}. Methods that return new L{ZipArchive} or L{ZipPath}
    instances will be in the mode of the argument to the creator method,
    converting if required.
    r   r&   r$   r   c                 C  s   | S r4   r.   r?   r.   r.   r/   r!     s   zZipArchive.archiveÚarchivePathnamer%   c                 C  sÒ   || _ ttd|ƒƒ| _| jj}|dusJ dƒ‚t||ƒ| _t|dƒ| _i | _| j ¡ D ];}t| j |ƒ 	| j
¡}tt|ƒƒD ]#}||  }| j
 |d| … ¡}|| jvrYi | j|< d| j| |< q=t|dƒ}q+dS )zÍ
        Create a ZipArchive, treating the archive at archivePathname as a zip
        file.

        @param archivePathname: a L{bytes} or L{unicode}, naming a path in the
            filesystem.
        ri   Nz7zipfile must have filename when initialized with a pathrA   )r    r   r   rT   Úfilenamer&   r#   rS   Únamelistr(   r,   ÚrangerC   r*   )r+   r�   ZzfnameÚnameZ	splitNameÚxrL   rG   r.   r.   r/   r0     s(   ÿþ


øzZipArchive.__init__r1   r2   r3   c                 C  s   t |tƒstS t| j|jƒS r4   )r5   rF   r6   r   r    r7   r.   r.   r/   r8   6  s   
zZipArchive.__cmp__r    r   úZipPath[OtherAnyStr, AnyStr]c                 C  s
   t | |ƒS )zà
        Create a ZipPath pointing at a path within the archive.

        @param path: a L{bytes} or L{unicode} with no path separators in it
            (either '/' or the system path separator, if it's different).
        N)r   )r+   r    r.   r.   r/   rL   ;  rq   zZipArchive.childrN   c                 C  ó   t | jƒ ¡ S )zC
        Returns C{True} if the underlying archive exists.
        N)r   r&   rQ   r?   r.   r.   r/   rQ   D  ó   zZipArchive.existsro   c                 C  rˆ   )z=
        Return the archive file's last access time.
        N)r   r&   rp   r?   r.   r.   r/   rp   J  r‰   zZipArchive.getAccessTimec                 C  rˆ   )z>
        Return the archive file's modification time.
        N)r   r&   ru   r?   r.   r.   r/   ru   P  r‰   zZipArchive.getModificationTimec                 C  rˆ   )z?
        Return the archive file's status change time.
        N)r   r&   rv   r?   r.   r.   r/   rv   V  r‰   zZipArchive.getStatusChangeTimer9   c                 C  s   dt j | j¡›d�S )NzZipArchive(r:   )r)   r    r;   r?   r.   r.   r/   r>   \  s   zZipArchive.__repr__N)r$   r   )r�   r   r$   r%   rw   )r    r   r$   r‡   ry   rz   rx   )r{   r|   r}   r~   r   r€   r!   r0   r8   rL   rQ   rp   ru   rv   r>   r.   r.   r.   r/   rF     s   
 



	


rF   ),r~   Ú
__future__r   r]   r)   rr   Útypingr   r   r   r   r   r   r	   r
   r   r   r   rT   r   Zzope.interfacer   Ztyping_extensionsr   r   Ztwisted.python.compatr   r   Ztwisted.python.filepathr   r   r   r   r   r   r'   Úbytesr9   r   r   r   r   rF   Ú__all__r.   r.   r.   r/   Ú<module>   s*   4 	" P[