o ^@sjddlmZddlZddlZddlZddlZddlZddlZddlZe Z ddZ ddZ GdddZ dS) )divisionNcCstt|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 _ancestrypathr &/usr/lib/python3/dist-packages/zipp.py_parentssr ccsN|tj}|r!|tjkr%|Vt|\}}|r#|tjksdSdSdSdS)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)rtailr r r r$s  rc@seZdZdZdZd,ddZeddZedd Z ed d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZd d!ZeZed"d#Zed$d%Zed&d'Zd(d)Zejd*krleZd+Sd+S)-Pathu 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 = '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('abcde.zip', 'a.txt') >>> b Path('abcde.zip', 'b/') name property: >>> b.name 'b' join with divide operator: >>> c = b / 'c.txt' >>> c Path('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: >>> str(c) 'abcde.zip/b/c.txt' z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})cCs,t|tjr|nt|||_||_dSN) isinstancezipfileZipFile_pathlib_compatrootat)selfrrr r r __init__}s  z Path.__init__cCs&z|WStyt|YSw)zu For path-like objects, convert to a filename for compatibility on Python 3.6.1 and earlier. ) __fspath__AttributeErrorstrrr r r rs    zPath._pathlib_compatcCt|jj|jSr) functoolspartialropenrrr r r r"z Path.opencCst|jdSN/)r basenamerr r#r r r namer$z Path.namecOsH|}tj|g|Ri|WdS1swYdSr)r"io TextIOWrapperread)rargskwargsstrmr r r read_texts $zPath.read_textcCs4| }|WdS1swYdSr)r"r+)rr.r r r read_bytess $zPath.read_bytescCst|jd|jdkSr%)r dirnamerr )rrr r r _is_childszPath._is_childcCs t|j|Sr)rr)rrr r r _nexts z Path._nextcCs|j p |jdSr%)rendswithr#r r r is_dirsz Path.is_dircCs | Sr)r5r#r r r is_files z Path.is_filecCs|j|vSr)r_namesr#r r r existsz Path.existscCs,|stdt|j|}t|j|S)NzCan't listdir a file)r5 ValueErrormapr3r7filterr2)rsubsr r r iterdirs z Path.iterdircCrr)r joinrfilenamerr#r r r __str__sz Path.__str__cCs|jj|dS)Nr#) _Path__reprformatr#r r r __repr__r9z Path.__repr__cCsP||}t|j|}t|j|d}|}|||vr%||vr%|S|S)Nr)rr r?rr7r3)raddnextnext_dirnamesr r r joinpaths  z Path.joinpathcstfddDS)Nc3s2|]}t|D] }|dvr|dVqqdS)r&N)r ).0r(parentrHr r s z%Path._implied_dirs..)more_itertoolsunique_everseenrLr rLr _implied_dirsszPath._implied_dirscCs|t||Sr)listrP)clsrHr r r _add_implied_dirsr$zPath._add_implied_dirscCs(t|jd}|r|d7}||Sr%)r r1rr r3)r parent_atr r r rKs z Path.parentcCs||jSr)rSrnamelistr#r r r r7sz Path._names)N)r)__name__ __module__ __qualname____doc__rBr staticmethodrpropertyr"r(r/r0r2r3r5r6r8r>rArDrI __truediv__rP classmethodrSrKr7sys version_info__div__r r r r r:s@@        r) __future__rr)r_r rr rrNtype __metaclass__r rrr r r r s