
    tf/              	         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+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                      e Zd ZU dZded<   d2d	Zd3dZd4dZed5d            Z	d6dZ
d7dZerd8dZd9dZd9dZd:dZd:dZd:dZd:dZd;d!Zd<d#Zd5d$Zd5d%Zd=d>d*Zd?d+Zd@d,ZdAd.ZdAd/ZdAd0Zd1S )BZipPathzF
    I represent a file or directory contained within a zip file.
    r   patharchiveZipArchive[_ArchiveStr]pathInArchivereturnNonec                   || _         || _        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   _zipfileFilename_nativePathInArchiveZIP_PATH_SEPsplitosr"   join)selfr#   r%   separchiveFilenamesegmentsfakePaths          U/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/zippath.py__init__zZipPath.__init__=   s     18&31L$m2
 2
! *-FF#>73$
 $
 #'"4":":3"?"?GLD8DDD%			    otherobjectintc                    t          |t                    st          S t          | j        | j        f|j        |j        f          S N)
isinstancer!   NotImplementedr   r#   r%   r/   r7   s     r4   __cmp__zZipPath.__cmp__W   sE    %)) 	"!!\4-.@S0T
 
 	
r6   strc                P   t          | j        t          j                            | j        j                            g}|                    | j                            | j                             t          | j        t          j                  }d|	                    |          dS )NzZipPath())
r   r0   r-   r"   abspathr#   extendr%   r,   r.   )r/   partsosseps      r4   __repr__zZipPath.__repr__^   s     ("'//$,BS2T2TUU
 	T'--dh77888+DHbf==0%**U++0000r6   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    r4   r0   zZipPath.sepg   s     +49lCCCr6   =Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ArchiveStr]]c                    | 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,   r0   lenr#   r!   r.   )r/   splitups     r4   _nativeParentzZipPath._nativeParentq   s]     $**4844w<<1<t|TX]]73B3<%@%@AAAr6   9Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ZipStr]]c                    |                                  }t          |t                    r,t          t          | j        | j        j                            S |S r;   )rP   r<   
ZipArchiver   r"   r#   r)   )r/   parents     r4   rT   zZipPath.parent}   sR    ##%%fj)) 	+DIt|7TUU   r6   CIterable[Union[ZipPath[_ZipStr, _ArchiveStr], ZipArchive[_ZipStr]]]c                    d S r;    rI   s    r4   parentszZipPath.parents   s	     Cr6   r   !ZipPath[OtherAnyStr, _ArchiveStr]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       r4   childzZipPath.child   sH     -T<@@3D$:LMMt|V[[-1F%G%GHHHr6   c                    |                                  }t          |t                    r| j        n|}|                    |          }|S r;   )rT   r<   rS   r#   r\   )r/   r"   rT   rightTypedParentr\   s        r4   siblingzZipPath.sibling   sD     +5fj+I+IU4<<v3C3I3I$3O3Or6   boolc                R    |                                  p|                                 S r;   )isdirisfilerI   s    r4   existszZipPath.exists   s    zz||,t{{}},r6   c                (    | j         | j        j        v S r;   )r%   r#   childmaprI   s    r4   rb   zZipPath.isdir   s    !T\%:::r6   c                2    | j         | j        j        j        v S r;   )r%   r#   zipfile
NameToInforI   s    r4   rc   zZipPath.isfile   s    !T\%9%DDDr6   c                    dS )NFrW   rI   s    r4   islinkzZipPath.islink   s    ur6   List[_ZipStr]c                                                      r                                 rOt           j        j         j                  } fd j        j        |                                         D             S t          t          t          j        d                    t          t          t          j        d                    )Nc                :    g | ]}t          j        |          S rW   )r   r"   ).0eachr/   s     r4   
<listcomp>z#ZipPath.listdir.<locals>.<listcomp>   s5        0	4@@  r6   zLeaf zip entry listedzNon-existent zip entry listed)rd   rb   r   r#   r)   r%   rf   keysr   OSErrorerrnoENOTDIRENOENT)r/   parentArchivePaths   ` r4   listdirzZipPath.listdir   s    ;;== 	zz|| 	W1LL143E2 2!    $ 56G H M M O O   
 &gem=T&U&UVVV!&EFF  r6   Tuple[_ZipStr, _ZipStr]c                J    t           j                            | j                  S )zQ
        Return a value similar to that returned by C{os.path.splitext}.
        )r-   r"   splitextrI   s    r4   r{   zZipPath.splitext   s     w	***r6   c                L    | j                             | j                  d         S )NrM   )r%   r,   r0   rI   s    r4   basenamezZipPath.basename   s     !''11"55r6   c                4    |                                  j        S r;   )rT   r"   rI   s    r4   dirnamezZipPath.dirname   s     {{}}!!r6   rmodeLiteral['r', 'w']	IO[bytes]c                n    t          d| j                  }| j        j                            ||          S )N )r   )r   r%   r#   rh   open)r/   r   r%   s      r4   r   zZipPath.open   s4     4B8JKK|#((T(BBBr6   c                    d S r;   rW   rI   s    r4   changedzZipPath.changed   s    r6   c                d    t          d| j                  }| j        j        j        |         j        S )zR
        Retrieve this file's size.

        @return: file size, in bytes
        r   )r   r%   r#   rh   ri   	file_sizer/   r%   s     r4   getsizezZipPath.getsize   s,     4B8JKK|#.}=GGr6   floatc                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#   getAccessTimerI   s    r4   r   zZipPath.getAccessTime   s     |))+++r6   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.
        r   )r   r   r   )r   r%   timemktimer#   rh   ri   	date_timer   s     r4   getModificationTimezZipPath.getModificationTime   sB     4B8JKK{L +M:DyP
 
 	
r6   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.
        )r   rI   s    r4   getStatusChangeTimezZipPath.getStatusChangeTime   s     '')))r6   N)r#   r$   r%   r   r&   r'   r7   r8   r&   r9   r&   r@   )r&   r   )r&   rJ   )r&   rQ   )r&   rU   )r"   r   r&   rY   r&   r`   )r&   rl   )r&   ry   )r   )r   r   r&   r   )r&   r'   )r&   r9   r&   r   )__name__
__module____qualname____doc____annotations__r5   r?   rG   propertyr0   rP   rT   r   rX   r\   r_   rd   rb   rc   rk   rx   r{   r}   r   r   r   r   r   r   r   rW   r6   r4   r!   r!   4   s+          MMM& & & &4
 
 
 
1 1 1 1 D D D XD
B 
B 
B 
B     	 	 	 	
I I I I    - - - -; ; ; ;E E E E      "+ + + +6 6 6 6" " " "
C C C C C   H H H H, , , ,

 

 

 

* * * * * *r6   r!   c                  v    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dS )"rS   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                    | S r;   rW   rI   s    r4   r#   zZipArchive.archive  s    r6   archivePathnamer'   c                x   || _         t          t          d|                    | _        | j        j        }|
J d            t          ||          | _        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.
        r   Nz7zipfile must have filename when initialized with a pathrL   )r"   r   r   rh   filenamer)   r%   rf   namelistr,   r0   rangerN   r.   )r/   r   zfnamename	splitNamexr\   rT   s           r4   r5   zZipArchive.__init__  sB    $	:2OOPP&D  ;OV T T8"MM :<L))++ 	F 	FD3DItDDJJ48TTI3y>>** 1 1!1"y1"~66..,.DM&)/0f%e,,0"EEFF	F 	Fr6   r7   r8   r9   c                n    t          |t                    st          S t          | j        |j                  S r;   )r<   rS   r=   r   r"   r>   s     r4   r?   zZipArchive.__cmp__6  s.    %,, 	"!!49ej)))r6   r"   r   ZipPath[OtherAnyStr, AnyStr]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     r4   r\   zZipArchive.child;  s     tT"""r6   r`   c                N    t          | j                                                  S )zC
        Returns C{True} if the underlying archive exists.
        )r   r)   rd   rI   s    r4   rd   zZipArchive.existsD  s!     -..55777r6   r   c                N    t          | j                                                  S )z=
        Return the archive file's last access time.
        )r   r)   r   rI   s    r4   r   zZipArchive.getAccessTimeJ  s!     -..<<>>>r6   c                N    t          | j                                                  S )z>
        Return the archive file's modification time.
        )r   r)   r   rI   s    r4   r   zZipArchive.getModificationTimeP  !     -..BBDDDr6   c                N    t          | j                                                  S )z?
        Return the archive file's status change time.
        )r   r)   r   rI   s    r4   r   zZipArchive.getStatusChangeTimeV  r   r6   r@   c                R    dt           j                            | j                  dS )NzZipArchive(rB   )r-   r"   rC   rI   s    r4   rG   zZipArchive.__repr__\  s#    <RW__TY77<<<<r6   N)r&   r   )r   r   r&   r'   r   )r"   r   r&   r   r   r   r   )r   r   r   r   r   r   r#   r5   r?   r\   rd   r   r   r   rG   rW   r6   r4   rS   rS     s         
 
    XF F F F<* * * *
# # # #8 8 8 8? ? ? ?E E E EE E E E= = = = = =r6   rS   ),r   
__future__r   rt   r-   r   typingr   r   r   r   r   r	   r
   r   r   r   r   rh   r   zope.interfacer   typing_extensionsr   r   twisted.python.compatr   r   twisted.python.filepathr   r   r   r   r   r   r+   bytesr@   r   r   r   r!   rS   __all__rW   r6   r4   <module>r      s\  
 
 # " " " " "  				                                 & & & & & & + + + + + + + + 1 1 1 1 1 1 1 1                 gmUC00
')UC
(
(7:%8999 YL* L* L* L* L*gg{*+-=g-F L* L*  L*^X= X= X= X= X=( X= X= X=v 
#r6   