o
    q¨Êh  ã                   @   sÈ   d dl m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	 zd dl
mZ W n ey;   d dlmZ Y nw eZdd„ Zdd„ ZG d	d
„ d
ejƒZG dd„ deƒZdd„ ZG dd„ dƒZdS )é    )ÚdivisionN)ÚOrderedDict)Úsuppressc                 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   ú6/var/www/html/env/lib/python3.10/site-packages/zipp.pyÚ_parents   s   r   c                 c   sN   � |   tj¡} | r!| tjkr%| V  t | ¡\} }| r#| tjksdS dS dS 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                       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                    s6   t j tt| ƒ¡}t| ƒ‰ t ‡ fdd„|D ƒ¡}|S )Nc                 3   s(   � | ]}|t j ˆ vr|t j V  qd S ©N)r   r   )Ú.0Úp©Úexistingr   r   Ú	<genexpr>J   s   € ÿþz-CompleteDirs._implied_dirs.<locals>.<genexpr>)r   ÚchainÚfrom_iterableÚmapr   Úsetr   Úfromkeys)ÚnamesÚparentsÚimplied_dirsr   r   r   Ú_implied_dirsD   s   ÿzCompleteDirs._implied_dirsc                    s    t t| ƒ ¡ }|t|  |¡ƒ S r   )Úsuperr   ÚnamelistÚlistr"   )Úselfr   ©Ú	__class__r   r   r$   P   s   zCompleteDirs.namelistc                 C   s   t |  ¡ ƒS r   )r   r$   ©r&   r   r   r   Ú	_name_setT   ó   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).
        ú/)r*   )r&   Únamer   ÚdirnameÚ	dir_matchr   r   r   Úresolve_dirW   s   zCompleteDirs.resolve_dirc                 C   sT   t |tƒr|S t |tjƒs| t|ƒƒS d|jvrt} |  | ¡}t|ƒ t|ƒ¡ |S )zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        Úr)	Ú
isinstancer   ÚzipfileÚZipFileÚ_pathlib_compatÚmodeÚ__new__ÚvarsÚupdate)ÚclsÚsourceÚresr   r   r   Úmakea   s   


zCompleteDirs.make)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr"   r$   r*   r0   Úclassmethodr=   Ú__classcell__r   r   r'   r   r   >   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                    óD   t tƒ� | jW  d   ƒ S 1 sw   Y  tt| ƒ ¡ | _| jS r   )r   ÚAttributeErrorÚ_FastLookup__namesr#   rE   r$   r)   r'   r   r   r$   {   ó
   
 ÿzFastLookup.namelistc                    rF   r   )r   rG   Ú_FastLookup__lookupr#   rE   r*   r)   r'   r   r   r*   �   rI   zFastLookup._name_set)r>   r?   r@   rA   r$   r*   rD   r   r   r'   r   rE   v   s    rE   c                 C   s&   z|   ¡ W S  ty   t| ƒ Y S w )zi
    For path-like objects, convert to a filename for compatibility
    on Python 3.6.1 and earlier.
    )Ú
__fspath__rG   Ústrr	   r   r   r   r5   ˆ   s
   
ÿr5   c                   @   s®   e Zd ZdZdZd%dd„Zd&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ejd#k rUeZd$S d$S )'ÚPathuš  
    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 = '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('abcde.zip', 'a.txt')
    >>> b
    Path('abcde.zip', 'b/')

    name property:

    >>> b.name
    'b'

    join with divide operator:

    >>> c = b / 'c.txt'
    >>> c
    Path('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:

    >>> str(c)
    'abcde.zip/b/c.txt'
    z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})Ú c                 C   s   t  |¡| _|| _d S r   )rE   r=   ÚrootÚat)r&   rO   rP   r   r   r   Ú__init__Ö   s   
zPath.__init__r1   c                 O   s\   |  dd¡}|d }| jj| j||d�}d|v r"|s|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().
        ÚpwdNr   )rR   Úbz*encoding args invalid for binary operation)ÚpoprO   ÚopenrP   Ú
ValueErrorÚioÚTextIOWrapper)r&   r6   ÚargsÚkwargsrR   Úzip_modeÚstreamr   r   r   rU   Ú   s   z	Path.openc                 C   s   t  | j d¡¡S ©Nr,   )r   ÚbasenamerP   r   r)   r   r   r   r-   é   s   z	Path.namec                 O   sD   | j dg|¢R i |¤Ž�}| ¡ W  d   ƒ S 1 sw   Y  d S )Nr1   ©rU   Úread)r&   rY   rZ   Ústrmr   r   r   Ú	read_textí   s   $ÿzPath.read_textc                 C   s6   |   d¡�}| ¡ W  d   ƒ S 1 sw   Y  d S )NÚrbr_   )r&   ra   r   r   r   Ú
read_bytesñ   s   $ÿzPath.read_bytesc                 C   s   t  |j d¡¡| j d¡kS r]   )r   r.   rP   r   )r&   r
   r   r   r   Ú	_is_childõ   s   zPath._is_childc                 C   s   t | j|ƒS r   )rM   rO   )r&   rP   r   r   r   Ú_nextø   r+   z
Path._nextc                 C   s   | j  p	| j  d¡S r]   )rP   Úendswithr)   r   r   r   Úis_dirû   s   zPath.is_dirc                 C   s
   |   ¡  S r   )rh   r)   r   r   r   Úis_fileþ   s   
zPath.is_filec                 C   s   | j | j ¡ v S r   )rP   rO   r*   r)   r   r   r   Úexists  s   zPath.existsc                 C   s.   |   ¡ stdƒ‚t| j| j ¡ ƒ}t| j|ƒS )NzCan't listdir a file)rh   rV   r   rf   rO   r$   Úfilterre   )r&   Úsubsr   r   r   Úiterdir  s   zPath.iterdirc                 C   s   t  | jj| j¡S r   )r   ÚjoinrO   ÚfilenamerP   r)   r   r   r   Ú__str__
  s   zPath.__str__c                 C   s   | j j| d�S )Nr)   )Ú_Path__reprÚformatr)   r   r   r   Ú__repr__  s   zPath.__repr__c                 C   s$   t  | jt|ƒ¡}|  | j |¡¡S r   )r   rn   rP   r5   rf   rO   r0   )r&   ÚaddÚnextr   r   r   Újoinpath  s   zPath.joinpathc                 C   s(   t  | j d¡¡}|r|d7 }|  |¡S r]   )r   r.   rP   r   rf   )r&   Ú	parent_atr   r   r   Úparent  s   
zPath.parent)é   N)rN   )r1   )r>   r?   r@   rA   rq   rQ   rU   Úpropertyr-   rb   rd   re   rf   rh   ri   rj   rm   rp   rs   rv   Ú__truediv__rx   ÚsysÚversion_infoÚ__div__r   r   r   r   rM   “   s0    @




ÿrM   )Ú
__future__r   rW   r|   r   r3   Ú	functoolsr   Úcollectionsr   Ú
contextlibr   ÚImportErrorÚcontextlib2ÚtypeÚ__metaclass__r   r   r4   r   rE   r5   rM   r   r   r   r   Ú<module>   s(   ÿ8