
    l0j-                        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Zddl	m
Z
mZ ddlm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dS )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   )none_assave_method_argstext_encoding)
TranslatorPathc                 H    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    P/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/zipp/__init__.py_parentsr      s      IdOOQ555    c              #      K   |                      t          j                  } |                      t          j                  r<| V  t          j        |           \  } }|                      t          j                  :dS dS )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   -   sy      * ;;y}%%D
++im
$
$ +


_T**
d ++im
$
$ + + + + +r   c                 P    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   L   s     
  Z!=wGGGr   c                   B     e Zd ZdZe fd            Zd Z fdZ xZS )InitializedStatez?
    Mix-in to save the initialization state for pickling.
    c                 :     t                      j        |i | d S Nsuper__init__)selfargskwargs	__class__s      r   r%   zInitializedState.__init__Y   s%    $)&)))))r   c                 2    | j         j        | j         j        fS r"   )_saved___init__r'   r(   r&   s    r   __getstate__zInitializedState.__getstate__]   s    #($*>*EEEr   c                 D    |\  }} t                      j        |i | d S r"   r#   )r&   stater'   r(   r)   s       r   __setstate__zInitializedState.__setstate__`   s.    f$)&)))))r   )	__name__
__module____qualname____doc__r   r%   r-   r0   __classcell__r)   s   @r   r    r    T   sz          * * * * *F F F* * * * * * * * *r   r    c                        e Zd ZdZed             Z fdZd Zd Z fdZ	e
d             Ze
dej        d	ej        f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                            t          t          |                     }d |D             }t          t          ||                     S )Nc              3   4   K   | ]}|t           j        z   V  d S r"   )r   r   ).0ps     r   	<genexpr>z-CompleteDirs._implied_dirs.<locals>.<genexpr>s   s)      661y}$666666r   )r   chainfrom_iterablemapr   _deduper   )namesparentsas_dirss      r   _implied_dirszCompleteDirs._implied_dirsp   sL    ///He0D0DEE66g666{7E22333r   c                     t                                                      }|t          |                     |                    z   S r"   )r$   namelistlistrE   )r&   rB   r)   s     r   rG   zCompleteDirs.namelistv   s9      ""tD..u556666r   c                 D    t          |                                           S r"   )r   rG   r,   s    r   	_name_setzCompleteDirs._name_setz   s    4==??###r   c                 P    |                                  }|dz   }||vo||v }|r|n|S )zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        /)rJ   )r&   namerB   dirname	dir_matchs        r   resolve_dirzCompleteDirs.resolve_dir}   s?    
   *%:'U*:	#-ww-r   c                     	 t                                          |          S # t          $ rD |                    d          r||                                 vr t          j        |          cY S w xY w)z6
        Supplement getinfo for implied dirs.
        rL   )filename)r$   getinfoKeyErrorendswithrJ   zipfileZipInfo)r&   rM   r)   s     r   rS   zCompleteDirs.getinfo   s}    	277??4((( 	2 	2 	2==%% T^^5E5E)E)E?D111111	2s    $ AA21A2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)
isinstancer8   rV   ZipFilemoder)   )clssources     r   makezCompleteDirs.make   s^     fl++ 	M&'/22 	3v;; fk!!Cr   zfreturnc                     |                      |                                          D ]}|                    |d           |S )z
        Given a writable zip file zf, inject directory entries for
        any directories implied by the presence of children.
        r   )rE   rG   writestr)r]   r`   rM   s      r   injectzCompleteDirs.inject   sE     %%bkkmm44 	# 	#DKKc""""	r   )r1   r2   r3   r4   staticmethodrE   rG   rJ   rP   rS   classmethodr_   rV   r[   rd   r5   r6   s   @r   r8   r8   e   s          4 4 \4
7 7 7 7 7$ $ $. . .	2 	2 	2 	2 	2   [$  GO    [    r   r8   c                   l     e Zd ZdZd Zej         fd            Zd Zej         fd            Z	 xZ
S )
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c                     | j         S r"   )	_namelistr,   s    r   rG   zFastLookup.namelist   s
    ~r   c                 D    t                                                      S r"   )r$   rG   r&   r)   s    r   rj   zFastLookup._namelist   s    ww!!!r   c                     | j         S r"   )_name_set_propr,   s    r   rJ   zFastLookup._name_set   s    ""r   c                 D    t                                                      S r"   )r$   rJ   rl   s    r   rn   zFastLookup._name_set_prop   s    ww  """r   )r1   r2   r3   r4   rG   	functoolscached_propertyrj   rJ   rn   r5   r6   s   @r   rh   rh      s         
   " " " " "# # # # # # # # # # # #r   rh   c                 ,    d}t          | |          ||fS )N   r   )encodingr'   r(   stack_levels       r   _extract_text_encodingrv      s    K;//v==r   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!dS )$r	   u#  
    A :class:`importlib.resources.abc.Traversable` interface for zip files.

    Implements many of the features users enjoy from
    :class:`pathlib.Path`.

    Consider a zip file with this structure::

        .
        ├── a.txt
        └── b
            ├── c.txt
            └── d
                └── e.txt

    >>> data = io.BytesIO()
    >>> zf = zipfile.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

    >>> path = Path(zf)

    From there, several path operations are available.

    Directory iteration (including the zip file itself):

    >>> a, b = path.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.

    >>> str(path)
    'mem/abcde.zip'
    >>> path.name
    'abcde.zip'
    >>> path.filename == pathlib.Path('mem/abcde.zip')
    True
    >>> str(path.parent)
    'mem'

    If the zipfile has no filename, such attributes are not
    valid and accessing them will raise an Exception.

    >>> zf.filename = None
    >>> path.name
    Traceback (most recent call last):
    ...
    TypeError: ...

    >>> path.filename
    Traceback (most recent call last):
    ...
    TypeError: ...

    >>> path.parent
    Traceback (most recent call last):
    ...
    TypeError: ...

    # workaround python/cpython#106763
    >>> pass
    z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r}) c                 R    t                               |          | _        || _        dS )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)rh   r_   rootat)r&   rz   r{   s      r   r%   zPath.__init__3  s"     OOD))	r   c                 h    | j         |j         urt          S | j        | j        f|j        |j        fk    S )zU
        >>> Path(zipfile.ZipFile(io.BytesIO(), 'w')) == 'foo'
        False
        )r)   NotImplementedrz   r{   )r&   others     r   __eq__zPath.__eq__@  s6    
 >00!!	47#
EH'===r   c                 8    t          | j        | j        f          S r"   )hashrz   r{   r,   s    r   __hash__zPath.__hash__I  s    TY()))r   rY   Npwdc                l   |                                  rt          |           |d         }|dk    r#|                                 st          |           | j                            | j        ||          }d|v r|s|rt          d          |S t          |i |\  }}}t          j
        ||g|R 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   rY   r   bz*encoding args invalid for binary operation)is_dirIsADirectoryErrorexistsFileNotFoundErrorrz   openr{   
ValueErrorrv   ioTextIOWrapper)r&   r\   r   r'   r(   zip_modestreamrt   s           r   r   z	Path.openL  s     ;;== 	*#D)))7s??4;;==?#D)))s;;$;; Ov O !MNNNM!7!H!H!H$B4BBB6BBBr   c                 P    | j         rt          j        | j                   n| j        S r"   )r{   pathlibPurePosixPathrR   r,   s    r   _basez
Path._base`  s#    15Kw$TW---dmKr   c                 4    |                                  j        S r"   )r   rM   r,   s    r   rM   z	Path.namec      zz||  r   c                 4    |                                  j        S r"   )r   suffixr,   s    r   r   zPath.suffixg  s    zz||""r   c                 4    |                                  j        S r"   )r   suffixesr,   s    r   r   zPath.suffixesk  s    zz||$$r   c                 4    |                                  j        S r"   )r   stemr,   s    r   r   z	Path.stemo  r   r   c                 n    t          j        | j        j                                      | j                  S r"   )r   r	   rz   rR   joinpathr{   r,   s    r   rR   zPath.filenames  s'    |DI.//88AAAr   c                     t          |i |\  }}} | j        d|g|R i |5 }|                                cd d d            S # 1 swxY w Y   d S )NrY   )rv   r   read)r&   r'   r(   rt   strms        r   	read_textzPath.read_textw  s    !7!H!H!H$TYsH6t666v66 	$99;;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     |                      d          5 }|                                cd d d            S # 1 swxY w Y   d S )Nrb)r   r   )r&   r   s     r   
read_byteszPath.read_bytes|  s~    YYt__ 	99;;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   7;;c                     t          j        |j                            d                    | j                            d          k    S NrL   )r   rN   r{   r   )r&   r   s     r   	_is_childzPath._is_child  s4     !4!4559L9LLLr   c                 8    |                      | j        |          S r"   )r)   rz   )r&   r{   s     r   _nextz
Path._next  s    ~~di,,,r   c                 F    | j          p| j                             d          S r   )r{   rU   r,   s    r   r   zPath.is_dir  s!    7{3dg..s333r   c                 T    |                                  o|                                  S r"   )r   r   r,   s    r   is_filezPath.is_file  s     {{}}2T[[]]!22r   c                 B    | j         | j                                        v S r"   )r{   rz   rJ   r,   s    r   r   zPath.exists  s    w$)--////r   c                     |                                  st          d          t          | j        | j                                                  }t          | j        |          S )NzCan't listdir a file)r   NotADirectoryErrorr@   r   rz   rG   filterr   )r&   subss     r   iterdirzPath.iterdir  sR    {{}} 	=$%;<<<4:ty113344dnd+++r   c                 Z    t          j        | j                                      |          S r"   )r   r   r{   match)r&   path_patterns     r   r   z
Path.match  s#    $TW--33LAAAr   c                 |    | j                             | j                  }|j        dz	  }t	          j        |          S )z8
        Return whether this path is a symlink.
           )rz   rS   r{   external_attrstatS_ISLNK)r&   infor\   s      r   
is_symlinkzPath.is_symlink  s8     y  ))!R'|D!!!r   c                 N   |st          d|          t          j        | j                  }t	          d          }t          j        ||                    |          z             j        }t          | j	        t          || j                                                            S )NzUnacceptable pattern: rL   )seps)r   reescaper{   r   compile	translate	fullmatchr@   r   r   rz   rG   )r&   patternprefixtrmatchess        r   globz	Path.glob  s     	CAgAABBB47##S!!!*Vbll7&;&;;<<F4:vgty/A/A/C/CDDEEEr   c                 2    |                      d|           S )Nz**/)r   )r&   r   s     r   rglobz
Path.rglob  s    yyw)))r   c                 p    t          j        t          |           t           |j        |                     S r"   )r   relpathstrr   )r&   r~   extras      r   relative_tozPath.relative_to  s,     TC0F,G,GHHHr   c                 |    t          | j        j        d          }| j        rt	          j        || j                  n|S )Nz	:zipfile:)r   rz   rR   r{   r   join)r&   rz   s     r   __str__zPath.__str__  s6    ty);7704Ay~dDG,,,TAr   c                 8    | j                             |           S )Nr,   )_Path__reprformatr,   s    r   __repr__zPath.__repr__  s    {!!t!,,,r   c                     t          j        | j        g|R  }|                     | j                            |                    S r"   )r   r   r{   r   rz   rP   )r&   r~   nexts      r   r   zPath.joinpath  s=    ~dg....zz$)//55666r   c                     | j         s| j        j        S t          j        | j                             d                    }|r|dz  }|                     |          S r   )r{   rR   parentr   rN   r   r   )r&   	parent_ats     r   r   zPath.parent  sY    w 	(=''%dgnnS&9&9::	 	Izz)$$$r   )rx   )rY   )"r1   r2   r3   r4   r   r%   r   r   r   r   propertyrM   r   r   r   rR   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __truediv__r    r   r   r	   r	      s<       d dL NF   > > >* * *C C C C C C(L L L ! ! X! # # X# % % X% ! ! X! B B XB  
  M M M- - -4 4 43 3 30 0 0, , ,B B B" " "F F F* * *I I IB B B- - -7 7 7 K% % X% % %r   r"   )r4   rp   r   r   r   r   r   r   rV   
_functoolsr   r   compat.py310r   r   r   __all__r   r   dictfromkeysrA   r   r    r[   r8   rh   rv   r	   r   r   r   <module>r      s        				          				   1 1 1 1 1 1 1 1 ' ' ' ' ' '      (6 6 6&+ + +6 - /H H H* * * * * * * *"H H H H H#W_ H H HV# # # # # # # #*> > > >
y% y% y% y% y% y% y% y% y% y%r   