
    \dD#                         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
e                                  Z G 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                       e Zd ZdZd Zd ZdefdZed             Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd ZdS )ZipPathzF
    I represent a file or directory contained within a zip file.
    c                     || _         || _        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archiveFilenames        6lib/python3.11/site-packages/twisted/python/zippath.py__init__zZipPath.__init__(   so     * *-FF57?3
 
 GLSD4F4L4LS4Q4QSSS			    c                     t          |t                    st          S t          | j        | j        f|j        |j        f          S N)
isinstancer   NotImplementedr   r   r   )r   others     r   __cmp__zZipPath.__cmp__;   sE    %)) 	"!!\4-.@S0T
 
 	
r   returnc                 P   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osseps      r   __repr__zZipPath.__repr__B   s    '"'//$,BS2T2TUU
 	T'--dh77888+DHbf==0%**U++0000r   c                 6    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   s    r   r   zZipPath.sepJ   s     +49lCCCr   c                     | j                             | j                  }t          |          dk    r| j        S t          | j        | j                            |d d                             S )N   )r   r   r   lenr   r   r   )r   splitups     r   parentzZipPath.parentT   s[    $**4844w<<1<t|TX]]73B3<%@%@AAAr   c                     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   s       r   childzZipPath.childZ   sH     -T<@@3D$:LMMt|V[[-1F%G%GHHHr   c                 P    |                                                      |          S r!   )r5   r8   r   r   s     r   siblingzZipPath.siblingj   s    {{}}""4(((r   c                 R    |                                  p|                                 S r!   )isdirisfiler/   s    r   existszZipPath.existsm   s    zz||,t{{}},r   c                 (    | j         | j        j        v S r!   )r   r   childmapr/   s    r   r=   zZipPath.isdirp   s    !T\%:::r   c                 2    | j         | j        j        j        v S r!   )r   r   r   
NameToInfor/   s    r   r>   zZipPath.isfiles   s    !T\%9%DDDr   c                     dS )NF r/   s    r   islinkzZipPath.islinkv   s    ur   c                 Z   |                                  rq|                                 r6t          | j        j        | j                                                           S t          t          t          j
        d                    t          t          t          j        d                    )NzLeaf zip entry listedzNon-existent zip entry listed)r?   r=   listr   rA   r   keysr   OSErrorerrnoENOTDIRENOENTr/   s    r   listdirzZipPath.listdiry   s    ;;== 	zz|| WDL1$2DEJJLLMMM%gem=T&U&UVVV!&EFF  r   c                 J    t           j                            | j                  S )zQ
        Return a value similar to that returned by C{os.path.splitext}.
        )r   r   splitextr/   s    r   rP   zZipPath.splitext   s     w	***r   c                 L    | j                             | j                  d         S )Nr2   )r   r   r   r/   s    r   basenamezZipPath.basename   s     !''11"55r   c                 4    |                                  j        S r!   )r5   r   r/   s    r   dirnamezZipPath.dirname   s     {{}}!!r   rc                 n    t          d| j                  }| j        j                            ||          S )N )mode)r   r   r   r   open)r   rX   r   s      r   rY   zZipPath.open   s2    3B8JKK|#((T(BBBr   c                     d S r!   rE   r/   s    r   changedzZipPath.changed   s    r   c                 d    t          d| j                  }| j        j        j        |         j        S )zR
        Retrieve this file's size.

        @return: file size, in bytes
        rW   )r   r   r   r   rC   	file_sizer   r   s     r   getsizezZipPath.getsize   s,     4B8JKK|#.}=GGr   c                 4    | 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/   s    r   ra   zZipPath.getAccessTime   s     |))+++r   c                     t          d| j                  }t          j        | j        j        j        |         j        dz             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.
        rW   )r   r   r   )r   r   timemktimer   r   rC   	date_timer^   s     r   getModificationTimezZipPath.getModificationTime   sB     4B8JKK{L +M:DyP
 
 	
r   c                 *    |                                  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.
        )rf   r/   s    r   getStatusChangeTimezZipPath.getStatusChangeTime   s     '')))r   N)rU   )__name__
__module____qualname____doc__r   r%   strr-   propertyr   r5   r8   r;   r?   r=   r>   rF   rN   rP   rR   rT   rY   r[   r_   ra   rf   rh   rE   r   r   r   r   !   s        T T T&
 
 
1# 1 1 1 1 D D XDB B BI I I ) ) )- - -; ; ;E E E  	 	 	+ + +6 6 6" " "
C C C C  H H H, , ,

 

 

* * * * *r   r   c                   X    e Zd ZdZed             Zd Zd Zd Zd Z	d Z
d Zd	ef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                     | S r!   rE   r/   s    r   r   zZipArchive.archive   s    r   c                    || _         t          t          d|                    | _        t          |d          | _        i | _        | j                                        D ]}t          | j         |                              | j                  }t          t          |                    D ]Q}||          }| j                            |d|                    }|| j        vr
i | j        |<   d| j        |         |<   Rt          |d          }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.
        rW   Nr1   )r   r   r   r   r   rA   namelistr   r   ranger3   r   )r   archivePathnamenamexr8   r5   s         r   r   zZipArchive.__init__   s    $	:2OOPP8"MM 46L))++ 	F 	FD.ty$??EEdhOOD3t99%% 1 1aRtCaRCy11..,.DM&)/0f%e,,0"EEFF	F 	Fr   c                 "    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   r:   s     r   r8   zZipArchive.child   s     tT"""r   c                 X    t          | j        j                                                  S )zC
        Returns C{True} if the underlying archive exists.
        )r	   r   r   r?   r/   s    r   r?   zZipArchive.exists   s#     -..55777r   c                 X    t          | j        j                                                  S )z=
        Return the archive file's last access time.
        )r	   r   r   ra   r/   s    r   ra   zZipArchive.getAccessTime   s#     -..<<>>>r   c                 X    t          | j        j                                                  S )z>
        Return the archive file's modification time.
        )r	   r   r   rf   r/   s    r   rf   zZipArchive.getModificationTime  #     -..BBDDDr   c                 X    t          | j        j                                                  S )z?
        Return the archive file's status change time.
        )r	   r   r   rh   r/   s    r   rh   zZipArchive.getStatusChangeTime	  r|   r   r&   c                 R    dt           j                            | j                  dS )NzZipArchive(r(   )r   r   r)   r/   s    r   r-   zZipArchive.__repr__  s#    <RW__TY77<<<<r   N)ri   rj   rk   rl   rn   r   r   r8   r?   ra   rf   rh   rm   r-   rE   r   r   rp   rp      s        
 
   XF F F2# # #8 8 8? ? ?E E EE E E=# = = = = = =r   rp   )rl   rK   r   rc   typingr   r   r   zope.interfacer   twisted.python.compatr   r   twisted.python.filepathr   r	   r
   r   r   r   r   rp   __all__rE   r   r   <module>r      s_  
   				              & & & & & & 1 1 1 1 1 1 1 1               Y^* ^* ^* ^* ^* ^* ^*  ^*BL= L= L= L= L= L= L= L=^ 
#r   