
    
_d                          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j                  dk  rd dlm	Z	 ne
Z	dgZd Zd Ze	j                  Z	 d Z G d d	ej"                        Z G d
 de      Zd Z G d d      Zy)    N)      )OrderedDictPathc                 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    9/usr/lib/python3/dist-packages/setuptools/_vendor/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                 T    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   ?   s!    
   Z!=!=wGGr   c                   N     e Zd ZdZed        Z fdZd Zd Ze	d        Z
 xZS )CompleteDirszk
    A ZipFile subclass that ensures that implied directories
    are always included in the namelist.
    c                     t         j                  j                  t        t        |             }d |D        }t        t        ||             S )Nc              3   B   K   | ]  }|t         j                  z     y wN)r   r   ).0ps     r   	<genexpr>z-CompleteDirs._implied_dirs.<locals>.<genexpr>P   s     61y}}$6s   )r	   chainfrom_iterablemapr   _deduper   )namesparentsas_dirss      r   _implied_dirszCompleteDirs._implied_dirsM   s9    ////He0DE6g6{7E233r   c                 b    t         t        |          }|t        | j	                  |            z   S r"   )superr   namelistlistr-   )selfr*   	__class__s     r   r0   zCompleteDirs.namelistS   s-    lD24tD..u5666r   c                 4    t        | j                               S r"   )r   r0   r2   s    r   	_name_setzCompleteDirs._name_setW   s    4==?##r   c                 L    | j                         }|dz   }||vxr ||v }|r|S |S )zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        /)r6   )r2   namer*   dirname	dir_matchs        r   resolve_dirzCompleteDirs.resolve_dirZ   s:    
  *%:'U*:	#w--r   c                     t        |t              r|S t        |t        j                        s | t	        |            S d|j
                  vrt        } | |_        |S )zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        r)
isinstancer   zipfileZipFile_pathlib_compatmoder3   )clssources     r   makezCompleteDirs.maked   sQ     fl+M&'//2v.// fkk!Cr   )__name__
__module____qualname____doc__staticmethodr-   r0   r6   r<   classmethodrF   __classcell__r3   s   @r   r   r   G   s?    
 4 4
7$.  r   r   c                   ,     e Zd ZdZ fdZ fdZ xZS )
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c                     t        j                  t              5  | j                  cd d d        S # 1 sw Y   nxY wt        t
        |          | _        | j                  S r"   )
contextlibsuppressAttributeError_FastLookup__namesr/   rP   r0   r2   r3   s    r   r0   zFastLookup.namelist~   sH      0 	 <<	  	  	 Z79||   1:c                     t        j                  t              5  | j                  cd d d        S # 1 sw Y   nxY wt        t
        |          | _        | j                  S r"   )rR   rS   rT   _FastLookup__lookupr/   rP   r6   rV   s    r   r6   zFastLookup._name_set   sH      0 	!==	! 	! 	!j$9;}}rW   )rG   rH   rI   rJ   r0   r6   rM   rN   s   @r   rP   rP   x   s    
 r   rP   c                 X    	 | j                         S # t        $ r t        |       cY S w xY w)zi
    For path-like objects, convert to a filename for compatibility
    on Python 3.6.1 and earlier.
    )
__fspath__rT   strr   s    r   rB   rB      s-    
   4ys    ))c                       e Zd ZdZdZddZddd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eZed        Zy)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                 F    t         j                  |      | _        || _        y)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)rP   rF   rootat)r2   r_   r`   s      r   __init__zPath.__init__   s     OOD)	r   Npwdc                .   | j                         rt        |       |d   }| j                         s|dk(  rt        |       | j                  j                  | j                  ||      }d|v r|s|rt        d      |S t        j                  |g|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>   rb   bz*encoding args invalid for binary operation)
is_dirIsADirectoryErrorexistsFileNotFoundErrorr_   openr`   
ValueErrorioTextIOWrapper)r2   rC   rc   argskwargszip_modestreams          r   rj   z	Path.open   s     ;;=#D))7{{}S#D))s;$;v !MNNM8888r   c                     t        j                  | j                        j                  xs | j                  j                  S r"   )pathlibr   r`   r9   filenamer5   s    r   r9   z	Path.name  *    ||DGG$))?T]]-?-??r   c                     t        j                  | j                        j                  xs | j                  j                  S r"   )rs   r   r`   suffixrt   r5   s    r   rw   zPath.suffix	  s*    ||DGG$++Ct}}/C/CCr   c                     t        j                  | j                        j                  xs | j                  j                  S r"   )rs   r   r`   suffixesrt   r5   s    r   ry   zPath.suffixes  s*    ||DGG$--G1G1GGr   c                     t        j                  | j                        j                  xs | j                  j                  S r"   )rs   r   r`   stemrt   r5   s    r   r{   z	Path.stem  ru   r   c                     t        j                  | j                  j                        j	                  | j
                        S r"   )rs   r   r_   rt   joinpathr`   r5   s    r   rt   zPath.filename  s*    ||DII../88AAr   c                 z     | j                   dg|i |5 }|j                         cd d d        S # 1 sw Y   y xY w)Nr>   rj   read)r2   rn   ro   strms       r   	read_textzPath.read_text  s:    TYYs,T,V, 	99;	 	 	s   1:c                 p    | j                  d      5 }|j                         cd d d        S # 1 sw Y   y xY w)Nrbr   )r2   r   s     r   
read_byteszPath.read_bytes  s-    YYt_ 	99;	 	 	s   ,5c                     t        j                  |j                  j                  d            | j                  j                  d      k(  S Nr8   )r   r:   r`   r   )r2   r   s     r   	_is_childzPath._is_child!  s2      !459LLLr   c                 :    | j                  | j                  |      S r"   )r3   r_   )r2   r`   s     r   _nextz
Path._next$  s    ~~dii,,r   c                 V    | j                    xs | j                   j                  d      S r   )r`   endswithr5   s    r   rf   zPath.is_dir'  s"    77{3dgg..s33r   c                 H    | j                         xr | j                          S r"   )rh   rf   r5   s    r   is_filezPath.is_file*  s    {{}2T[[]!22r   c                 N    | j                   | j                  j                         v S r"   )r`   r_   r6   r5   s    r   rh   zPath.exists-  s    ww$))--///r   c                     | j                         st        d      t        | j                  | j                  j                               }t        | j                  |      S )NzCan't listdir a file)rf   rk   r(   r   r_   r0   filterr   )r2   subss     r   iterdirzPath.iterdir0  sE    {{}3444::tyy1134dnnd++r   c                 j    t        j                  | j                  j                  | j                        S r"   )r   joinr_   rt   r`   r5   s    r   __str__zPath.__str__6  s!    ~~dii00$''::r   c                 :    | j                   j                  |       S )Nr5   )_Path__reprformatr5   s    r   __repr__zPath.__repr__9  s    {{!!t!,,r   c                     t        j                  | j                  gt        t        |       }| j                  | j                  j                  |            S r"   )r   r   r`   r(   rB   r   r_   r<   )r2   othernexts      r   r}   zPath.joinpath<  s>    ~~dggDOU(CDzz$))//566r   c                     | j                   s| j                  j                  S t        j                  | j                   j                  d            }|r|dz  }| j                  |      S r   )r`   rt   parentr   r:   r   r   )r2   	parent_ats     r   r   zPath.parentB  sR    ww=='''%%dggnnS&9:	Izz)$$r   ) )r>   )rG   rH   rI   rJ   r   ra   rj   propertyr9   rw   ry   r{   rt   r   r   r   r   rf   r   rh   r   r   r   r}   __truediv__r    r   r   r   r      s    KZ NF9 9$ @ @ D D H H @ @ B BM-430,;-7 K% %r   )rl   r   r@   r	   rR   sysrs   version_infocollectionsr   dict__all__r   r   fromkeysr)   r   rA   r   rP   rB   r   r   r   r   <module>r      s    	     
 f'K (6&+, 

 /H.7?? .b &s% s%r   