
    Ǉf                         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d dl	Z	e
Zd Zd Z G d d      Z G d d      Zy)	    )divisionNc                 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(''))
    []
       N)	itertoolsislice	_ancestrypaths    &/usr/lib/python3/dist-packages/zipp.py_parentsr      s      IdOQ55    c              #      K   | j                  t        j                        } | rH| t        j                  k7  r4|  t        j                  |       \  } }| r| t        j                  k7  r2yyyyw)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
   tails     r   r   r   %   sV       ;;y}}%D
49==(
__T*
d 49==($($s   A&A-)A-c                   2     e Zd ZdZ fdZed        Z xZS )SanitizedNamesz7
    ZipFile mix-in to ensure names are sanitized.
    c                 Z    t        t        | j                  t        |                      S N)listmap	_sanitizesupernamelist)self	__class__s    r   r   zSanitizedNames.namelist?   s!    C(8(:;<<r   c                    d }t        j                  dd| t         j                        }|j                  dd      }|j	                  d      }dj                  t        ||            }|st        d      |d| j                  d      z  z   S )a]  
        Ensure a relative path with posix separators and no dot names.
        Modeled after
        https://github.com/python/cpython/blob/bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c/Lib/zipfile/__init__.py#L1799-L1813
        but provides consistent cross-platform behavior.
        >>> san = SanitizedNames._sanitize
        >>> san('/foo/bar')
        'foo/bar'
        >>> san('//foo.txt')
        'foo.txt'
        >>> san('foo/.././bar.txt')
        'foo/bar.txt'
        >>> san('foo../.bar.txt')
        'foo../.bar.txt'
        >>> san('\\foo\\bar.txt')
        'foo/bar.txt'
        >>> san('D:\\foo.txt')
        'D/foo.txt'
        >>> san('\\\\server\\share\\file.txt')
        'server/share/file.txt'
        >>> san('\\\\?\\GLOBALROOT\\Volume3')
        '?/GLOBALROOT/Volume3'
        >>> san('\\\\.\\PhysicalDrive1\\root')
        'PhysicalDrive1/root'
        Retain any trailing slash.
        >>> san('abc/')
        'abc/'
        Raises a ValueError if the result is empty.
        >>> san('../..')
        Traceback (most recent call last):
        ...
        ValueError: Empty filename
        c                     | xr | dvS )N>   ... )parts    r   allowedz)SanitizedNames._sanitize.<locals>.allowedf   s    3D33r   z	^([A-Z]):z\1)flags\/zEmpty filename)	resub
IGNORECASEreplacer   joinfilter
ValueErrorendswith)namer%   barecleanpartsjoineds         r   r   zSanitizedNames._sanitizeB   s}    H	4
 vvk5$bmmDT3'C &%01-..dmmC0000r   )__name__
__module____qualname____doc__r   staticmethodr   __classcell__)r   s   @r   r   r   :   s!    = .1 .1r   r   c                       e Zd ZdZdZd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eZed        Zed        Zed        Zd Zej:                  dk  reZyy)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                     t        |t        j                        r|n#t        j                  | j                  |            | _        || _        y r   )
isinstancezipfileZipFile_pathlib_compatrootat)r   rC   rD   s      r   __init__zPath.__init__   s>     $0 !5!5d!;< 		
 r   c                 X    	 | j                         S # t        $ r t        |       cY S w xY w)zu
        For path-like objects, convert to a filename for compatibility
        on Python 3.6.1 and earlier.
        )
__fspath__AttributeErrorstrr	   s    r   rB   zPath._pathlib_compat   s-    	??$$ 	t9	s    ))c                 j    t        j                  | j                  j                  | j                        S r   )	functoolspartialrC   openrD   r   s    r   rM   z	Path.open   s!      99r   c                 ^    t        j                  | j                  j                  d            S Nr(   )r   basenamerD   r   rN   s    r   r1   z	Path.name   s     !!$''.."566r   c                     | j                         5 }t        j                  |g|i |j                         cd d d        S # 1 sw Y   y xY wr   )rM   ioTextIOWrapperread)r   argskwargsstrms       r   	read_textzPath.read_text   sG    YY[ 	BD##D:4:6:??A	B 	B 	Bs   'AAc                 n    | j                         5 }|j                         cd d d        S # 1 sw Y   y xY wr   )rM   rU   )r   rX   s     r   
read_byteszPath.read_bytes   s+    YY[ 	D99;	 	 	s   +4c                     t        j                  |j                  j                  d            | j                  j                  d      k(  S rP   )r   dirnamerD   r   )r   r
   s     r   	_is_childzPath._is_child   s2      !459LLLr   c                 .    t        | j                  |      S r   )r=   rC   )r   rD   s     r   _nextz
Path._next   s    DIIr""r   c                 V    | j                    xs | j                   j                  d      S rP   )rD   r0   rN   s    r   is_dirzPath.is_dir   s"    77{3dgg..s33r   c                 $    | j                          S r   )rb   rN   s    r   is_filezPath.is_file   s    ;;=  r   c                 :    | j                   | j                         v S r   )rD   _namesrN   s    r   existszPath.exists   s    ww$++-''r   c                     | j                         st        d      t        | j                  | j	                               }t        | j                  |      S )NzCan't listdir a file)rb   r/   r   r`   rf   r.   r^   )r   subss     r   iterdirzPath.iterdir   s>    {{}3444::t{{}-dnnd++r   c                 j    t        j                  | j                  j                  | j                        S r   )r   r-   rC   filenamerD   rN   s    r   __str__zPath.__str__   s!    ~~dii00$''::r   c                 :    | j                   j                  |       S )NrN   )_Path__reprformatrN   s    r   __repr__zPath.__repr__   s    {{!!t!,,r   c                    | j                  |      }t        j                  | j                  |      }t        j                  | j                  |d      }| j	                         }| j                  ||vr
||v r|      S |      S )N )rB   r   r-   rD   rf   r`   )r   addnextnext_dirnamess        r   joinpathzPath.joinpath   sm    ""3'~~dggs+>>$''33zzd%&7H<M(XXSWXXr   c                 @     t        j                   fd D              S )Nc              3   V   K   | ]   }t        |      D ]  }|d z   vr|d z     " yw)r(   N)r   ).0r1   parentrw   s      r   	<genexpr>z%Path._implied_dirs.<locals>.<genexpr>   sB      .
"4..
 |5( SL.
.
s   &))more_itertoolsunique_everseen)rw   s   `r   _implied_dirszPath._implied_dirs   s#    -- .
.
 
 	
r   c                 <    |t        | j                  |            z   S r   )r   r   )clsrw   s     r   _add_implied_dirszPath._add_implied_dirs  s    tC--e4555r   c                     t        j                  | j                  j                  d            }|r|dz  }| j	                  |      S rP   )r   r]   rD   r   r`   )r   	parent_ats     r   r|   zPath.parent
  s;    %%dggnnS&9:	Izz)$$r   c           	          | j                  t        t        t        j                  | j
                  j                                           S r   )r   r   r   r   r   rC   r   rN   s    r   rf   zPath._names  s2    %%d3~/G/GI[I[I]+^&_``r   )   N)rs   )r6   r7   r8   r9   ro   rE   r:   rB   propertyrM   r1   rY   r[   r^   r`   rb   rd   rg   rj   rm   rq   rx   __truediv__r   classmethodr   r|   rf   sysversion_info__div__r#   r   r   r=   r=   s   s    >@ NF   : : 7 7BM#4!(,;-Y K
 
 6 6 % %a $ r   r=   )
__future__r   rS   r   r   r@   rK   r   r)   r~   type__metaclass__r   r   r   r=   r#   r   r   <module>r      sH      	 
     	 6&+*71 71rb br   