Ë
    òT•j*  ã                   óð   — d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 dgZ
d„ Zd„ Zej                  Z	 d„ Z G d	„ d
«      Z G d„ deej$                  «      Z G d„ de«      Zdd„Z G d„ d«      Zy)zÒ
A Path-like interface for zipfiles.

This codebase is shared between zipfile.Path in the stdlib
and zipp in PyPI. See
https://github.com/python/importlib_metadata/wiki/Development-Methodology
for more detail.
é    Né   )Ú	translateÚPathc                 óB   — t        j                  t        | «      dd«      S )a2  
    Given a path with elements separated by
    posixpath.sep, generate all parents of that path.

    >>> list(_parents('b/d'))
    ['b']
    >>> list(_parents('/b/d/'))
    ['/b']
    >>> list(_parents('b/d/f/'))
    ['b/d', 'b']
    >>> list(_parents('b'))
    []
    >>> list(_parents(''))
    []
    r   N)Ú	itertoolsÚisliceÚ	_ancestry)Úpaths    ú-/usr/lib/python3.12/zipfile/_path/__init__.pyÚ_parentsr      s   € ô  ×ÑœI d›O¨Q°Ó5Ð5ó    c              #   ó  K  — | j                  t        j                  «      } | j                  t        j                  «      r=| –— t        j                  | «      \  } }| j                  t        j                  «      rŒ<yy­w)aÔ  
    Given a path with elements separated by
    posixpath.sep, generate all elements of that path.

    >>> list(_ancestry('b/d'))
    ['b/d', 'b']
    >>> list(_ancestry('/b/d/'))
    ['/b/d', '/b']
    >>> list(_ancestry('b/d/f/'))
    ['b/d/f', 'b/d', 'b']
    >>> list(_ancestry('b'))
    ['b']
    >>> list(_ancestry(''))
    []

    Multiple separators are treated like a single.

    >>> list(_ancestry('//b//d///f//'))
    ['//b//d///f', '//b//d', '//b']
    N)ÚrstripÚ	posixpathÚsepÚsplit)r
   Útails     r   r	   r	   +   sS   è ø€ ð* �;‰;”y—}‘}Ó%€DØ
�+‰+”i—m‘mÔ
$ØŠ
Ü—_‘_ TÓ*‰
ˆˆdð �+‰+”i—m‘m×
$ùs   ‚A:A?Á=A?c                 óT   — t        j                  t        |«      j                  | «      S )zZ
    Return items in minuend not in subtrahend, retaining order
    with O(1) lookup.
    )r   ÚfilterfalseÚsetÚ__contains__)ÚminuendÚ
subtrahends     r   Ú_differencer   J   s!   € ô
 × Ñ ¤ Z£×!=Ñ!=¸wÓGÐGr   c                   ó2   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ fd„Zˆ xZS )ÚInitializedStatez?
    Mix-in to save the initialization state for pickling.
    c                 ó@   •— || _         || _        t        ‰| �  |i |¤Ž y ©N)Ú_InitializedState__argsÚ_InitializedState__kwargsÚsuperÚ__init__)ÚselfÚargsÚkwargsÚ	__class__s      €r   r"   zInitializedState.__init__W   s#   ø€ ØˆŒØˆŒÜ‰Ñ˜$Ð) &Ó)r   c                 ó2   — | j                   | j                  fS r   )r   r    ©r#   s    r   Ú__getstate__zInitializedState.__getstate__\   s   € Ø�{‰{˜DŸM™MÐ)Ð)r   c                 ó.   •— |\  }}t        ‰| �  |i |¤Ž y r   )r!   r"   )r#   Ústater$   r%   r&   s       €r   Ú__setstate__zInitializedState.__setstate___   s   ø€ Ø‰ˆˆfÜ‰Ñ˜$Ð) &Ó)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r)   r,   Ú__classcell__©r&   s   @r   r   r   R   s   ø„ ñô*ò
*÷*ð *r   r   c                   óX   ‡ — e Zd ZdZed„ «       Zˆ fd„Zd„ Zd„ Zˆ fd„Z	e
d„ «       Zˆ xZS )ÚCompleteDirsa8  
    A ZipFile subclass that ensures that implied directories
    are always included in the namelist.

    >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt']))
    ['foo/', 'foo/bar/']
    >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt', 'foo/bar/']))
    ['foo/']
    c                 ó˜   — t         j                  j                  t        t        | «      «      }d„ |D «       }t        t        || «      «      S )Nc              3   óB   K  — | ]  }|t         j                  z   –— Œ y ­wr   )r   r   )Ú.0Úps     r   ú	<genexpr>z-CompleteDirs._implied_dirs.<locals>.<genexpr>r   s   è ø€ Ò6¨�1”y—}‘}Õ$Ñ6ùs   ‚)r   ÚchainÚfrom_iterableÚmapr   Ú_deduper   )ÚnamesÚparentsÚas_dirss      r   Ú_implied_dirszCompleteDirs._implied_dirso   s9   € ä—/‘/×/Ñ/´´H¸eÓ0DÓEˆÙ6¨gÔ6ˆÜ”{ 7¨EÓ2Ó3Ð3r   c                 óZ   •— t         ‰| �  «       }|t        | j                  |«      «      z   S r   )r!   ÚnamelistÚlistrA   )r#   r>   r&   s     €r   rC   zCompleteDirs.namelistu   s+   ø€ Ü‘Ñ Ó"ˆØ”t˜D×.Ñ.¨uÓ5Ó6Ñ6Ð6r   c                 ó4   — t        | j                  «       «      S r   )r   rC   r(   s    r   Ú	_name_setzCompleteDirs._name_sety   s   € Ü�4—=‘=“?Ó#Ð#r   c                 óL   — | j                  «       }|dz   }||vxr ||v }|r|S |S )zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        ú/)rF   )r#   Únamer>   ÚdirnameÚ	dir_matchs        r   Úresolve_dirzCompleteDirs.resolve_dir|   s:   € ð
 —‘Ó ˆØ˜‘*ˆØ Ð%Ò:¨'°UÐ*:ˆ	Ù#ˆwÐ-¨Ð-r   c                 ó¶   •— 	 t         ‰| �  |«      S # t        $ r= |j                  d«      r|| j	                  «       vr‚ t        j                  |¬«      cY S w xY w)z6
        Supplement getinfo for implied dirs.
        rH   )Úfilename)r!   ÚgetinfoÚKeyErrorÚendswithrF   ÚzipfileÚZipInfo)r#   rI   r&   s     €r   rO   zCompleteDirs.getinfo†   sR   ø€ ð	2Ü‘7‘? 4Ó(Ð(øÜò 	2Ø—=‘= Ô%¨°T·^±^Ó5EÑ)EØÜ—?‘?¨DÔ1Ò1ð	2ús   ƒ ’AAÁAc                 ó¤   — t        |t        «      r|S t        |t        j                  «      s | |«      S d|j                  vrt        } | |_        |S )zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        Úr)Ú
isinstancer4   rR   ÚZipFileÚmoder&   )ÚclsÚsources     r   ÚmakezCompleteDirs.make‘   sK   € ô �fœlÔ+ØˆMä˜&¤'§/¡/Ô2Ù�v“;Ðð �f—k‘kÑ!ÜˆCàˆÔØˆr   )r-   r.   r/   r0   ÚstaticmethodrA   rC   rF   rL   rO   Úclassmethodr[   r1   r2   s   @r   r4   r4   d   sD   ø„ ñð ñ4ó ð4ô
7ò$ò.ô	2ð ñó ôr   r4   c                   ó,   ‡ — e Zd ZdZˆ fd„Zˆ fd„Zˆ xZS )Ú
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c                 ó¸   •— t        j                  t        «      5  | j                  cd d d «       S # 1 sw Y   nxY wt        ‰| �  «       | _        | j                  S r   )Ú
contextlibÚsuppressÚAttributeErrorÚ_FastLookup__namesr!   rC   ©r#   r&   s    €r   rC   zFastLookup.namelist«   sF   ø€ Ü× Ñ ¤Ó0ñ 	 Ø—<‘<÷	 ÷ 	 ò 	 úä‘wÑ'Ó)ˆŒØ�|‰|Ðó   ›1±:c                 ó¸   •— t        j                  t        «      5  | j                  cd d d «       S # 1 sw Y   nxY wt        ‰| �  «       | _        | j                  S r   )ra   rb   rc   Ú_FastLookup__lookupr!   rF   re   s    €r   rF   zFastLookup._name_set±   sF   ø€ Ü× Ñ ¤Ó0ñ 	!Ø—=‘=÷	!÷ 	!ò 	!úä™Ñ)Ó+ˆŒØ�}‰}Ðrf   )r-   r.   r/   r0   rC   rF   r1   r2   s   @r   r_   r_   ¥   s   ø„ ñô
÷ð r   r_   c                 ó4   — t        j                  | d«      ||fS )Né   )ÚioÚtext_encoding)Úencodingr$   r%   s      r   Ú_extract_text_encodingrn   ¸   s   € ä×Ñ˜H aÓ(¨$°Ð6Ð6r   c                   ó   — e Zd ZdZdZd d„Zd„ Zd„ Zd!ddœd„Zd	„ Z	e
d
„ «       Ze
d„ «       Ze
d„ «       Ze
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„ Zd„ Zd„ Zd„ Zd„ ZeZ e
d„ «       Z!y)"r   u<  
    A pathlib-compatible interface for zip files.

    Consider a zip file with this structure::

        .
        â”œâ”€â”€ a.txt
        â””â”€â”€ b
            â”œâ”€â”€ c.txt
            â””â”€â”€ d
                â””â”€â”€ e.txt

    >>> data = io.BytesIO()
    >>> zf = ZipFile(data, 'w')
    >>> zf.writestr('a.txt', 'content of a')
    >>> zf.writestr('b/c.txt', 'content of c')
    >>> zf.writestr('b/d/e.txt', 'content of e')
    >>> zf.filename = 'mem/abcde.zip'

    Path accepts the zipfile object itself or a filename

    >>> root = Path(zf)

    From there, several path operations are available.

    Directory iteration (including the zip file itself):

    >>> a, b = root.iterdir()
    >>> a
    Path('mem/abcde.zip', 'a.txt')
    >>> b
    Path('mem/abcde.zip', 'b/')

    name property:

    >>> b.name
    'b'

    join with divide operator:

    >>> c = b / 'c.txt'
    >>> c
    Path('mem/abcde.zip', 'b/c.txt')
    >>> c.name
    'c.txt'

    Read text:

    >>> c.read_text(encoding='utf-8')
    'content of c'

    existence:

    >>> c.exists()
    True
    >>> (b / 'missing.txt').exists()
    False

    Coercion to string:

    >>> import os
    >>> str(c).replace(os.sep, posixpath.sep)
    'mem/abcde.zip/b/c.txt'

    At the root, ``name``, ``filename``, and ``parent``
    resolve to the zipfile. Note these attributes are not
    valid and will raise a ``ValueError`` if the zipfile
    has no filename.

    >>> root.name
    'abcde.zip'
    >>> str(root.filename).replace(os.sep, posixpath.sep)
    'mem/abcde.zip'
    >>> str(root.parent)
    'mem'
    z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})c                 óF   — t         j                  |«      | _        || _        y)aX  
        Construct a Path from a ZipFile or filename.

        Note: When the source is an existing ZipFile object,
        its type (__class__) will be mutated to a
        specialized type. If the caller wishes to retain the
        original type, the caller should either create a
        separate ZipFile object or pass a filename.
        N)r_   r[   ÚrootÚat)r#   rq   rr   s      r   r"   zPath.__init__  s   € ô —O‘O DÓ)ˆŒ	Øˆ�r   c                 ó    — | j                   |j                   urt        S | j                  | j                  f|j                  |j                  fk(  S )zU
        >>> Path(zipfile.ZipFile(io.BytesIO(), 'w')) == 'foo'
        False
        )r&   ÚNotImplementedrq   rr   )r#   Úothers     r   Ú__eq__zPath.__eq__  s?   € ð
 �>‰> §¡Ñ0Ü!Ð!Ø—	‘	˜4Ÿ7™7Ð#¨¯
©
°E·H±HÐ'=Ñ=Ð=r   c                 óD   — t        | j                  | j                  f«      S r   )Úhashrq   rr   r(   s    r   Ú__hash__zPath.__hash__#  s   € Ü�T—Y‘Y §¡Ð(Ó)Ð)r   N©Úpwdc                óN  — | j                  «       rt        | «      ‚|d   }| j                  «       s|dk(  rt        | «      ‚| j                  j                  | j                  ||¬«      }d|v r|s|rt        d«      ‚|S t        |i |¤Ž\  }}}t        j                  ||g|¢­i |¤ŽS )zª
        Open this entry as text or binary following the semantics
        of ``pathlib.Path.open()`` by passing arguments through
        to io.TextIOWrapper().
        r   rU   rz   Úbz*encoding args invalid for binary operation)Úis_dirÚIsADirectoryErrorÚexistsÚFileNotFoundErrorrq   Úopenrr   Ú
ValueErrorrn   rk   ÚTextIOWrapper)r#   rX   r{   r$   r%   Úzip_modeÚstreamrm   s           r   r‚   z	Path.open&  s§   € ð �;‰;Œ=Ü# DÓ)Ð)Ø˜‘7ˆØ�{‰{Œ} ¨S¢Ü# DÓ)Ð)Ø—‘—‘ §¡¨°s�Ó;ˆØ�$‰;Ù‘vÜ Ð!MÓNÐNØˆMä!7¸Ð!HÀÑ!HÑˆ�$˜Ü×Ñ ¨ÐB°4ÒB¸6ÑBÐBr   c                 óp   — t        j                  | j                  xs | j                  j                  «      S r   )ÚpathlibÚPurePosixPathrr   rq   rN   r(   s    r   Ú_basez
Path._base:  s&   € Ü×$Ñ$ T§W¡WÒ%B°·	±	×0BÑ0BÓCÐCr   c                 ó6   — | j                  «       j                  S r   )rŠ   rI   r(   s    r   rI   z	Path.name=  ó   € à�z‰z‹|× Ñ Ð r   c                 ó6   — | j                  «       j                  S r   )rŠ   Úsuffixr(   s    r   rŽ   zPath.suffixA  s   € à�z‰z‹|×"Ñ"Ð"r   c                 ó6   — | j                  «       j                  S r   )rŠ   Úsuffixesr(   s    r   r�   zPath.suffixesE  s   € à�z‰z‹|×$Ñ$Ð$r   c                 ó6   — | j                  «       j                  S r   )rŠ   Ústemr(   s    r   r’   z	Path.stemI  rŒ   r   c                 ó†   — t        j                  | j                  j                  «      j	                  | j
                  «      S r   )rˆ   r   rq   rN   Újoinpathrr   r(   s    r   rN   zPath.filenameM  s*   € ä�|‰|˜DŸI™I×.Ñ.Ó/×8Ñ8¸¿¹ÓAÐAr   c                 óš   — t        |i |¤Ž\  }}} | j                  d|g|¢­i |¤Ž5 }|j                  «       cd d d «       S # 1 sw Y   y xY w)NrU   )rn   r‚   Úread)r#   r$   r%   rm   Ústrms        r   Ú	read_textzPath.read_textQ  sR   € Ü!7¸Ð!HÀÑ!HÑˆ�$˜ØˆT�Y‰Y�s˜HÐ6 tÒ6¨vÑ6ð 	¸$Ø—9‘9“;÷	÷ 	ò 	ús   §AÁA
c                 óp   — | j                  d«      5 }|j                  «       cd d d «       S # 1 sw Y   y xY w)NÚrb)r‚   r–   )r#   r—   s     r   Ú
read_byteszPath.read_bytesV  s-   € Ø�Y‰Y�t‹_ð 	 Ø—9‘9“;÷	÷ 	ò 	ús   ’,¬5c                 ó–   — t        j                  |j                  j                  d«      «      | j                  j                  d«      k(  S ©NrH   )r   rJ   rr   r   )r#   r
   s     r   Ú	_is_childzPath._is_childZ  s2   € Ü× Ñ  §¡§¡°Ó!4Ó5¸¿¹¿¹ÈÓ9LÑLÐLr   c                 ó:   — | j                  | j                  |«      S r   )r&   rq   )r#   rr   s     r   Ú_nextz
Path._next]  s   € Ø�~‰~˜dŸi™i¨Ó,Ð,r   c                 óV   — | j                    xs | j                   j                  d«      S r�   )rr   rQ   r(   s    r   r~   zPath.is_dir`  s"   € Ø—7‘7ˆ{Ò3˜dŸg™g×.Ñ.¨sÓ3Ð3r   c                 óH   — | j                  «       xr | j                  «        S r   )r€   r~   r(   s    r   Úis_filezPath.is_filec  s   € Ø�{‰{‹}Ò2 T§[¡[£]Ð!2Ð2r   c                 óN   — | j                   | j                  j                  «       v S r   )rr   rq   rF   r(   s    r   r€   zPath.existsf  s   € Ø�w‰w˜$Ÿ)™)×-Ñ-Ó/Ð/Ð/r   c                 óÀ   — | j                  «       st        d«      ‚t        | j                  | j                  j                  «       «      }t        | j                  |«      S )NzCan't listdir a file)r~   rƒ   r<   r    rq   rC   Úfilterrž   )r#   Úsubss     r   ÚiterdirzPath.iterdiri  sE   € Ø�{‰{Œ}ÜÐ3Ó4Ð4Ü�4—:‘:˜tŸy™y×1Ñ1Ó3Ó4ˆÜ�d—n‘n dÓ+Ð+r   c                 ó^   — t        j                  | j                  «      j                  |«      S r   )rˆ   r‰   rr   Úmatch)r#   Úpath_patterns     r   rª   z
Path.matcho  s"   € Ü×$Ñ$ T§W¡WÓ-×3Ñ3°LÓAÐAr   c                  ó   — y)z]
        Return whether this path is a symlink. Always false (python/cpython#82102).
        F© r(   s    r   Ú
is_symlinkzPath.is_symlinkr  s   € ð r   c                 ó&  — |st        d|›�«      ‚t        j                  | j                  «      }t        j                  |t        |«      z   «      j                  }t        | j                  t        || j                  j                  «       «      «      S )NzUnacceptable pattern: )rƒ   ÚreÚescaperr   Úcompiler   Ú	fullmatchr<   r    r¦   rq   rC   )r#   ÚpatternÚprefixÚmatchess       r   Úglobz	Path.globx  sm   € ÙÜÐ5°g°[ÐAÓBÐBä—‘˜4Ÿ7™7Ó#ˆÜ—*‘*˜V¤i°Ó&8Ñ8Ó9×CÑCˆÜ�4—:‘:œv g¨t¯y©y×/AÑ/AÓ/CÓDÓEÐEr   c                 ó*   — | j                  d|› �«      S )Nz**/)r·   )r#   r´   s     r   Úrglobz
Path.rglob€  s   € Ø�y‰y˜3˜w˜i˜Ó)Ð)r   c                 ól   — t        j                  t        | «      t         |j                  |Ž «      «      S r   )r   ÚrelpathÚstrr”   )r#   ru   Úextras      r   Úrelative_tozPath.relative_toƒ  s)   € Ü× Ñ ¤ T£¬C°°·±ÀÐ0FÓ,GÓHÐHr   c                 ój   — t        j                  | j                  j                  | j                  «      S r   )r   Újoinrq   rN   rr   r(   s    r   Ú__str__zPath.__str__†  s!   € Ü�~‰~˜dŸi™i×0Ñ0°$·'±'Ó:Ð:r   c                 ó:   — | j                   j                  | ¬«      S )Nr(   )Ú_Path__reprÚformatr(   s    r   Ú__repr__zPath.__repr__‰  s   € Ø�{‰{×!Ñ! tÐ!Ó,Ð,r   c                 ó–   — t        j                  | j                  g|¢­Ž }| j                  | j                  j                  |«      «      S r   )r   rÀ   rr   r    rq   rL   )r#   ru   Únexts      r   r”   zPath.joinpathŒ  s7   € Ü�~‰~˜dŸg™gÐ.¨Ò.ˆØ�z‰z˜$Ÿ)™)×/Ñ/°Ó5Ó6Ð6r   c                 óÒ   — | j                   s| j                  j                  S t        j                  | j                   j                  d«      «      }|r|dz  }| j                  |«      S r�   )rr   rN   Úparentr   rJ   r   r    )r#   Ú	parent_ats     r   rÉ   zPath.parent’  sR   € à�wŠwØ—=‘=×'Ñ'Ð'Ü×%Ñ% d§g¡g§n¡n°SÓ&9Ó:ˆ	ÙØ˜ÑˆIØ�z‰z˜)Ó$Ð$r   )Ú )rU   )"r-   r.   r/   r0   rÃ   r"   rv   ry   r‚   rŠ   ÚpropertyrI   rŽ   r�   r’   rN   r˜   r›   rž   r    r~   r£   r€   r¨   rª   r®   r·   r¹   r¾   rÁ   rÅ   r”   Ú__truediv__rÉ   r­   r   r   r   r   ½   s  „ ñKðZ N€Fóò>ò*ðC¨ô Cò(Dð ñ!ó ð!ð ñ#ó ð#ð ñ%ó ð%ð ñ!ó ð!ð ñBó ðBòò
òMò-ò4ò3ò0ò,òBòòFò*òIò;ò-ò7ð €Kàñ%ó ñ%r   r   )r0   rk   r   rR   r   ra   rˆ   r°   r·   r   Ú__all__r   r	   ÚdictÚfromkeysr=   r   r   rW   r4   r_   rn   r   r­   r   r   ú<module>rÑ      s†   ðñó 
Û Û Û Û Û Û 	å ð ˆ(€ò6ò&+ð6 �-‰-€Ø /òH÷*ñ *ô$>Ð# W§_¡_ô >ôB�ô ó&7÷
\%ò \%r   