3
W>p_3                 @   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ejdk rHd dlmZ ne	Zdd Z
dd Zej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 )    N      )OrderedDictc             C   s   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)path r
   y/home/aldo/Documentos/tesis/tesis/device auto/pruebas pulsar/pruebaclonado/envClonado/lib/python3.6/site-packages/zipp.py_parents   s    r   c             c   s8   | j tj} x&| r2| tjkr2| V  tj| \} }qW 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 jt|j| S )zZ
    Return items in minuend not in subtrahend, retaining order
    with O(1) lookup.
    )r   filterfalseset__contains__)ZminuendZ
subtrahendr
   r
   r   _difference;   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jtt| }dd |D }tt|| S )Nc             s   s   | ]}|t j V  qd S )N)r   r   ).0pr
   r
   r   	<genexpr>L   s    z-CompleteDirs._implied_dirs.<locals>.<genexpr>)r   chainfrom_iterablemapr   _deduper   )namesparentsZas_dirsr
   r
   r   _implied_dirsI   s    zCompleteDirs._implied_dirsc                s    t t| j }|t| j| S )N)superr   namelistlistr    )selfr   )	__class__r
   r   r"   O   s    zCompleteDirs.namelistc             C   s   t | j S )N)r   r"   )r$   r
   r
   r   	_name_setS   s    zCompleteDirs._name_setc             C   s,   | j  }|d }||ko||k}|r(|S |S )zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        /)r&   )r$   namer   dirnameZ	dir_matchr
   r
   r   resolve_dirV   s    zCompleteDirs.resolve_dirc             C   s>   t |tr|S t |tjs&| t|S d|jkr4t} | |_|S )zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        r)
isinstancer   zipfileZipFile_pathlib_compatmoder%   )clssourcer
   r
   r   make`   s    

zCompleteDirs.make)__name__
__module____qualname____doc__staticmethodr    r"   r&   r*   classmethodr3   __classcell__r
   r
   )r%   r   r   C   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          
      s.   t jt | jS Q R X tt| j | _| jS )N)
contextlibsuppressAttributeErrorZ_FastLookup__namesr!   r;   r"   )r$   )r%   r
   r   r"   z   s    zFastLookup.namelistc          
      s.   t jt | jS Q R X tt| j | _| jS )N)r<   r=   r>   Z_FastLookup__lookupr!   r;   r&   )r$   )r%   r
   r   r&      s    zFastLookup._name_set)r4   r5   r6   r7   r"   r&   r:   r
   r
   )r%   r   r;   t   s   r;   c             C   s&   y| j  S  tk
r    t| S X dS )zi
    For path-like objects, convert to a filename for compatibility
    on Python 3.6.1 and earlier.
    N)
__fspath__r>   str)r	   r
   r
   r   r/      s    r/   c               @   s   e Zd ZdZdZd%ddZd&d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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 j|| _|| _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)r;   r3   rootat)r$   rC   rD   r
   r
   r   __init__   s    
zPath.__init__r+   N)pwdc            O   st   | j  rt| |d }| j  r2|dkr2t| | jj| j||d}d|krb|sV|r^td|S tj	|f||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+   )rF   bz*encoding args invalid for binary operation)
is_dirIsADirectoryErrorexistsFileNotFoundErrorrC   openrD   
ValueErrorioTextIOWrapper)r$   r0   rF   argskwargsZzip_modestreamr
   r
   r   rL      s    z	Path.openc             C   s   t j| jjdS )Nr'   )r   basenamerD   r   )r$   r
   r
   r   r(      s    z	Path.namec          	   O   s$   | j d||
}|j S Q R X d S )Nr+   )r+   )rL   read)r$   rP   rQ   strmr
   r
   r   	read_text   s    zPath.read_textc          	   C   s   | j d
}|j S Q R X d S )Nrb)rL   rT   )r$   rU   r
   r
   r   
read_bytes   s    zPath.read_bytesc             C   s   t j|jjd| jjdkS )Nr'   )r   r)   rD   r   )r$   r	   r
   r
   r   	_is_child   s    zPath._is_childc             C   s   | j | j|S )N)r%   rC   )r$   rD   r
   r
   r   _next  s    z
Path._nextc             C   s   | j  p| j jdS )Nr'   )rD   endswith)r$   r
   r
   r   rH     s    zPath.is_dirc             C   s   | j  o| j  S )N)rJ   rH   )r$   r
   r
   r   is_file	  s    zPath.is_filec             C   s   | j | jj kS )N)rD   rC   r&   )r$   r
   r
   r   rJ     s    zPath.existsc             C   s.   | j  stdt| j| jj }t| j|S )NzCan't listdir a file)rH   rM   r   rZ   rC   r"   filterrY   )r$   subsr
   r
   r   iterdir  s    zPath.iterdirc             C   s   t j| jj| jS )N)r   joinrC   filenamerD   )r$   r
   r
   r   __str__  s    zPath.__str__c             C   s   | j j| dS )N)r$   )_Path__reprformat)r$   r
   r
   r   __repr__  s    zPath.__repr__c             C   s$   t j| jt|}| j| jj|S )N)r   r`   rD   r/   rZ   rC   r*   )r$   addnextr
   r
   r   joinpath  s    zPath.joinpathc             C   s(   t j| jjd}|r|d7 }| j|S )Nr'   )r   r)   rD   r   rZ   )r$   Z	parent_atr
   r
   r   parent!  s    zPath.parent)rB   )r+   )r4   r5   r6   r7   rc   rE   rL   propertyr(   rV   rX   rY   rZ   rH   r\   rJ   r_   rb   re   rh   __truediv__ri   r
   r
   r
   r   rA      s$   ?
rA   )r   r   )rN   r   r-   r   r<   sysversion_infocollectionsr   dictr   r   fromkeysr   r   r.   r   r;   r/   rA   r
   r
   r
   r   <module>   s    
1