3 ”ReÊã@südZddgZddlmZmZddlmZddlmZddl m Z m Z ddl m Z dd lmZdd lmZmZmZdd lmZdd lmZerÐdd lmZmZmZmZmZmZddlm Z ddl m!Z!ddl"m#Z#Gdd„de$ƒZ%dd„Z&Gdd„de'ƒZ(dS)zLazy ZIP over HTTPÚHTTPRangeRequestUnsupportedÚdist_from_wheel_urlé)Ú bisect_leftÚ bisect_right)Úcontextmanager)ÚNamedTemporaryFile)Ú BadZipfileÚZipFile)ÚCONTENT_CHUNK_SIZE)Úrange)ÚHEADERSÚraise_for_statusÚresponse_chunks)ÚMYPY_CHECK_RUNNING)Ú$pkg_resources_distribution_for_wheel)ÚAnyÚDictÚIteratorÚListÚOptionalÚTuple)Ú Distribution)ÚResponse)Ú PipSessionc@s eZdZdS)rN)Ú__name__Ú __module__Ú __qualname__©rrú�/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/network/lazy_wheel.pyrsc Cs,t||ƒ�}t|ƒ}t|||jƒSQRXdS)a%Return a pkg_resources.Distribution from the given wheel URL. This uses HTTP range requests to only fetch the potion of the wheel containing metadata, just enough for the object to be constructed. If such requests are not supported, HTTPRangeRequestUnsupported is raised. N)ÚLazyZipOverHTTPr rÚname)r ÚurlÚsessionÚwheelÚzip_filerrrr"s c@sÆeZdZdZefdd„Zedd„ƒZedd„ƒZdd „Z d d „Z ed d „ƒZ d,dd„Z dd„Z d-dd„Zdd„Zd.dd„Zdd„Zdd„Zdd „Zed!d"„ƒZd#d$„Zefd%d&„Zd'd(„Zd)d*„ZdS)/raFile-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. cCs�|j|td�}t|ƒ|jdks$t‚||||_|_|_t|j dƒ|_ t ƒ|_ |j |j ƒg|_g|_d|j jddƒkr„tdƒ‚|jƒdS)N)ÚheaderséÈzContent-LengthÚbytesz Accept-RangesÚnonezrange request is not supported)Úheadr r Ú status_codeÚAssertionErrorÚ_sessionÚ_urlÚ _chunk_sizeÚintr%Ú_lengthrÚ_fileÚtruncateÚ_leftÚ_rightÚgetrÚ _check_zip)Úselfr!r"Ú chunk_sizer)rrrÚ__init__=s zLazyZipOverHTTP.__init__cCsdS)z!Opening mode, which is always rb.Úrbr)r7rrrÚmodeLszLazyZipOverHTTP.modecCs|jjS)zPath to the underlying file.)r1r )r7rrrr RszLazyZipOverHTTP.namecCsdS)z9Return whether random access is supported, which is True.Tr)r7rrrÚseekableXszLazyZipOverHTTP.seekablecCs|jjƒdS)zClose the file.N)r1Úclose)r7rrrr=]szLazyZipOverHTTP.closecCs|jjS)zWhether the file is closed.)r1Úclosed)r7rrrr>bszLazyZipOverHTTP.closedécCs`t||jƒ}|jƒ|j}}|dkr(|n t|||ƒ}td||ƒ}|j||dƒ|jj|ƒS)zäRead 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. rr?)Úmaxr.Útellr0ÚminÚ _downloadr1Úread)r7ÚsizeZ download_sizeÚstartÚlengthÚstoprrrrDhs  zLazyZipOverHTTP.readcCsdS)z3Return whether the file is readable, which is True.Tr)r7rrrÚreadablewszLazyZipOverHTTP.readablercCs|jj||ƒ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. )r1Úseek)r7ÚoffsetÚwhencerrrrJ|s zLazyZipOverHTTP.seekcCs |jjƒS)zReturn the current possition.)r1rA)r7rrrrA‡szLazyZipOverHTTP.tellNcCs |jj|ƒS)zÌResize 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. )r1r2)r7rErrrr2Œs zLazyZipOverHTTP.truncatecCsdS)z Return False.Fr)r7rrrÚwritable—szLazyZipOverHTTP.writablecCs|jjƒ|S)N)r1Ú __enter__)r7rrrrNœs zLazyZipOverHTTP.__enter__cGs |jj|ŽS)N)r1Ú__exit__)r7ÚexcrrrrO¡szLazyZipOverHTTP.__exit__c cs$|jƒ}z dVWd|j|ƒXdS)zyReturn a context manager keeping the position. At the end of the block, seek back to original position. N)rArJ)r7ÚposrrrÚ_stay¥s zLazyZipOverHTTP._staycCsn|jd}x^ttd||jƒƒD]H}|j||ƒ|jƒ�*y t|ƒWntk rXYnXPWdQRXqWdS)z1Check and download until the file is a valid ZIP.r?rN)r0Úreversedr r.rCrRr r)r7ÚendrFrrrr6²s    zLazyZipOverHTTP._check_zipcCs4|jƒ}dj||ƒ|d<d|d<|jj|j|dd�S)z:Return HTTP response to a range request from start to end.z bytes={}-{}ZRangezno-cachez Cache-ControlT)r%Ústream)ÚcopyÚformatr,r5r-)r7rFrTZ base_headersr%rrrÚ_stream_responseÂsz LazyZipOverHTTP._stream_responsec cs¼|j||…|j||…}}t|g|dd…ƒ}}t|g|dd…ƒ}x4t||ƒD]&\}} ||krx||dfV| d}qZW||kr–||fV|g|g|j||…<|j||…<dS)a/Return an iterator 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 Nr?éÿÿÿÿ)r3r4rBr@Úzip) r7rFrTÚleftÚrightZlsliceZrsliceÚiÚjÚkrrrÚ_mergeËs   zLazyZipOverHTTP._mergec CsŽ|jƒ�|t|j|ƒ}t|j|ƒ}x\|j||||ƒD]H\}}|j||ƒ}|jƒ|j|ƒx t ||j ƒD]}|j j |ƒqhWq4WWdQRXdS)z-Download bytes from start to end inclusively.N) rRrr4rr3r`rXr rJrr.r1Úwrite)r7rFrTr[r\ÚresponseÚchunkrrrrCàs     zLazyZipOverHTTP._downloadrY)rY)r)N)rrrÚ__doc__r r9Úpropertyr;r r<r=r>rDrIrJrAr2rMrNrOrrRr6r rXr`rCrrrrr4s(         rN))rdÚ__all__ÚbisectrrÚ contextlibrÚtempfilerÚzipfilerr Zpip._vendor.requests.modelsr Úpip._vendor.six.movesr Úpip._internal.network.utilsr r rÚpip._internal.utils.typingrÚpip._internal.utils.wheelrÚtypingrrrrrrZpip._vendor.pkg_resourcesrrÚpip._internal.network.sessionrÚ ExceptionrrÚobjectrrrrrÚs$