_d ddlZddlZddlZddlZddlZddlZddlZejdkrddlm Z ne Z dgZ dZ dZ e jZ dZGdd ej"ZGd d eZd ZGd dZy)N)) OrderedDictPathcBtjt|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('')) [] N) itertoolsislice _ancestrypaths 9/usr/lib/python3/dist-packages/setuptools/_vendor/zipp.py_parentsrs   IdOQ 55c#K|jtj}|rH|tjk7r4|tj|\}}|r|tjk7r2yyyyw)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 tails rr r %sV ;;y}} %D 49==( __T* d 49==($($s A&A-)A-cTtjt|j|S)zZ Return items in minuend not in subtrahend, retaining order with O(1) lookup. )r filterfalseset __contains__)minuend subtrahends r _differencer?s!  Z!=!=w GGrcNeZdZdZedZfdZdZdZe dZ xZ S) CompleteDirszk A ZipFile subclass that ensures that implied directories are always included in the namelist. ctjjtt|}d|D}t t ||S)Nc3BK|]}|tjzywN)rr).0ps r z-CompleteDirs._implied_dirs..Ps61y}}$6s)r chain from_iterablemapr_deduper)namesparentsas_dirss r _implied_dirszCompleteDirs._implied_dirsMs9////He0DE6g6{7E233rcbtt| }|t|j |zSr")superrnamelistlistr-)selfr* __class__s rr0zCompleteDirs.namelistSs-lD24tD..u5666rc4t|jSr")rr0r2s r _name_setzCompleteDirs._name_setWs4==?##rcL|j}|dz}||vxr||v}|r|S|S)zx If the name represents a directory, return that name as a directory (with the trailing slash). /)r6)r2namer*dirname dir_matchs r resolve_dirzCompleteDirs.resolve_dirZs:  *%:'U*: #w--rct|tr|St|tjs|t |Sd|j vrt}||_|S)zl Given a source (filename or zipfile), return an appropriate CompleteDirs subclass. r) isinstancerzipfileZipFile_pathlib_compatmoder3)clssources rmakezCompleteDirs.makedsQ fl +M&'//2v./ / fkk !C r) __name__ __module__ __qualname____doc__ staticmethodr-r0r6r< classmethodrF __classcell__r3s@rrrGs? 44 7$.rrc,eZdZdZfdZfdZxZS) FastLookupzV ZipFile subclass to ensure implicit dirs exist and are resolved rapidly. ctjt5|jcdddS#1swYnxYwtt ||_|jSr") contextlibsuppressAttributeError_FastLookup__namesr/rPr0r2r3s rr0zFastLookup.namelist~sH   0 <<   Z79 || 1:ctjt5|jcdddS#1swYnxYwtt ||_|jSr")rRrSrT_FastLookup__lookupr/rPr6rVs rr6zFastLookup._name_setsH   0 !== ! ! !j$9; }}rW)rGrHrIrJr0r6rMrNs@rrPrPxs  rrPcX |jS#t$rt|cYSwxYw)zi For path-like objects, convert to a filename for compatibility on Python 3.6.1 and earlier. ) __fspath__rTstrr s rrBrBs-   4ys ))ceZdZdZdZddZddddZedZedZ ed Z ed Z ed Z d Z d ZdZdZdZdZdZdZdZdZdZeZedZy)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})cFtj||_||_y)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)rPrFrootat)r2r_r`s r__init__z Path.__init__sOOD) rNpwdc.|jr t||d}|js|dk(r t||jj |j ||}d|vr|s|r td|Stj|g|i|S)z Open this entry as text or binary following the semantics of ``pathlib.Path.open()`` by passing arguments through to io.TextIOWrapper(). rr>rbbz*encoding args invalid for binary operation) is_dirIsADirectoryErrorexistsFileNotFoundErrorr_openr` ValueErrorio TextIOWrapper)r2rCrcargskwargszip_modestreams rrjz Path.opens ;;=#D) )7{{}S#D) )s; $;v !MNNM8888rctj|jjxs|jjSr")pathlibrr`r9filenamer5s rr9z Path.name*||DGG$))?T]]-?-??rctj|jjxs|jjSr")rsrr`suffixrtr5s rrwz Path.suffix s*||DGG$++Ct}}/C/CCrctj|jjxs|jjSr")rsrr`suffixesrtr5s rryz Path.suffixes s*||DGG$--G1G1GGrctj|jjxs|jjSr")rsrr`stemrtr5s rr{z Path.stemrurctj|jjj |j Sr")rsrr_rtjoinpathr`r5s rrtz Path.filenames*||DII../88AArcz|jdg|i|5}|jcdddS#1swYyxYw)Nr>rjread)r2rnrostrms r read_textzPath.read_texts: TYYs ,T ,V , 99;   s1:cp|jd5}|jcdddS#1swYyxYw)Nrbr)r2rs r read_byteszPath.read_bytess- YYt_ 99;   s,5ctj|jjd|jjdk(SNr8)rr:r`r)r2r s r _is_childzPath._is_child!s2  !459LLLrc:|j|j|Sr")r3r_)r2r`s r_nextz Path._next$s~~dii,,rcV|j xs|jjdSr)r`endswithr5s rrfz Path.is_dir's"77{3dgg..s33rcH|jxr|j Sr")rhrfr5s ris_filez Path.is_file*s{{}2T[[]!22rcN|j|jjvSr")r`r_r6r5s rrhz Path.exists-sww$))--///rc|js tdt|j|jj }t |j|S)NzCan't listdir a file)rfrkr(rr_r0filterr)r2subss riterdirz Path.iterdir0sE{{}34 44::tyy1134dnnd++rcjtj|jj|jSr")rjoinr_rtr`r5s r__str__z Path.__str__6s!~~dii00$''::rc:|jj|S)Nr5) _Path__reprformatr5s r__repr__z Path.__repr__9s{{!!t!,,rctj|jgtt|}|j |j j|Sr")rrr`r(rBrr_r<)r2othernexts rr}z Path.joinpath<s>~~dggDOU(CDzz$))//566rc|js|jjStj|jj d}|r|dz }|j |Sr)r`rtparentrr:rr)r2 parent_ats rrz Path.parentBsRww=='' '%%dggnnS&9:   Izz)$$r))r>)rGrHrIrJrrarjpropertyr9rwryr{rtrrrrrfrrhrrrr} __truediv__rrrrrsKZNF 99$@@DDHH@@BBM-430, ;-7K %%r)rlrr@r rRsysrs version_info collectionsrdict__all__rr fromkeysr)rrArrPrBrrrrrs  f'K (6&+,   /H.7??.b&s%s%r