a „oeé ã@s´ddlZddlZddlZddlZddlZddlZddlZejdkrPddlm Z ne Z dgZ dd„Z dd„Z e jZd d „ZGd d „d ejƒZGd d„deƒZdd„ZGdd„dƒZdS)éN)éé)Ú OrderedDictÚPathcCst t|ƒ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 ú8C:\Program Files\Certbot\pkgs\setuptools\_vendor\zipp.pyÚ_parentssrccs4| tj¡}|r0|tjkr0|Vt |¡\}}q dS)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 cCst t|ƒj|¡S)zZ Return items in minuend not in subtrahend, retaining order with O(1) lookup. )rÚ filterfalseÚsetÚ __contains__)ZminuendZ subtrahendr r r Ú _difference?srcsHeZdZdZedd„ƒZ‡fdd„Zdd„Zdd „Ze d d „ƒZ ‡Z S) Ú CompleteDirszk A ZipFile subclass that ensures that implied directories are always included in the namelist. cCs.tj tt|ƒ¡}dd„|Dƒ}tt||ƒƒS)Ncss|]}|tjVqdS©N)rr)Ú.0Úpr r r Ú Póz-CompleteDirs._implied_dirs..)rÚchainÚ from_iterableÚmaprÚ_deduper)ÚnamesÚparentsZas_dirsr r r Ú _implied_dirsMszCompleteDirs._implied_dirscs tt|ƒ ¡}|t| |¡ƒSr)ÚsuperrÚnamelistÚlistr$)Úselfr"©Ú __class__r r r&SszCompleteDirs.namelistcCs t| ¡ƒSr)rr&©r(r r r Ú _name_setWszCompleteDirs._name_setcCs,| ¡}|d}||vo||v}|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_dirZszCompleteDirs.resolve_dircCs>t|tƒr|St|tjƒs&|t|ƒƒSd|jvr4t}||_|S)zl Given a source (filename or zipfile), return an appropriate CompleteDirs subclass. Úr)Ú isinstancerÚzipfileÚZipFileÚ_pathlib_compatÚmoder*)ÚclsÚsourcer r r Úmakeds    zCompleteDirs.make) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú staticmethodr$r&r,r0Ú classmethodr9Ú __classcell__r r r)r rGs   rcs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú FastLookupzV ZipFile subclass to ensure implicit dirs exist and are resolved rapidly. csFt t¡�|jWdƒS1s&0Ytt|ƒ ¡|_|jSr)Ú contextlibÚsuppressÚAttributeErrorZ_FastLookup__namesr%rAr&r+r)r r r&~s $zFastLookup.namelistcsFt t¡�|jWdƒS1s&0Ytt|ƒ ¡|_|jSr)rBrCrDZ_FastLookup__lookupr%rAr,r+r)r r r,„s $zFastLookup._name_set)r:r;r<r=r&r,r@r r r)r rAxs rAcCs*z | ¡WSty$t|ƒYS0dS)zi For path-like objects, convert to a filename for compatibility on Python 3.6.1 and earlier. N)Ú __fspath__rDÚstrr r r r r5‹s  r5c@sÒeZdZdZdZd-dd„Zd.ddœd d „Zed d „ƒZed d„ƒZ edd„ƒZ edd„ƒZ edd„ƒ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})ÚcCst |¡|_||_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)rAr9ÚrootÚat)r(rHrIr r r Ú__init__æs z Path.__init__r1N©ÚpwdcOsx| ¡rt|ƒ‚|d}| ¡s0|dkr0t|ƒ‚|jj|j||d�}d|vr`|sT|r\tdƒ‚|Stj |g|¢Ri|¤ŽS)zª Open this entry as text or binary following the semantics of ``pathlib.Path.open()`` by passing arguments through to io.TextIOWrapper(). rr1rKÚbz*encoding args invalid for binary operation) Úis_dirÚIsADirectoryErrorÚexistsÚFileNotFoundErrorrHÚopenrIÚ ValueErrorÚioÚ TextIOWrapper)r(r6rLÚargsÚkwargsZzip_modeÚstreamr r r rRósz Path.opencCst |j¡jp|jjSr)ÚpathlibrrIr.Úfilenamer+r r r r.sz Path.namecCst |j¡jp|jjSr)rYrrIÚsuffixrZr+r r r r[ sz Path.suffixcCst |j¡jp|jjSr)rYrrIÚsuffixesrZr+r r r r\ sz Path.suffixescCst |j¡jp|jjSr)rYrrIÚstemrZr+r r r r]sz Path.stemcCst |jj¡ |j¡Sr)rYrrHrZÚjoinpathrIr+r r r rZsz Path.filenamecOsD|jdg|¢Ri|¤Ž�}| ¡WdƒS1s60YdS)Nr1©rRÚread)r(rVrWÚstrmr r r Ú read_textszPath.read_textcCs6| d¡�}| ¡WdƒS1s(0YdS)NÚrbr_)r(rar r r Ú read_bytess zPath.read_bytescCst |j d¡¡|j d¡kS©Nr-)rr/rIr)r(r r r r Ú _is_child!szPath._is_childcCs| |j|¡Sr)r*rH)r(rIr r r Ú_next$sz Path._nextcCs|j p|j d¡Sre)rIÚendswithr+r r r rN'sz Path.is_dircCs| ¡o| ¡ Sr)rPrNr+r r r Úis_file*sz Path.is_filecCs|j|j ¡vSr)rIrHr,r+r r r rP-sz Path.existscCs.| ¡stdƒ‚t|j|j ¡ƒ}t|j|ƒS)NzCan't listdir a file)rNrSr rgrHr&Úfilterrf)r(Zsubsr r r Úiterdir0sz Path.iterdircCst |jj|j¡Sr)rÚjoinrHrZrIr+r r r Ú__str__6sz Path.__str__cCs|jj|d�S)Nr+)Ú _Path__reprÚformatr+r r r Ú__repr__9sz Path.__repr__cGs,tj|jgtt|ƒ¢RŽ}| |j |¡¡Sr)rrlrIr r5rgrHr0)r(ÚotherÚnextr r r r^<sz Path.joinpathcCs6|js|jjSt |j d¡¡}|r,|d7}| |¡Sre)rIrZÚparentrr/rrg)r(Z parent_atr r r rsBs z Path.parent)rG)r1)r:r;r<r=rnrJrRÚpropertyr.r[r\r]rZrbrdrfrgrNrirPrkrmrpr^Ú __truediv__rsr r r r r–s8M      )rTrr3rrBÚsysrYÚ version_infoÚ collectionsrÚdictÚ__all__rr Úfromkeysr!rr4rrAr5rr r r r Ús$ 1