3

Z'ícé ã@s´ddlZddlZddlZddlZddlZddlZddlZejdkrPddlm	Z	ne
Z	dgZdd„Zdd	„Z
e	jZd
d„ZGdd
„d
ejƒZGdd„deƒZdd„ZGdd„dƒZdS)éNéé)ÚOrderedDictÚPathcCstjt|ƒddƒ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ú$/tmp/pip-build-gk9425m9/zipp/zipp.pyÚ_parentssr
ccs8|jtjƒ}x&|r2|tjkr2|Vtj|ƒ\}}qWdS)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
Útailrrrr	%sr	cCstjt|ƒj|ƒS)zZ
    Return items in minuend not in subtrahend, retaining order
    with O(1) lookup.
    )rÚfilterfalseÚsetÚ__contains__)ZminuendZ
subtrahendrrrÚ_difference?srcsHeZdZdZedd„ƒZ‡fdd„Zdd„Zdd	„Ze	d
d„ƒZ
‡ZS)ÚCompleteDirszk
    A ZipFile subclass that ensures that implied directories
    are always included in the namelist.
    cCs.tjjtt|ƒƒ}dd„|Dƒ}tt||ƒƒS)Ncss|]}|tjVqdS)N)rr)Ú.0Úprrrú	<genexpr>Psz-CompleteDirs._implied_dirs.<locals>.<genexpr>)rÚchainÚ
from_iterableÚmapr
Ú_deduper)ÚnamesÚparentsZas_dirsrrrÚ
_implied_dirsMszCompleteDirs._implied_dirscs tt|ƒjƒ}|t|j|ƒƒS)N)ÚsuperrÚnamelistÚlistr!)Úselfr)Ú	__class__rrr#SszCompleteDirs.namelistcCst|jƒƒS)N)rr#)r%rrrÚ	_name_setWszCompleteDirs._name_setcCs,|jƒ}|d}||ko||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_matchrrrÚresolve_dirZszCompleteDirs.resolve_dircCs>t|tƒr|St|tjƒs&|t|ƒƒSd|jkr4t}||_|S)zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        Úr)Ú
isinstancerÚzipfileÚZipFileÚ_pathlib_compatÚmoder&)ÚclsÚsourcerrrÚmakeds

zCompleteDirs.make)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr!r#r'r+Úclassmethodr4Ú
__classcell__rr)r&rrGs
rcs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c
s.tjtƒ|jSQRXtt|ƒjƒ|_|jS)N)Ú
contextlibÚsuppressÚAttributeErrorZ_FastLookup__namesr"r<r#)r%)r&rrr#~szFastLookup.namelistc
s.tjtƒ|jSQRXtt|ƒjƒ|_|jS)N)r=r>r?Z_FastLookup__lookupr"r<r')r%)r&rrr'„szFastLookup._name_set)r5r6r7r8r#r'r;rr)r&rr<xsr<cCs&y|jƒStk
r t|ƒSXdS)zi
    For path-like objects, convert to a filename for compatibility
    on Python 3.6.1 and earlier.
    N)Ú
__fspath__r?Ústr)r
rrrr0‹sr0c@sÒeZdZdZdZd-dd„Zd.ddœd	d
„Zedd„ƒZed
d„ƒZ	edd„ƒZ
edd„ƒZedd„ƒZdd„Z
dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„ZeZed+d,„ƒZdS)/ru4
    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})ÚcCstj|ƒ|_||_dS)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<r4ÚrootÚat)r%rCrDrrrÚ__init__æs
z
Path.__init__r,N)ÚpwdcOst|jƒrt|ƒ‚|d}|jƒr2|dkr2t|ƒ‚|jj|j||d}d|krb|sV|r^tdƒ‚|Stj	|f|ž|ŽS)zª
        Open this entry as text or binary following the semantics
        of ``pathlib.Path.open()`` by passing arguments through
        to io.TextIOWrapper().
        rr,)rFÚbz*encoding args invalid for binary operation)
Úis_dirÚIsADirectoryErrorÚexistsÚFileNotFoundErrorrCÚopenrDÚ
ValueErrorÚioÚ
TextIOWrapper)r%r1rFÚargsÚkwargsZzip_modeÚstreamrrrrLósz	Path.opencCstj|jƒjp|jjS)N)ÚpathlibrrDr)Úfilename)r%rrrr)sz	Path.namecCstj|jƒjp|jjS)N)rSrrDÚsuffixrT)r%rrrrU	szPath.suffixcCstj|jƒjp|jjS)N)rSrrDÚsuffixesrT)r%rrrrV
sz
Path.suffixescCstj|jƒjp|jjS)N)rSrrDÚstemrT)r%rrrrWsz	Path.stemcCstj|jjƒj|jƒS)N)rSrrCrTÚjoinpathrD)r%rrrrTsz
Path.filenamec	Os$|jd|ž|Ž
}|jƒSQRXdS)Nr,)r,)rLÚread)r%rPrQÚstrmrrrÚ	read_textszPath.read_textc	Cs|jdƒ
}|jƒSQRXdS)NÚrb)rLrY)r%rZrrrÚ
read_bytesszPath.read_bytescCstj|jjdƒƒ|jjdƒkS)Nr()rr*rDr)r%r
rrrÚ	_is_child!szPath._is_childcCs|j|j|ƒS)N)r&rC)r%rDrrrÚ_next$sz
Path._nextcCs|jp|jjdƒS)Nr()rDÚendswith)r%rrrrH'szPath.is_dircCs|jƒo|jƒS)N)rJrH)r%rrrÚis_file*szPath.is_filecCs|j|jjƒkS)N)rDrCr')r%rrrrJ-szPath.existscCs.|jƒstdƒ‚t|j|jjƒƒ}t|j|ƒS)NzCan't listdir a file)rHrMrr_rCr#Úfilterr^)r%ÚsubsrrrÚiterdir0szPath.iterdircCstj|jj|jƒS)N)rÚjoinrCrTrD)r%rrrÚ__str__6szPath.__str__cCs|jj|dS)N)r%)Ú_Path__reprÚformat)r%rrrÚ__repr__9sz
Path.__repr__cGs*tj|jftt|ƒžŽ}|j|jj|ƒƒS)N)rrerDrr0r_rCr+)r%ÚotherÚnextrrrrX<sz
Path.joinpathcCs6|js|jjStj|jjdƒƒ}|r,|d7}|j|ƒS)Nr()rDrTÚparentrr*rr_)r%Z	parent_atrrrrlBszPath.parent)rB)r,)r5r6r7r8rgrErLÚpropertyr)rUrVrWrTr[r]r^r_rHrarJrdrfrirXÚ__truediv__rlrrrrr–s,L

)rr)rNrr.rr=ÚsysrSÚversion_infoÚcollectionsrÚdictÚ__all__r
r	Úfromkeysrrr/rr<r0rrrrrÚ<module>s$
1