o 7]h@sdZddgZddlmZmZddlmZddlmZddl m Z m Z m Z m Z mZmZddlmZmZdd lmZdd lmZmZdd lmZmZmZdd lmZdd lmZm Z m!Z!Gddde"Z#de$de$dedefddZ%GdddZ&dS)zLazy ZIP over HTTPHTTPRangeRequestUnsupporteddist_from_wheel_url) bisect_left bisect_right)contextmanager)NamedTemporaryFile)AnyDictIteratorListOptionalTuple) BadZipfileZipFile)canonicalize_name)CONTENT_CHUNK_SIZEResponse)BaseDistribution MemoryWheelget_wheel_distribution) PipSession)HEADERSraise_for_statusresponse_chunksc@s eZdZdS)rN)__name__ __module__ __qualname__rrB/usr/lib/python3/dist-packages/pip/_internal/network/lazy_wheel.pyrsnameurlsessionreturncCsHt||}t|j|}t|t|WdS1swYdS)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 @seZdZdZefdedededdfddZe defd d Z e defd d Z de fd dZ d8ddZe de fddZd9dedefddZde fddZd:dededefddZdefddZd;deedefd d!Zde fd"d#Zd)zWhether the file is closed.)r2closedr<rrrrCSr?zLazyZipOverHTTP.closedsizecCs`t||j}||j}}|dkr|nt|||}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)maxr/tellr1min _downloadr2read)r8rE download_sizestartlengthstoprrrrKXs  zLazyZipOverHTTP.readcCr:)z3Return whether the file is readable, which is True.Trr<rrrreadablefrAzLazyZipOverHTTP.readableroffsetwhencecCs|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. )r2seek)r8rQrRrrrrSjszLazyZipOverHTTP.seekcCs |jS)zReturn the current position.)r2rHr<rrrrHts zLazyZipOverHTTP.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. )r2r3)r8rErrrr3xs zLazyZipOverHTTP.truncatecCr:)z Return False.Frr<rrrwritablerAzLazyZipOverHTTP.writablecCs|j|SN)r2 __enter__r<rrrrVs zLazyZipOverHTTP.__enter__exccGs |jj|SrU)r2__exit__)r8rWrrrrXs zLazyZipOverHTTP.__exit__c cs.|}z dVW||dS||w)zyReturn a context manager keeping the position. At the end of the block, seek back to original position. N)rHrS)r8posrrr_stays zLazyZipOverHTTP._stayc Cs|jd}ttd||jD]6}||||"zt|Wn ty*Yn w WddSWdn1s?wYqdS)z1Check and download until the file is a valid ZIP.rFrN)r1reversedranger/rJrZrr)r8endrMrrrr7s     zLazyZipOverHTTP._check_ziprMr] base_headerscCs8|}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-r6r.)r8rMr]r^r'rrr_stream_responsesz LazyZipOverHTTP._stream_responseleftrightc cs|j|||j||}}t|g|dd}}t|g|dd}t||D]\}} ||kr<||dfV| d}q-||krJ||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 NrFrD)r4r5rIrGzip) r8rMr]rdrelslicersliceijkrrr_merges   &zLazyZipOverHTTP._mergecCs|@t|j|}t|j|}|||||D]"\}}|||}|||t ||j D]}|j |q2qWddS1sGwYdS)z-Download bytes from start to end inclusively.N) rZrr5rr4rlrcrrSrr/r2write)r8rMr]rdreresponsechunkrrrrJs     "zLazyZipOverHTTP._download)r"N)rD)rrU)r"r#)&rrr__doc__rstrrr0r9propertyr=rboolr@rBrCr)rKrPrSrHr r3rTrVrrXrr rZr7rr rrcr rlrJrrrrr#(sj          r#N)'rp__all__bisectrr contextlibrtempfilertypingrr r r r r zipfilerrpip._vendor.packaging.utilsrpip._vendor.requests.modelsrrpip._internal.metadatarrrpip._internal.network.sessionrpip._internal.network.utilsrrr Exceptionrrqrr#rrrrs