a
    �ÏOc!  ã                   @   s˜   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gZdd„ Zdd„ Ze	j
Zdd„ ZG d	d
„ d
ƒZG dd„ deejƒZG dd„ deƒZG dd„ dƒZdS )é    NÚPathc                 C   s   t  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(''))
    []
    é   N)Ú	itertoolsÚisliceÚ	_ancestry)Úpath© r   ú;/var/www/html/gsl.tools/lib/python3.9/site-packages/zipp.pyÚ_parents   s    r
   c                 c   s4   |   tj¡} | r0| tjkr0| V  t | ¡\} }qdS )aR  
    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(''))
    []
    N)ÚrstripÚ	posixpathÚsepÚsplit)r   Útailr   r   r	   r      s    r   c                 C   s   t  t|ƒj| ¡S )zZ
    Return items in minuend not in subtrahend, retaining order
    with O(1) lookup.
    )r   ÚfilterfalseÚsetÚ__contains__)ÚminuendÚ
subtrahendr   r   r	   Ú_difference9   s    r   c                       s4   e Zd ZdZ‡ fdd„Zdd„ Z‡ fdd„Z‡  ZS )ÚInitializedStatez?
    Mix-in to save the initialization state for pickling.
    c                    s"   || _ || _tƒ j|i |¤Ž d S ©N)Ú_InitializedState__argsÚ_InitializedState__kwargsÚsuperÚ__init__)ÚselfÚargsÚkwargs©Ú	__class__r   r	   r   F   s    zInitializedState.__init__c                 C   s   | j | jfS r   )r   r   ©r   r   r   r	   Ú__getstate__K   s    zInitializedState.__getstate__c                    s   |\}}t ƒ j|i |¤Ž d S r   )r   r   )r   Ústater   r   r   r   r	   Ú__setstate__N   s    zInitializedState.__setstate__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r$   Ú__classcell__r   r   r   r	   r   A   s   r   c                       sH   e Zd ZdZedd„ ƒZ‡ fdd„Zdd„ Zdd	„ Ze	d
d„ ƒZ
‡  ZS )ÚCompleteDirszk
    A ZipFile subclass that ensures that implied directories
    are always included in the namelist.
    c                 C   s.   t j tt| ƒ¡}dd„ |D ƒ}tt|| ƒƒS )Nc                 s   s   | ]}|t j V  qd S r   )r   r   )Ú.0Úpr   r   r	   Ú	<genexpr>\   ó    z-CompleteDirs._implied_dirs.<locals>.<genexpr>)r   ÚchainÚfrom_iterableÚmapr
   Ú_deduper   )ÚnamesÚparentsÚas_dirsr   r   r	   Ú_implied_dirsY   s    zCompleteDirs._implied_dirsc                    s    t t| ƒ ¡ }|t|  |¡ƒ S r   )r   r*   ÚnamelistÚlistr6   )r   r3   r   r   r	   r7   _   s    zCompleteDirs.namelistc                 C   s   t |  ¡ ƒS r   )r   r7   r!   r   r   r	   Ú	_name_setc   s    zCompleteDirs._name_setc                 C   s,   |   ¡ }|d }||vo||v }|r(|S |S )zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        ú/)r9   )r   Únamer3   ÚdirnameÚ	dir_matchr   r   r	   Úresolve_dirf   s    zCompleteDirs.resolve_dirc                 C   s:   t |tƒr|S t |tjƒs"| |ƒS d|jvr0t} | |_|S )zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        Úr)Ú
isinstancer*   ÚzipfileÚZipFileÚmoder    )ÚclsÚsourcer   r   r	   Úmakep   s    

zCompleteDirs.make)r%   r&   r'   r(   Ústaticmethodr6   r7   r9   r>   ÚclassmethodrF   r)   r   r   r   r	   r*   S   s   

r*   c                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )Ú
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c                    sF   t  t¡� | jW  d   ƒ S 1 s&0    Y  tt| ƒ ¡ | _| jS r   )Ú
contextlibÚsuppressÚAttributeErrorÚ_FastLookup__namesr   rI   r7   r!   r   r   r	   r7   Š   s    $zFastLookup.namelistc                    sF   t  t¡� | jW  d   ƒ S 1 s&0    Y  tt| ƒ ¡ | _| jS r   )rJ   rK   rL   Ú_FastLookup__lookupr   rI   r9   r!   r   r   r	   r9   �   s    $zFastLookup._name_set)r%   r&   r'   r(   r7   r9   r)   r   r   r   r	   rI   „   s   rI   c                   @   sÒ   e Zd ZdZdZd-dd„Zd.ddœd	d
„Zedd„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZ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%d&„ Zd'd(„ Zd)d*„ ZeZed+d,„ ƒZdS )/r   u4  
    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.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()
    '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                 C   s   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)rI   rF   ÚrootÚat)r   rP   rQ   r   r   r	   r   ç   s    
zPath.__init__r?   N©Úpwdc                O   sx   |   ¡ rt| ƒ‚|d }|  ¡ s0|dkr0t| ƒ‚| jj| j||d�}d|v r`|sT|r\tdƒ‚|S 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   r?   rR   Úbz*encoding args invalid for binary operation)
Úis_dirÚIsADirectoryErrorÚexistsÚFileNotFoundErrorrP   ÚopenrQ   Ú
ValueErrorÚioÚTextIOWrapper)r   rC   rS   r   r   Úzip_modeÚstreamr   r   r	   rY   ô   s    z	Path.openc                 C   s   t  | j¡jp| jjS r   )Úpathlibr   rQ   r;   Úfilenamer!   r   r   r	   r;     s    z	Path.namec                 C   s   t  | j¡jp| jjS r   )r_   r   rQ   Úsuffixr`   r!   r   r   r	   ra   
  s    zPath.suffixc                 C   s   t  | j¡jp| jjS r   )r_   r   rQ   Úsuffixesr`   r!   r   r   r	   rb     s    zPath.suffixesc                 C   s   t  | j¡jp| jjS r   )r_   r   rQ   Ústemr`   r!   r   r   r	   rc     s    z	Path.stemc                 C   s   t  | jj¡ | j¡S r   )r_   r   rP   r`   ÚjoinpathrQ   r!   r   r   r	   r`     s    zPath.filenamec                 O   sD   | j dg|¢R i |¤Ž�}| ¡ W  d   ƒ S 1 s60    Y  d S )Nr?   ©rY   Úread)r   r   r   Ústrmr   r   r	   Ú	read_text  s    zPath.read_textc                 C   s6   |   d¡�}| ¡ W  d   ƒ S 1 s(0    Y  d S )NÚrbre   )r   rg   r   r   r	   Ú
read_bytes  s    zPath.read_bytesc                 C   s   t  |j d¡¡| j d¡kS ©Nr:   )r   r<   rQ   r   )r   r   r   r   r	   Ú	_is_child"  s    zPath._is_childc                 C   s   |   | j|¡S r   )r    rP   )r   rQ   r   r   r	   Ú_next%  s    z
Path._nextc                 C   s   | j  p| j  d¡S rk   )rQ   Úendswithr!   r   r   r	   rU   (  s    zPath.is_dirc                 C   s   |   ¡ o|  ¡  S r   )rW   rU   r!   r   r   r	   Úis_file+  s    zPath.is_filec                 C   s   | j | j ¡ v S r   )rQ   rP   r9   r!   r   r   r	   rW   .  s    zPath.existsc                 C   s.   |   ¡ stdƒ‚t| j| j ¡ ƒ}t| j|ƒS )NzCan't listdir a file)rU   rZ   r1   rm   rP   r7   Úfilterrl   )r   Úsubsr   r   r	   Úiterdir1  s    zPath.iterdirc                 C   s   t  | jj| j¡S r   )r   ÚjoinrP   r`   rQ   r!   r   r   r	   Ú__str__7  s    zPath.__str__c                 C   s   | j j| d�S )Nr!   )Ú_Path__reprÚformatr!   r   r   r	   Ú__repr__:  s    zPath.__repr__c                 G   s&   t j| jg|¢R Ž }|  | j |¡¡S r   )r   rs   rQ   rm   rP   r>   )r   ÚotherÚnextr   r   r	   rd   =  s    zPath.joinpathc                 C   s6   | j s| jjS t | j  d¡¡}|r,|d7 }|  |¡S rk   )rQ   r`   Úparentr   r<   r   rm   )r   Ú	parent_atr   r   r	   rz   C  s    zPath.parent)rO   )r?   )r%   r&   r'   r(   ru   r   rY   Úpropertyr;   ra   rb   rc   r`   rh   rj   rl   rm   rU   ro   rW   rr   rt   rw   rd   Ú__truediv__rz   r   r   r   r	   r   —   s8   M





)r[   r   rA   r   rJ   r_   Ú__all__r
   r   ÚdictÚfromkeysr2   r   r   rB   r*   rI   r   r   r   r   r	   Ú<module>   s   1