a †oeœ+ã@sÂddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z dgZ dd„Z dd „Z ejZd d „ZGd d „d ƒZGdd„deejƒZGdd„deƒZddd„ZGdd„dƒZdS)éNé©Ú text_encoding)Ú translateÚ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('')) [] rN)Ú itertoolsÚisliceÚ _ancestry)Úpath©r ú.C:\Program Files\Certbot\pkgs\zipp\__init__.pyÚ_parentssr ccs4| 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=srcs4eZdZdZ‡fdd„Zdd„Z‡fdd„Z‡ZS)ÚInitializedStatez? Mix-in to save the initialization state for pickling. cs"||_||_tƒj|i|¤ŽdS©N)Ú_InitializedState__argsÚ_InitializedState__kwargsÚsuperÚ__init__)ÚselfÚargsÚkwargs©Ú __class__r r rJszInitializedState.__init__cCs |j|jfSr)rr©rr r r Ú __getstate__OszInitializedState.__getstate__cs|\}}tƒj|i|¤ŽdSr)rr)rÚstaterrr r r Ú __setstate__RszInitializedState.__setstate__)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr#r%Ú __classcell__r r r r rEs rcsleZdZdZedd„ƒZ‡fdd„Zdd„Zdd „Z‡fd d „Z e d d „ƒZ e e j e j dœdd„ƒZ‡ZS)Ú CompleteDirsa8 A ZipFile subclass that ensures that implied directories are always included in the namelist. >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt'])) ['foo/', 'foo/bar/'] >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt', 'foo/bar/'])) ['foo/'] cCs.tj tt|ƒ¡}dd„|Dƒ}tt||ƒƒS)Ncss|]}|tjVqdSr)rr)Ú.0Úpr r r Ú eóz-CompleteDirs._implied_dirs..)rÚchainÚ from_iterableÚmapr Ú_deduper)ÚnamesÚparentsZas_dirsr r r Ú _implied_dirsbszCompleteDirs._implied_dirscstƒ ¡}|t| |¡ƒSr)rÚnamelistÚlistr6)rr4r r r r7hs zCompleteDirs.namelistcCs t| ¡ƒSr)rr7r"r r r Ú _name_setlszCompleteDirs._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). ú/)r9)rÚnamer4ÚdirnameZ dir_matchr r r Ú resolve_diroszCompleteDirs.resolve_dircsJztƒ |¡WStyD| d¡r2|| ¡vr4‚tj|d�YS0dS)z6 Supplement getinfo for implied dirs. r:)ÚfilenameN)rÚgetinfoÚKeyErrorÚendswithr9ÚzipfileZZipInfo)rr;r r r r?ys  zCompleteDirs.getinfocCs:t|tƒr|St|tjƒs"||ƒSd|jvr0t}||_|S)zl Given a source (filename or zipfile), return an appropriate CompleteDirs subclass. Úr)Ú isinstancer+rBÚZipFileÚmoder!)ÚclsÚsourcer r r Úmake„s   zCompleteDirs.make)ÚzfÚreturncCs$| | ¡¡D]}| |d¡q|S)z‰ Given a writable zip file zf, inject directory entries for any directories implied by the presence of children. r/)r6r7Zwritestr)rGrJr;r r r Úinject—szCompleteDirs.inject)r&r'r(r)Ú staticmethodr6r7r9r=r?Ú classmethodrIrBrErLr*r r r r r+Ws     r+cs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú FastLookupzV ZipFile subclass to ensure implicit dirs exist and are resolved rapidly. csBt t¡�|jWdƒS1s&0Ytƒ ¡|_|jSr)Ú contextlibÚsuppressÚAttributeErrorZ_FastLookup__namesrr7r"r r r r7¨s $ zFastLookup.namelistcsBt t¡�|jWdƒS1s&0Ytƒ ¡|_|jSr)rPrQrRZ_FastLookup__lookuprr9r"r r r r9®s $ zFastLookup._name_set)r&r'r(r)r7r9r*r r r r rO¢s rOcOst|dƒ||fS)Nér)Úencodingrrr r r Ú_extract_text_encodingµsrUc@seZdZdZdZd=dd„Zdd„Zdd „Zd>d d œd d„Zdd„Z e dd„ƒZ e dd„ƒZ e dd„ƒZ e dd„ƒZe dd„ƒZdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„ZeZ e d;d<„ƒZ!d S)?ru¹ 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 >>> path = Path(zf) From there, several path operations are available. Directory iteration (including the zip file itself): >>> a, b = path.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(encoding='utf-8') '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. >>> str(path) 'mem/abcde.zip/' >>> path.name 'abcde.zip' >>> path.filename == pathlib.Path('mem/abcde.zip') True >>> str(path.parent) 'mem' If the zipfile has no filename, such attribtues are not valid and accessing them will raise an Exception. >>> zf.filename = None >>> path.name Traceback (most recent call last): ... TypeError: ... >>> path.filename Traceback (most recent call last): ... TypeError: ... >>> path.parent Traceback (most recent call last): ... TypeError: ... # workaround python/cpython#106763 >>> pass 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)rOrIÚrootÚat)rrWrXr r r r s z Path.__init__cCs(|j|jurtS|j|jf|j|jfkS)zU >>> Path(zipfile.ZipFile(io.BytesIO(), 'w')) == 'foo' False )r!ÚNotImplementedrWrX)rÚotherr r r Ú__eq__-s z Path.__eq__cCst|j|jfƒSr)ÚhashrWrXr"r r r Ú__hash__6sz Path.__hash__rCN©ÚpwdcOsŽ| ¡rt|ƒ‚|d}| ¡s0|dkr0t|ƒ‚|jj|j||d�}d|vr`|sT|r\tdƒ‚|St|i|¤Ž\}}}t j ||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(). rrCr^Úbz*encoding args invalid for binary operation) Úis_dirÚIsADirectoryErrorÚexistsÚFileNotFoundErrorrWÚopenrXÚ ValueErrorrUÚioÚ TextIOWrapper)rrFr_rrZzip_modeÚstreamrTr r r re9sz Path.opencCst |jp|jj¡Sr)ÚpathlibÚ PurePosixPathrXrWr>r"r r r Ú_baseMsz Path._basecCs | ¡jSr)rlr;r"r r r r;Psz Path.namecCs | ¡jSr)rlÚsuffixr"r r r rmTsz Path.suffixcCs | ¡jSr)rlÚsuffixesr"r r r rnXsz Path.suffixescCs | ¡jSr)rlÚstemr"r r r ro\sz Path.stemcCst |jj¡ |j¡Sr)rjrrWr>ÚjoinpathrXr"r r r r>`sz Path.filenamecOsZt|i|¤Ž\}}}|jd|g|¢Ri|¤Ž�}| ¡WdƒS1sL0YdS)NrC)rUreÚread)rrrrTÚstrmr r r Ú read_textdszPath.read_textcCs6| d¡�}| ¡WdƒS1s(0YdS)NÚrb)rerq)rrrr r r Ú read_bytesis zPath.read_bytescCst |j d¡¡|j d¡kS©Nr:)rr<rXr)rr r r r Ú _is_childmszPath._is_childcCs| |j|¡Sr)r!rW)rrXr r r Ú_nextpsz Path._nextcCs|j p|j d¡Srv)rXrAr"r r r rassz Path.is_dircCs| ¡o| ¡ Sr)rcrar"r r r Úis_filevsz Path.is_filecCs|j|j ¡vSr)rXrWr9r"r r r rcysz Path.existscCs.| ¡stdƒ‚t|j|j ¡ƒ}t|j|ƒS)NzCan't listdir a file)rarfr2rxrWr7Úfilterrw)rZsubsr r r Úiterdir|sz Path.iterdircCst |j¡ |¡Sr)rjrkrXÚmatch)rÚ path_patternr r r r|‚sz Path.matchcCsdS)z] Return whether this path is a symlink. Always false (python/cpython#82102). Fr r"r r r Ú is_symlink…szPath.is_symlinkcCsJ|std|›�ƒ‚t |j¡}t |t|ƒ¡j}t|jt ||j   ¡ƒƒS)NzUnacceptable pattern: ) rfÚreÚescaperXÚcompilerÚ fullmatchr2rxrzrWr7)rÚpatternÚprefixÚmatchesr r r Úglob‹s  z Path.globcCs| d|›�¡S)Nz**/)r†)rrƒr r r Úrglob“sz Path.rglobcGst t|ƒt|j|Žƒ¡Sr)rÚrelpathÚstrrp)rrZZextrar r r Ú relative_to–szPath.relative_tocCst |jj|j¡Sr)rÚjoinrWr>rXr"r r r Ú__str__™sz Path.__str__cCs|jj|d�S)Nr")Ú _Path__reprÚformatr"r r r Ú__repr__œsz Path.__repr__cGs&tj|jg|¢RŽ}| |j |¡¡Sr)rr‹rXrxrWr=)rrZÚnextr r r rpŸsz Path.joinpathcCs6|js|jjSt |j d¡¡}|r,|d7}| |¡Srv)rXr>Úparentrr<rrx)rZ parent_atr r r r‘¥s z Path.parent)rV)rC)"r&r'r(r)r�rr[r]rerlÚpropertyr;rmrnror>rsrurwrxraryrcr{r|r~r†r‡rŠrŒr�rpÚ __truediv__r‘r r r r rºsHc       )N)rgrrBrrPrjrZ py310compatrr†rÚ__all__r r ÚdictÚfromkeysr3rrrEr+rOrUrr r r r Ús$  K