U C^f@sPddlmZmZmZddlZddlmZmZddlm Z m Z GdddeZ dS))print_functiondivisionabsolute_importN)AbstractFileSystem open_files)tokenizeDEFAULT_BLOCK_SIZEcs^eZdZdZdZdddZefddZdd Zdd d Z d dZ dddZ ddZ Z S) ZipFileSystemzRead contents of ZIP archive as a file-system Keeps file object open while instance lives. This class is pickleable, but not necessarily thread-safe rcKs|jr dSt||dkr$td||_t|tr`t|}t|dkrXtd |||d}| |_ t |j |_|dt|_d|_dS)a Parameters ---------- fo: str or file-like Contains ZIP, and must exist. If a str, will fetch file using `open_files()`, which must return one file exactly. mode: str Currently, only 'r' accepted storage_options: key-value May be credentials, e.g., `{'auth': ('username', 'pword')}` or any other parameters for requests Nr z!Only read from zip files acceptedz2Path "{}" did not resolve to exactlyone file: "{}"r block_size)_cachedr__init__ ValueErrorin_fo isinstancestrrlenformat __enter__fozipfileZipFilezipgetrr dir_cache)selfrmodeZstorage_optionsfilesr >/tmp/pip-install-6_kvzl1k/fsspec/fsspec/implementations/zip.pyrs(     zZipFileSystem.__init__cst|dS)N/)super_strip_protocollstrip)clspath __class__r r!r$2szZipFileSystem._strip_protocolcsn|jdkrj|j}i|_|D]JfddtjjD}|jj rPdndd||j|d<qdS)Ncsi|]}|t|qSr )getattr).0szr r! <sz+ZipFileSystem._get_dirs.. directoryfilenamesizetyper3) rrinfolistrZipInfo __slots__updatefilename file_sizeis_dir)rrfr r-r! _get_dirs7s  zZipFileSystem._get_dirsFc Csn|i}|jD]$\}}|d}d|krD|ddd}nd}||dkr`|||<q|rtddt|d|ddDrd |ddt |dd}||kr|dddd}|||<qtd dt|ddg|ddDr|dddd}||kr|dddd}|||<qt | }|rT|St t d d|DSdS) Nr"r rr css|]\}}||kVqdSNr r+abr r r! Qsz#ZipFileSystem.ls..r0r2css|]\}}||kVqdSr?r r@r r r!rCZscss|]}|dVqdS)r3Nr )r+r=r r r!rCgs)r>ritemsrstriprsplitallrsplitstripjoinrlistvaluessorted) rr'Zdetailpathspr=rootZppathoutr r r!lsFs6   &    zZipFileSystem.lscCs |j|Sr?)rreadrr'r r r!catiszZipFileSystem.catrbNTc KsF||}|dkrt||}|j|d}|d|_|d|_|S)NrVr r4r3)r$NotImplementedErrorinforopenr4r3) rr'rr Z autocommitZ cache_optionskwargsrXrQr r r!_openls    zZipFileSystem._opencCst||j|jSr?)rrprotocolrTr r r!ukey~szZipFileSystem.ukey)r r )F)rVNTN)__name__ __module__ __qualname____doc__Z root_markerr classmethodr$r>rRrUr[r] __classcell__r r r(r!r s  # r ) __future__rrrrZfsspecrrZ fsspec.utilsrrr r r r r!s