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