U
    [e                     @   sj   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Ze	Z
dd Zdd ZG dd dZdS )	    )divisionNc                 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	   F/var/www/html/services/stratfitenv/lib/python3.8/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                   @   s   e Zd ZdZdZd,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ed$d% Zed&d' Zd(d) Zejd*k reZ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 |tjr|nt| || _|| _d S N)
isinstancezipfileZipFile_pathlib_compatrootat)selfr   r   r	   r	   r
   __init__}   s
    
zPath.__init__c                 C   s,   z
|   W S  tk
r&   t|  Y S X dS )zu
        For path-like objects, convert to a filename for compatibility
        on Python 3.6.1 and earlier.
        N)
__fspath__AttributeErrorstrr   r	   r	   r
   r      s    
zPath._pathlib_compatc                 C   s   t | jj| jS r   )	functoolspartialr   openr   r   r	   r	   r
   r!      s    z	Path.openc                 C   s   t | jdS N/)r   basenamer   r   r"   r	   r	   r
   name   s    z	Path.namec              
   O   s6   |   $}tj|f|| W  5 Q R  S Q R X d S r   )r!   ioTextIOWrapperread)r   argskwargsstrmr	   r	   r
   	read_text   s    
zPath.read_textc              
   C   s(   |   }| W  5 Q R  S Q R X d S r   )r!   r)   )r   r,   r	   r	   r
   
read_bytes   s    
zPath.read_bytesc                 C   s   t |jd| jdkS r#   )r   dirnamer   r   )r   r   r	   r	   r
   	_is_child   s    zPath._is_childc                 C   s   t | j|S r   )r   r   )r   r   r	   r	   r
   _next   s    z
Path._nextc                 C   s   | j  p| j dS r#   )r   endswithr"   r	   r	   r
   is_dir   s    zPath.is_dirc                 C   s
   |    S r   )r3   r"   r	   r	   r
   is_file   s    zPath.is_filec                 C   s   | j |  kS r   )r   _namesr"   r	   r	   r
   exists   s    zPath.existsc                 C   s,   |   stdt| j|  }t| j|S )NzCan't listdir a file)r3   
ValueErrormapr1   r5   filterr0   )r   subsr	   r	   r
   iterdir   s    zPath.iterdirc                 C   s   t | jj| jS r   )r   joinr   filenamer   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   sN   |  |}t| j|}t| j|d}|  }| ||krH||krH|n|S )Nr   )r   r   r<   r   r5   r1   )r   addnextZnext_dirnamesr	   r	   r
   joinpath   s
    
zPath.joinpathc                    s   t  fdd D S )Nc                 3   s0   | ](}t |D ]}|d   kr|d  V  qqdS )r$   N)r   ).0r&   parentrD   r	   r
   	<genexpr>   s
   
 z%Path._implied_dirs.<locals>.<genexpr>)more_itertoolsZunique_everseenrH   r	   rH   r
   _implied_dirs   s    zPath._implied_dirsc                 C   s   |t | | S r   )listrK   )clsrD   r	   r	   r
   _add_implied_dirs   s    zPath._add_implied_dirsc                 C   s(   t | jd}|r|d7 }| |S r#   )r   r/   r   r   r1   )r   	parent_atr	   r	   r
   rG      s    zPath.parentc                 C   s   |  | j S r   )rN   r   namelistr"   r	   r	   r
   r5      s    zPath._names)   N)r   )__name__
__module____qualname____doc__r?   r   staticmethodr   propertyr!   r&   r-   r.   r0   r1   r3   r4   r6   r;   r>   rA   rE   __truediv__rK   classmethodrN   rG   r5   sysversion_infoZ__div__r	   r	   r	   r
   r   :   s<   @








r   )
__future__r   r'   rZ   r   r   r   r   rJ   typeZ__metaclass__r   r   r   r	   r	   r	   r
   <module>   s   