
    Ϫf/              	      h   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      Z'e ee       G d dee&e%f   ee&                       Z( G d de(e
e
f         Z)ddgZ*y)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                      e Zd ZU dZded<   	 	 	 	 	 	 ddZddZddZedd       Z		 	 d dZ
d!d	Zer	 	 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y),ZipPathzF
    I represent a file or directory contained within a zip file.
    r   pathc                &   || _         || _        t        |j                  |      | _        t        |t
              }t        ||j                        }| j                  j                  |      }t        j                  j                  |g| }|| _        y)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   _zipfileFilename_nativePathInArchiveZIP_PATH_SEPsplitosr"   join)selfr$   r%   separchiveFilenamesegmentsfakePaths          8/usr/lib/python3/dist-packages/twisted/python/zippath.py__init__zZipPath.__init__=   s     18&31L$$m2
! *-F#>733$
 #'"4"4":":3"?GGLLD8D%	    c                    t        |t              st        S t        | j                  | j
                  f|j                  |j
                  f      S N)
isinstancer!   NotImplementedr   r$   r%   r,   others     r1   __cmp__zZipPath.__cmp__W   sB    %)!!\\4--.@S@S0T
 	
r3   c                l   t        | j                  t        j                  j	                  | j
                  j                              g}|j                  | j                  j                  | j                               t        | j                  t        j                        }d|j                  |      dS )NzZipPath())
r   r-   r*   r"   abspathr$   extendr%   r)   r+   )r,   partsosseps      r1   __repr__zZipPath.__repr__^   s     ("''//$,,BSBS2TU
 	T''--dhh78+DHHbff=%**U+.a00r3   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    r1   r-   zZipPath.sepg   s     +499lCCr3   c                    | j                   j                  | j                        }t        |      dk(  r| j                  S t        | j                  | 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,   splitups     r1   _nativeParentzZipPath._nativeParentq   sX     $$**4884w<1<<t||TXX]]73B<%@AAr3   c                    | j                         }t        |t              r3t        t        | j                  | j
                  j                              S |S r5   )rI   r6   
ZipArchiver   r"   r$   r&   )r,   parents     r1   rL   zZipPath.parent}   sF    ##%fj)+DIIt||7T7TU  r3   c                     y r5    rC   s    r1   parentszZipPath.parents   s     r3   c                    t        |t              }t        || j                        }t        | j                  |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       r1   childzZipPath.child   sA     -T<@3D$:L:LMt||V[[-1F%GHHr3   c                    | j                         }t        |t              r| j                  n|}|j	                  |      }|S r5   )rL   r6   rK   r$   rR   )r,   r"   rL   rightTypedParentrR   s        r1   siblingzZipPath.sibling   s9     +5fj+I4<<v3C3I3I$3Or3   c                F    | j                         xs | j                         S r5   )isdirisfilerC   s    r1   existszZipPath.exists   s    zz|,t{{},r3   c                F    | j                   | j                  j                  v S r5   )r%   r$   childmaprC   s    r1   rW   zZipPath.isdir   s    !!T\\%:%:::r3   c                Z    | j                   | j                  j                  j                  v S r5   )r%   r$   zipfile
NameToInforC   s    r1   rX   zZipPath.isfile   s#    !!T\\%9%9%D%DDDr3   c                     y)NFrN   rC   s    r1   islinkzZipPath.islink   s    r3   c                   | j                         r| j                         rst        | j                  j                  | j
                        }| j                  j                  |   j                         D cg c]  }t        | j                  |       c}S t        t        t        j                  d            t        t        t        j                  d            c c}w )NzLeaf zip entry listedzNon-existent zip entry listed)rY   rW   r   r$   r&   r%   r[   keysr"   r   OSErrorerrnoENOTDIRENOENT)r,   parentArchivePatheachs      r1   listdirzZipPath.listdir   s    ;;=zz|1LLL1143E3E2!
 !% 5 56G H M M O 0		4@ 
 &gemm=T&UVV!&EF s   4Cc                T    t         j                  j                  | j                        S )zQ
        Return a value similar to that returned by C{os.path.splitext}.
        )r*   r"   splitextrC   s    r1   rk   zZipPath.splitext   s     ww		**r3   c                R    | j                   j                  | j                        d   S )NrF   )r%   r)   r-   rC   s    r1   basenamezZipPath.basename   s"    !!''1"55r3   c                6    | j                         j                  S r5   )rL   r"   rC   s    r1   dirnamezZipPath.dirname   s     {{}!!!r3   c                |    t        d| j                        }| j                  j                  j	                  ||      S )N )mode)r   r%   r$   r]   open)r,   rr   r%   s      r1   rs   zZipPath.open   s6     4B8J8JK||##((T(BBr3   c                     y r5   rN   rC   s    r1   changedzZipPath.changed   s    r3   c                    t        d| j                        }| j                  j                  j                  |   j
                  S )zR
        Retrieve this file's size.

        @return: file size, in bytes
        rq   )r   r%   r$   r]   r^   	file_sizer,   r%   s     r1   getsizezZipPath.getsize   s7     4B8J8JK||##..}=GGGr3   c                6    | j                   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$   getAccessTimerC   s    r1   r{   zZipPath.getAccessTime   s     ||))++r3   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.
        rq   )r   r   r   )r   r%   timemktimer$   r]   r^   	date_timerx   s     r1   getModificationTimezZipPath.getModificationTime   sJ     4B8J8JK{{LL  ++M:DDyP
 	
r3   c                "    | j                         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.
        )r   rC   s    r1   getStatusChangeTimezZipPath.getStatusChangeTime   s     ''))r3   N)r$   zZipArchive[_ArchiveStr]r%   r   returnNoner9   objectr   intr   str)r   r   )r   z=Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ArchiveStr]])r   z9Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ZipStr]])r   zCIterable[Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ZipStr]]])r"   r   r   z!ZipPath[OtherAnyStr, _ArchiveStr]r   bool)r   zList[_ZipStr])r   zTuple[_ZipStr, _ZipStr])r)rr   zLiteral['r', 'w']r   z	IO[bytes])r   r   )r   r   r   float)__name__
__module____qualname____doc____annotations__r2   r:   rA   propertyr-   rI   rL   r   rO   rR   rU   rY   rW   rX   r`   ri   rk   rm   ro   rs   ru   ry   r{   r   r   rN   r3   r1   r!   r!   4   s     M&.&?F&	&4
1 D D
B	F
B 	P	
I -;E"+6"
CH,

*r3   r!   c                  n    e Zd ZU dZded<   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y)rK   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&   c                    | S r5   rN   rC   s    r1   r$   zZipArchive.archive  s    r3   c                d   || _         t        t        d|            | _        | j                  j                  }|J d       t        ||      | _        t        |d      | _        i | _        | j                  j                         D ]  }t        | j                   |      j                  | j                        }t        t        |            D ]V  }||    }| j                  j                  |d|        }|| j                  vri | j                  |<   d| j                  |   |<   X t        |d      } y)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.
        rq   Nz7zipfile must have filename when initialized with a pathrE   )r"   r   r   r]   filenamer&   r%   r[   namelistr)   r-   rangerG   r+   )r,   archivePathnamezfnamename	splitNamexrR   rL   s           r1   r2   zZipArchive.__init__  s"    $	:2OP&&	ED	E ;OV T8"M :<LL))+ 	FD3DIItDJJ488TI3y>* 1!1"y1"~6.,.DMM&)/0f%e,1 1"EF	Fr3   c                n    t        |t              st        S t        | j                  |j                        S r5   )r6   rK   r7   r   r"   r8   s     r1   r:   zZipArchive.__cmp__6  s'    %,!!499ejj))r3   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,   r"   s     r1   rR   zZipArchive.child;  s     tT""r3   c                H    t        | j                        j                         S )zC
        Returns C{True} if the underlying archive exists.
        )r   r&   rY   rC   s    r1   rY   zZipArchive.existsD  s     --.5577r3   c                H    t        | j                        j                         S )z=
        Return the archive file's last access time.
        )r   r&   r{   rC   s    r1   r{   zZipArchive.getAccessTimeJ  s     --.<<>>r3   c                H    t        | j                        j                         S )z>
        Return the archive file's modification time.
        )r   r&   r   rC   s    r1   r   zZipArchive.getModificationTimeP       --.BBDDr3   c                H    t        | j                        j                         S )z?
        Return the archive file's status change time.
        )r   r&   r   rC   s    r1   r   zZipArchive.getStatusChangeTimeV  r   r3   c                \    dt         j                  j                  | j                        dS )NzZipArchive(r<   )r*   r"   r=   rC   s    r1   rA   zZipArchive.__repr__\  s#    RWW__TYY7:!<<r3   N)r   r   )r   r   r   r   r   )r"   r   r   zZipPath[OtherAnyStr, AnyStr]r   r   r   )r   r   r   r   r   r   r$   r2   r:   rR   rY   r{   r   r   rA   rN   r3   r1   rK   rK     sL    
  F<*
#8?EE=r3   rK   )+r   
__future__r   rd   r*   r}   typingr   r   r   r   r   r	   r
   r   r   r   r   r]   r   zope.interfacer   r   r   twisted.python.compatr   r   twisted.python.filepathr   r   r   r   r   r   r(   bytesr   r   r   r   r!   rK   __all__rN   r3   r1   <module>r      s   

 #  	      &   1   mUC0
)UC
(:%89 YL*gg{*+-=g-F L*  L*^X=( X=v 
#r3   