o
    ¯bD#  ã                   @   s¨   d Z ddlZddlZddlZddl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mZmZmZ dZee	eƒG d	d
„ d
eƒƒƒZG dd„ deƒ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.
é    N)ÚDict)ÚZipFile)Úimplementer)ÚcmpÚ
comparable)ÚAbstractFilePathÚFilePathÚ	IFilePathÚUnlistableErrorÚ_coerceToFilesystemEncodingú/c                   @   sÄ   e Zd ZdZdd„ Zdd„ Zdefdd„Ze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d „ Zd/d"d#„Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.S )0ÚZipPathzF
    I represent a file or directory contained within a zip file.
    c                 C   sF   || _ || _t|tƒ}t||jjƒ}tjj|g| j 	|¡¢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)
ÚarchiveÚpathInArchiver   ÚZIP_PATH_SEPÚzipfileÚfilenameÚosÚpathÚjoinÚsplit)Úselfr   r   ÚsepÚarchiveFilename© r   ú8/usr/lib/python3/dist-packages/twisted/python/zippath.pyÚ__init__(   s   
ÿ"zZipPath.__init__c                 C   s(   t |tƒstS t| j| jf|j|jfƒS ©N)Ú
isinstancer   ÚNotImplementedr   r   r   )r   Úotherr   r   r   Ú__cmp__;   s
   
ÿzZipPath.__cmp__Úreturnc                 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   ÚpartsÚossepr   r   r   Ú__repr__B   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}.
        )r   r   r   ©r   r   r   r   r   J   s   zZipPath.sepc                 C   s<   | j  | j¡}t|ƒdkr| jS t| j| j |d d… ¡ƒS )Né   éÿÿÿÿ)r   r   r   Úlenr   r   r   )r   Úsplitupr   r   r   ÚparentT   s   zZipPath.parentc                 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.
        )r   r   r   r   r   r   )r   r   Újoinerr   r   r   r   ÚchildZ   s   
zZipPath.childc                 C   s   |   ¡  |¡S r   )r.   r0   ©r   r   r   r   r   Úsiblingj   ó   zZipPath.siblingc                 C   s   |   ¡ p|  ¡ S r   )ÚisdirÚisfiler)   r   r   r   Úexistsm   ó   zZipPath.existsc                 C   s   | j | jjv S r   )r   r   Úchildmapr)   r   r   r   r4   p   r3   zZipPath.isdirc                 C   s   | j | jjjv S r   )r   r   r   Ú
NameToInfor)   r   r   r   r5   s   r7   zZipPath.isfilec                 C   s   dS )NFr   r)   r   r   r   Úislinkv   ó   zZipPath.islinkc                 C   sF   |   ¡ r|  ¡ rt| jj| j  ¡ ƒS ttt	j
dƒƒ‚ttt	jdƒƒ‚)NzLeaf zip entry listedzNon-existent zip entry listed)r6   r4   Úlistr   r8   r   Úkeysr
   ÚOSErrorÚerrnoÚENOTDIRÚENOENTr)   r   r   r   Úlistdiry   s   
ÿzZipPath.listdirc                 C   s   t j | j¡S )zQ
        Return a value similar to that returned by C{os.path.splitext}.
        )r   r   Úsplitextr)   r   r   r   rC   „   s   zZipPath.splitextc                 C   s   | j  | j¡d S )Nr+   )r   r   r   r)   r   r   r   Úbasename�   s   zZipPath.basenamec                 C   s
   |   ¡ jS r   )r.   r   r)   r   r   r   Údirname�   s   
zZipPath.dirnameÚrc                 C   s   t d| jƒ}| jjj||d�S )NÚ )Úmode)r   r   r   r   Úopen)r   rH   r   r   r   r   rI   •   s   zZipPath.openc                 C   s   d S r   r   r)   r   r   r   Úchanged™   r;   zZipPath.changedc                 C   s   t d| jƒ}| jjj| jS )zR
        Retrieve this file's size.

        @return: file size, in bytes
        rG   )r   r   r   r   r9   Ú	file_size©r   r   r   r   r   Úgetsizeœ   s   zZipPath.getsizec                 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
        )r   ÚgetAccessTimer)   r   r   r   rN   ¥   ó   
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.
        rG   )r   r   r   )r   r   ÚtimeÚmktimer   r   r9   Ú	date_timerL   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.
        )rS   r)   r   r   r   ÚgetStatusChangeTimeº   s   zZipPath.getStatusChangeTimeN)rF   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   Ústrr(   Úpropertyr   r.   r0   r2   r6   r4   r5   r:   rB   rC   rD   rE   rI   rJ   rM   rN   rS   rT   r   r   r   r   r   !   s0    
		
		r   c                   @   sZ   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdefdd„ZdS )Ú
ZipArchiveaì  
    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.
    c                 C   s   | S r   r   r)   r   r   r   r   Ñ   s   zZipArchive.archivec                 C   s®   || _ ttd|ƒƒ| _t|dƒ| _i | _| j ¡ D ];}t| j |ƒ | j¡}t	t
|ƒƒD ]#}||  }| j |d| … ¡}|| jvrGi | 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.
        rG   Nr*   )r   r   r   r   r   r8   Únamelistr   r   Úranger,   r   )r   ÚarchivePathnameÚnameÚxr0   r.   r   r   r   r   Õ   s   


øzZipArchive.__init__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).
        )r   r1   r   r   r   r0   î   rO   zZipArchive.childc                 C   ó   t | jjƒ ¡ S )zC
        Returns C{True} if the underlying archive exists.
        )r   r   r   r6   r)   r   r   r   r6   ÷   ó   zZipArchive.existsc                 C   ra   )z=
        Return the archive file's last access time.
        )r   r   r   rN   r)   r   r   r   rN   ý   rb   zZipArchive.getAccessTimec                 C   ra   )z>
        Return the archive file's modification time.
        )r   r   r   rS   r)   r   r   r   rS     rb   zZipArchive.getModificationTimec                 C   ra   )z?
        Return the archive file's status change time.
        )r   r   r   rT   r)   r   r   r   rT   	  rb   zZipArchive.getStatusChangeTimer"   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)rU   rV   rW   rX   rZ   r   r   r0   r6   rN   rS   rT   rY   r(   r   r   r   r   r[   Ä   s    
	r[   )rX   r?   r   rP   Útypingr   r   r   Úzope.interfacer   Útwisted.python.compatr   r   Útwisted.python.filepathr   r   r	   r
   r   r   r   r[   Ú__all__r   r   r   r   Ú<module>   s     "O