L i>ddlZddlZddlZddlmZGddeZy)N)AbstractArchiveFileSystemceZdZdZdZdZdZddddejddffd Z e fd Z d Z d Z d Zd Z ddZddZxZS) ZipFileSystemzRead/Write contents of ZIP archive as a file-system Keeps file object open while instance lives. This class is pickleable, but not necessarily thread-safe zipFrNTc t ||fi||tdvrtd|d||_t |t tjfr*|dk(rd} n|dz} tj|f| |d|xsi}||_ ||_ |j|_tj |j|||||_d |_y ) a Parameters ---------- fo: str or file-like Contains ZIP, and must exist. If a str, will fetch file using :meth:`~fsspec.open_files`, which must return one file exactly. mode: str Accept: "r", "w", "a" target_protocol: str (optional) If ``fo`` is a string, this value can be used to override the FS protocol inferred from a URL target_options: dict (optional) Kwargs passed when instantiating the target FS, if ``fo`` is a string. compression, allowZip64, compresslevel: passed to ZipFile Only relevant when creating a ZIP rwazmode 'z' no understoodazr+bb)modeprotocol)r compression allowZip64 compresslevelN)super__init__set ValueErrorr isinstancestrosPathLikefsspecopen force_zip_64of __enter__fozipfileZipFiler dir_cache) selfrr target_protocoltarget_optionsrrrkwargsm __class__s `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fsspec/implementations/zip.pyrzZipFileSystem.__init__s8 (( s5z !vdV?;< < b3 , -s{3J_9G9M2B',,.?? GG#!'  c@t||jdS)N/)r_strip_protocollstrip)clspathr(s r)r-zZipFileSystem._strip_protocolHs w&t,33C88r*cBt|dr|j|`yy)Nr)hasattrcloserr#s r)__del__zZipFileSystem.__del__Ms 4  JJL r*c8|jjy)z;Commits any write changes to the file. Done on ``del`` too.N)rr3r4s r)r3zZipFileSystem.closeRs r*c |j|jtdvr|jj }|j |jj Dcic]'}|jd|jdddd)c}|_|D]}tjjDcic]}|t||d}}|j|jjd|j|jrdndd||j|d<yycc}wcc}w)Nwar,r directory)namesizetypefiler:)r"r rrinfolist _all_dirnamesnamelistrstripr ZipInfo __slots__getattrupdatefilename file_sizeis_dir)r#filesdirnamezsfs r) _get_dirszZipFileSystem._get_dirsVs! >> !TYY#d)%;HH%%'E $11$((2C2C2EF   s##NN3/'&DN .5<__5N5NOQ1d++OO ! 1 1# 6 ! 01 -.qy) .&<Ps *,D6?D;c @|jj||fi|yN)rwritestr)r#r0valuer&s r) pipe_filezZipFileSystem.pipe_filens$00r*c |j|}d|vr>|jtdvr'|j|r t dt |d|jvrd|vr t d|j j||jd|j}d|vr%|j|}|d|_ |d|_ |S) Nrr8z7ZipFS can only be open for reading or writing, not bothwr ) force_zip64r;r:) r-r rexistsOSErrorFileNotFoundErrorrrstriprinfor;r:) r#r0r block_size autocommit cache_optionsr&outr[s r)_openzZipFileSystem._openrs##D) $;499D 1{{4 WXX#D) ) $)) t ST ThhmmD$**S/t?P?PmQ $;99T?DF|CHF|CH r*c  ||dkr td|jd}ttd|j d fd}|j i}||j vr.|j |ddk(r|j |||<|r|S|gS|j jD]D\}} |dk(s ||s| dd k(r|r||vr| ||jd<7||vs<|r| nd||<F|rL|jd} |jD cic] \} } | jd| z |ks| | "}} } |r|St|Scc} } w) Nzmaxdepth must be at least 1r,ct|SrPboolrLs r)z$ZipFileSystem.find..s 47r*cttd|jd}tdt|DS)Nct|SrPrdrfs r)rgz>ZipFileSystem.find.._matching_starts..s $q'r*r,c3,K|] \}}||k(ywrP).0r r s r) z?ZipFileSystem.find.._matching_starts..sF$!QqAvFs)filtersplitallr) file_path file_parts path_partss r)_matching_startsz,ZipFileSystem.find.._matching_startss1 19??33GHJF#j**EFF Fr*r<r=rr9) rr.listrnrorNr"itemsrZcountsorted)r#r0maxdepthwithdirsdetailr&rtresultrq file_info path_depthkvrss @r)findzZipFileSystem.finds  HqL:; ;{{3&!2DJJsODE  G  4>> !dnnT&:6&Bf&L>>$/F4L#6 /$ /$(NN$8$8$: B IyBJ"29"= K/ .7@ys34&17ITy! B CJ!'A1773<*3Lx3W1F v3VF^3s $EE)rbNTN)NFF)__name__ __module__ __qualname____doc__ root_markerrcachabler ZIP_STOREDr classmethodr-r5r3rNrSr`r __classcell__)r(s@r)rrs|KHH  &&2h99 .01 .(4r*r)rr rfsspec.archiverrrkr*r)rs   4i4-i4r*