U ʗRe@sdZddgZddlmZmZddlmZddlmZddl m Z m Z m Z m Z mZmZddlmZmZdd lmZdd lmZmZdd lmZmZmZdd lmZdd lmZm Z m!Z!Gddde"Z#e$e$eedddZ%GdddZ&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_chunksc@s eZdZdS)rN)__name__ __module__ __qualname__rr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_internal/network/lazy_wheel.pyrs)nameurlsessionreturnc Cs<t||(}t|j|}t|t|W5QRSQRXdS)aReturn a distribution object 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)LazyZipOverHTTPrrrr)rr r!zfwheelrrrrs  c@s|eZdZdZefeeeddddZe edddZ e edd d Z e dd d Z ddd dZe e dddZd4eedddZe dddZd5eeedddZedddZd6eeedddZe ddd Zddd!d"Zedd#d$d%Zeed&dd'd(Zddd)d*Zefeee eefe!d+d,d-Z"eeeeee#eefddfd.d/d0Z$eedd1d2d3Z%dS)7r#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. N)r r! chunk_sizer"cCs|j|td}t||jdks$t||||_|_|_t|j d|_ t |_ | |j g|_g|_d|j ddkrtd|dS)N)headerszContent-Lengthbytesz Accept-Rangesnonezrange request is not supported)headrr status_codeAssertionError_session_url _chunk_sizeintr'_lengthr_filetruncate_left_rightgetr _check_zip)selfr r!r&r+rrr__init__1s zLazyZipOverHTTP.__init__)r"cCsdS)z!Opening mode, which is always rb.rbrr9rrrmodeAszLazyZipOverHTTP.modecCs|jjS)zPath to the underlying file.)r3rr<rrrrFszLazyZipOverHTTP.namecCsdS)z9Return whether random access is supported, which is True.Trr<rrrseekableKszLazyZipOverHTTP.seekablecCs|jdS)zClose the file.N)r3closer<rrrr?OszLazyZipOverHTTP.closecCs|jjS)zWhether the file is closed.)r3closedr<rrrr@SszLazyZipOverHTTP.closed)sizer"cCs`t||j}||j}}|dkr(|n t|||}td||}|||d|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)maxr0tellr2min _downloadr3read)r9rB download_sizestartlengthstoprrrrHXs  zLazyZipOverHTTP.readcCsdS)z3Return whether the file is readable, which is True.Trr<rrrreadablefszLazyZipOverHTTP.readabler)offsetwhencer"cCs|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. )r3seek)r9rNrOrrrrPjszLazyZipOverHTTP.seekcCs |jS)zReturn the current position.)r3rEr<rrrrEtszLazyZipOverHTTP.tellcCs |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. )r3r4)r9rBrrrr4xszLazyZipOverHTTP.truncatecCsdS)z Return False.Frr<rrrwritableszLazyZipOverHTTP.writablecCs|j|SN)r3 __enter__r<rrrrSs zLazyZipOverHTTP.__enter__)excr"cGs|jj|dSrR)r3__exit__)r9rTrrrrUszLazyZipOverHTTP.__exit__)NNNc cs$|}z dVW5||XdS)zyReturn a context manager keeping the position. At the end of the block, seek back to original position. N)rErP)r9posrrr_stays zLazyZipOverHTTP._stayc Csv|jd}ttd||jD]T}||||6z t|Wntk rVYnXW5QRqrW5QRXqdS)z1Check and download until the file is a valid ZIP.rCrN)r2reversedranger0rGrWrr)r9endrJrrrr8s    zLazyZipOverHTTP._check_zip)rJrZ base_headersr"cCs8|}d|d||d<d|d<|jj|j|ddS)z:Return HTTP response to a range request from start to end.zbytes=-Rangezno-cachez Cache-ControlT)r'stream)copyr.r7r/)r9rJrZr[r'rrr_stream_responsesz LazyZipOverHTTP._stream_response)rJrZleftrightr"c cs|j|||j||}}t|g|dd}}t|g|dd}t||D]&\}} ||krv||dfV| d}qX||kr||fV|g|g|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 NrCrA)r5r6rFrDzip) r9rJrZrarblslicersliceijkrrr_merges   zLazyZipOverHTTP._merge)rJrZr"c Cs|tt|j|}t|j|}|||||D]D\}}|||}|||t ||j D]}|j |qdq2W5QRXdS)z-Download bytes from start to end inclusively.N) rWrr6rr5rir`rrPrr0r3write)r9rJrZrarbresponsechunkrrrrGs     zLazyZipOverHTTP._download)rA)r)N)&rrr__doc__rstrrr1r:propertyr=rboolr>r?r@r)rHrMrPrEr r4rQrSrrUrr rWr8rr rr`r rirGrrrrr#(sR        r#N)'rm__all__bisectrr contextlibrtempfilertypingrr r r r r zipfilerrpip._vendor.packaging.utilsrZpip._vendor.requests.modelsrrpip._internal.metadatarrrpip._internal.network.sessionrpip._internal.network.utilsrrr Exceptionrrnrr#rrrrs