7fdZddgZddlmZmZddlmZddlmZddl m Z m Z m Z m Z mZmZddlmZmZdd lmZdd lmZmZdd lmZmZmZdd lmZdd lmZm Z m!Z!Gdde"Z#de$de$dedefdZ%GddZ&dS)zLazy ZIP over HTTPHTTPRangeRequestUnsupporteddist_from_wheel_url) bisect_left bisect_right)contextmanager)NamedTemporaryFile)AnyDict GeneratorListOptionalTuple) BadZipFileZipFile)canonicalize_name)CONTENT_CHUNK_SIZEResponse)BaseDistribution MemoryWheelget_wheel_distribution) PipSession)HEADERSraise_for_statusresponse_chunksceZdZdS)rN)__name__ __module__ __qualname__/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pip/_internal/network/lazy_wheel.pyrrsDr nameurlsessionreturnct||5}t|j|}t|t |cdddS#1swxYwYdS)aReturn a distribution object from the given wheel URL. This uses HTTP range requests to only fetch the portion of the wheel containing metadata, just enough for the object to be constructed. If such requests are not supported, HTTPRangeRequestUnsupported is raised. N)LazyZipOverHTTPrr"rr)r"r#r$zfwheels r!rrs g & &F"BGR((&e->t-D-DEE FFFFFFFFFFFFFFFFFFs2AAAc eZdZdZefdedededdfdZe defdZ e defd Z de fd Z d&d Ze de fd Zd'dedefdZde fdZd(dededefdZdefdZd)deedefdZde fdZd*dZdeddfdZededfdZd&dZefdeded e eefde!fd!Z"deded"ed#edee#eefddff d$Z$dededdfd%Z%dS)+r'aFile-like object mapped to a ZIP file over HTTP. This uses HTTP range requests to lazily fetch the file's content, which is supposed to be fed to ZipFile. If such requests are not supported by the server, raise HTTPRangeRequestUnsupported during initialization. r#r$ chunk_sizer%Nc||t}t||jdksJ|||c|_|_|_t|jd|_ t|_ | |j g|_ g|_d|jddvrt!d|dS)N)headerszContent-Lengthbytesz Accept-Rangesnonezrange request is not supported)headrr status_code_session_url _chunk_sizeintr-_lengthr_filetruncate_left_rightgetr _check_zip)selfr#r$r+r1s r!__init__zLazyZipOverHTTP.__init__1s||C|113&&&&5s r!modezLazyZipOverHTTP.modeAs tr c|jjS)zPath to the underlying file.)r8r"rBs r!r"zLazyZipOverHTTP.nameFszr cdS)z9Return whether random access is supported, which is True.TrrBs r!seekablezLazyZipOverHTTP.seekableKtr c8|jdS)zClose the file.N)r8closerBs r!rIzLazyZipOverHTTP.closeOs r c|jjS)zWhether the file is closed.)r8closedrBs r!rKzLazyZipOverHTTP.closedSsz  r sizec$t||j}||j}}|dkr|nt ||z|}td||z }|||dz |j|S)zRead up to size bytes from the object and return them. As a convenience, if size is unspecified or -1, all bytes until EOF are returned. Fewer than size bytes may be returned if EOF is reached. r)maxr5tellr7min _downloadr8read)r>rM download_sizestartlengthstops r!rTzLazyZipOverHTTP.readXsD$"233  T\vvvs5=+@&'I'IAtm+,, udQh'''zt$$$r cdS)z3Return whether the file is readable, which is True.TrrBs r!readablezLazyZipOverHTTP.readablefrGr roffsetwhencec8|j||S)a-Change stream position and return the new absolute position. Seek to offset relative position indicated by whence: * 0: Start of stream (the default). pos should be >= 0; * 1: Current position - pos may be negative; * 2: End of stream - pos usually negative. )r8seek)r>r[r\s r!r^zLazyZipOverHTTP.seekjszvv...r c4|jS)zReturn the current position.)r8rQrBs r!rQzLazyZipOverHTTP.telltsz   r c6|j|S)zResize the stream to the given size in bytes. If size is unspecified resize to the current position. The current stream position isn't changed. Return the new file size. )r8r9)r>rMs r!r9zLazyZipOverHTTP.truncatexsz""4(((r cdS)z Return False.FrrBs r!writablezLazyZipOverHTTP.writablesur c8|j|SN)r8 __enter__rBs r!rezLazyZipOverHTTP.__enter__s  r excc$|jj|dSrd)r8__exit__)r>rfs r!rhzLazyZipOverHTTP.__exit__s S!!!!r )NNNc#K|} dV||dS#||wxYw)zyReturn a context manager keeping the position. At the end of the block, seek back to original position. N)rQr^)r>poss r!_stayzLazyZipOverHTTP._staysJ iikk  EEE IIcNNNNNDIIcNNNNs 3A cJ|jdz }ttd||jD]t}||||5 t | ddddS#t$rYnwxYw dddn #1swxYwYudS)z1Check and download until the file is a valid ZIP.rOrN)r7reversedranger5rSrkrr)r>endrVs r!r=zLazyZipOverHTTP._check_zipslQeAsD,<==>>  E NN5# & & &  DMMM          "D                  s6BA:+B: BBBBB B rVro base_headersc|}d|d||d<d|d<|j|j|dS)z:Return HTTP response to a range request from start to end.zbytes=-Rangezno-cachez Cache-ControlT)r-stream)copyr3r<r4)r>rVrorpr-s r!_stream_responsez LazyZipOverHTTP._stream_responsesX##%%1E11C11#- }  GD IIIr leftrightc#XK|j|||j||}}t|g|ddzx}}t|g|ddz}t ||D]\}} ||kr ||dz fV| dz}||kr||fV|g|gc|j||<|j||<dS)a/Return a generator of intervals to be fetched. Args: start (int): Start of needed interval end (int): End of needed interval left (int): Index of first overlapping downloaded data right (int): Index after last overlapping downloaded data NrOrL)r:r;rRrPzip) r>rVrorwrxlslicersliceijks r!_mergezLazyZipOverHTTP._mergesDJ/T%Z1H&!*,---E3%&+%&&''  DAq1uuQhAAA 88S&LLL;@'C57 4: DJ 7 7 7r c|5t|j|}t|j|}|||||D]v\}}|||}|||t||j D]}|j |w ddddS#1swxYwYdS)z-Download bytes from start to end inclusively.N) rkrr;rr:rrvrr^rr5r8write)r>rVrorwrxresponsechunks r!rSzLazyZipOverHTTP._downloads3 ZZ\\ , ,t{E22D S11E"kk%dEBB , , s00<<))+++ %   ,Xt7GHH,,EJ$$U++++,  , , , , , , , , , , , , , , , , , , ,sB:CC!$C!)r%N)rL)rrd)r%r')&rrr__doc__rstrrr6r?propertyrCr"boolrFrIrKr/rTrZr^rQr r9rbrer rhrr rkr=rr rrvrrrSrr r!r'r'(s@R!+9<  cXcX$!!!!X! % % %e % % % %$//3//C////!c!!!!))Xc])c))))$"S"T"""" y!12   ^      DKJJJ"J26sCx.J JJJJII"I*-I69I 5c?D$. /IIII, ,s , , , , , , , ,r r'N)'r__all__bisectrr contextlibrtempfilertypingr r r r r rzipfilerrpip._vendor.packaging.utilsrpip._vendor.requests.modelsrrpip._internal.metadatarrrpip._internal.network.sessionrpip._internal.network.utilsrrr Exceptionrrrr'rr r!rs (*? @,,,,,,,,%%%%%%''''''>>>>>>>>>>>>>>>>''''''''999999DDDDDDDDXXXXXXXXXX444444RRRRRRRRRR     )   FcFFjFEUFFFF"j,j,j,j,j,j,j,j,j,j,r