a oe+@sddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z dgZ ddZ dd Z ejZd d ZGd d d ZGdddeejZGdddeZdddZGdddZdS)N text_encoding) translatePathcCstt|ddS)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) itertoolsislice _ancestry)pathr .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 posixpathsepsplit)r tailr r r r #s r cCstt|j|S)zZ Return items in minuend not in subtrahend, retaining order with O(1) lookup. )r filterfalseset __contains__)ZminuendZ subtrahendr r r _difference=srcs4eZdZdZfddZddZfddZZS)InitializedStatez? Mix-in to save the initialization state for pickling. cs"||_||_tj|i|dSN)_InitializedState__args_InitializedState__kwargssuper__init__)selfargskwargs __class__r r rJszInitializedState.__init__cCs |j|jfSr)rrrr r r __getstate__OszInitializedState.__getstate__cs|\}}tj|i|dSr)rr)rstaterrr r r __setstate__RszInitializedState.__setstate__)__name__ __module__ __qualname____doc__rr#r% __classcell__r r r r rEs rcsleZdZdZeddZfddZddZdd Zfd d Z e d d Z e e j e j dddZZS) 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.tjtt|}dd|D}tt||S)Ncss|]}|tjVqdSr)rr).0pr r r ez-CompleteDirs._implied_dirs..)rchain from_iterablemapr _deduper)namesparentsZas_dirsr r r _implied_dirsbszCompleteDirs._implied_dirscst}|t||Sr)rnamelistlistr6)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)rnamer4dirnameZ dir_matchr r r resolve_diroszCompleteDirs.resolve_dircsJzt|WStyD|dr2||vr4tj|dYS0dS)z6 Supplement getinfo for implied dirs. r:)filenameN)rgetinfoKeyErrorendswithr9zipfileZZipInfo)rr;r r r r?ys  zCompleteDirs.getinfocCs:t|tr|St|tjs"||Sd|jvr0t}||_|S)zl Given a source (filename or zipfile), return an appropriate CompleteDirs subclass. r) isinstancer+rBZipFilemoder!)clssourcer r r makes   zCompleteDirs.make)zfreturncCs$||D]}||dq|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 injectszCompleteDirs.inject)r&r'r(r) staticmethodr6r7r9r=r? classmethodrIrBrErLr*r r r r r+Ws     r+cs,eZdZdZfddZfddZZS) FastLookupzV ZipFile subclass to ensure implicit dirs exist and are resolved rapidly. csBtt|jWdS1s&0Yt|_|jSr) contextlibsuppressAttributeErrorZ_FastLookup__namesrr7r"r r r r7s $ zFastLookup.namelistcsBtt|jWdS1s&0Yt|_|jSr)rPrQrRZ_FastLookup__lookuprr9r"r r r r9s $ zFastLookup._name_set)r&r'r(r)r7r9r*r r r r rOs rOcOst|d||fS)Nr)encodingrrr r r _extract_text_encodingsrUc@seZdZdZdZd=ddZddZdd Zd>d d d dZddZ e ddZ e ddZ e ddZ e ddZe ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d: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)rOrIrootat)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)rotherr r r __eq__-s z Path.__eq__cCst|j|jfSr)hashrWrXr"r r r __hash__6sz Path.__hash__rCNpwdcOs|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_dirIsADirectoryErrorexistsFileNotFoundErrorrWopenrX ValueErrorrUio TextIOWrapper)rrFr_rrZzip_modestreamrTr r r re9sz Path.opencCst|jp|jjSr)pathlib PurePosixPathrXrWr>r"r r r _baseMsz Path._basecCs |jSr)rlr;r"r r r r;Psz Path.namecCs |jSr)rlsuffixr"r r r rmTsz Path.suffixcCs |jSr)rlsuffixesr"r r r rnXsz Path.suffixescCs |jSr)rlstemr"r r r ro\sz Path.stemcCst|jj|jSr)rjrrWr>joinpathrXr"r r r r>`sz Path.filenamecOsZt|i|\}}}|jd|g|Ri|}|WdS1sL0YdS)NrC)rUreread)rrrrTstrmr r r read_textdszPath.read_textcCs6|d}|WdS1s(0YdS)Nrb)rerq)rrrr r r read_bytesis zPath.read_bytescCst|jd|jdkSNr:)rr<rXr)rr r r r _is_childmszPath._is_childcCs||j|Sr)r!rW)rrXr r r _nextpsz Path._nextcCs|j p|jdSrv)rXrAr"r r r rassz Path.is_dircCs|o| Sr)rcrar"r r r is_filevsz Path.is_filecCs|j|jvSr)rXrWr9r"r r r rcysz Path.existscCs.|stdt|j|j}t|j|S)NzCan't listdir a file)rarfr2rxrWr7filterrw)rZsubsr r r iterdir|sz Path.iterdircCst|j|Sr)rjrkrXmatch)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_symlinkszPath.is_symlinkcCsJ|std|t|j}t|t|j}t|jt ||j S)NzUnacceptable pattern: ) rfreescaperXcompiler fullmatchr2rxrzrWr7)rpatternprefixmatchesr r r globs  z Path.globcCs|d|S)Nz**/)r)rrr r r rglobsz Path.rglobcGstt|t|j|Sr)rrelpathstrrp)rrZZextrar r r relative_toszPath.relative_tocCst|jj|jSr)rjoinrWr>rXr"r r r __str__sz Path.__str__cCs|jj|dS)Nr") _Path__reprformatr"r r r __repr__sz Path.__repr__cGs&tj|jg|R}||j|Sr)rrrXrxrWr=)rrZnextr r r rpsz Path.joinpathcCs6|js|jjSt|jd}|r,|d7}||Srv)rXr>parentrr<rrx)rZ parent_atr r r rs z Path.parent)rV)rC)"r&r'r(r)rrr[r]rerlpropertyr;rmrnror>rsrurwrxraryrcr{r|r~rrrrrrp __truediv__rr r r r rsHc       )N)rgrrBrrPrjrZ py310compatrrr__all__r r dictfromkeysr3rrrEr+rOrUrr r r r s$  K