a  ze@sdZddgZddlmZmZddlmZddlmZddl m Z m Z m Z m Z mZmZddlmZmZdd lmZdd lmZmZdd lmZdd lmZmZmZdd lmZGddde Z!e"e"eedddZ#GdddZ$dS)zLazy ZIP over HTTPHTTPRangeRequestUnsupporteddist_from_wheel_url) bisect_left bisect_right)contextmanager)NamedTemporaryFile)AnyDictIteratorListOptionalTuple) BadZipfileZipFile) Distribution)CONTENT_CHUNK_SIZEResponse) PipSession)HEADERSraise_for_statusresponse_chunks)$pkg_resources_distribution_for_wheelc@s eZdZdS)rN)__name__ __module__ __qualname__rrb/opt/bitninja-python-dojo/embedded/lib/python3.9/site-packages/pip/_internal/network/lazy_wheel.pyrs)nameurlsessionreturncCsDt||&}t|}t|||jWdS1s60YdS)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)LazyZipOverHTTPrrr)rrrwheelzip_filerrrrs c@szeZdZdZefeeeddddZe edddZ e edd d Z e dd d Z ddd dZe e dddZd3eedddZe dddZd4eeedddZedddZd5eeedddZe ddd Zddd!d"Zeee d#d$d%Zeeddd&d'Zddd(d)Zefeee eefe!d*d+d,Z"eeeeee#eefd-d.d/Z$eedd0d1d2Z%dS)6r!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)rr chunk_sizer cCs|j|td}t||jdks$J||||_|_|_t|jd|_ t |_ | |j g|_ g|_d|jddvrtd|dS)N)headerszContent-Lengthbytesz Accept-Rangesnonezrange request is not supported)headrr status_code_session_url _chunk_sizeintr%_lengthr_filetruncate_left_rightgetr _check_zip)selfrrr$r)rrr__init__1s zLazyZipOverHTTP.__init__)r cCsdS)z!Opening mode, which is always rb.rbrr6rrrmodeAszLazyZipOverHTTP.modecCs|jjS)zPath to the underlying file.)r0rr9rrrrFszLazyZipOverHTTP.namecCsdS)z9Return whether random access is supported, which is True.Trr9rrrseekableKszLazyZipOverHTTP.seekablecCs|jdS)zClose the file.N)r0closer9rrrr<OszLazyZipOverHTTP.closecCs|jjS)zWhether the file is closed.)r0closedr9rrrr=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)maxr-tellr/min _downloadr0read)r6r? download_sizestartlengthstoprrrrEXs  zLazyZipOverHTTP.readcCsdS)z3Return whether the file is readable, which is True.Trr9rrrreadablefszLazyZipOverHTTP.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. )r0seek)r6rKrLrrrrMjszLazyZipOverHTTP.seekcCs |jS)zReturn the current position.)r0rBr9rrrrBtszLazyZipOverHTTP.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. )r0r1)r6r?rrrr1xszLazyZipOverHTTP.truncatecCsdS)z Return False.Frr9rrrwritableszLazyZipOverHTTP.writablecCs|j|SN)r0 __enter__r9rrrrPs zLazyZipOverHTTP.__enter__)excr cGs |jj|SrO)r0__exit__)r6rQrrrrRszLazyZipOverHTTP.__exit__c cs.|}zdVW||n ||0dS)zyReturn a context manager keeping the position. At the end of the block, seek back to original position. N)rBrM)r6posrrr_stayszLazyZipOverHTTP._stayc Cs|jd}ttd||jD]h}||||@z t|WntyTYn0WdqWdq1sz0YqdS)z1Check and download until the file is a valid ZIP.r@rN)r/reversedranger-rDrTrr)r6endrGrrrr5s     zLazyZipOverHTTP._check_zip)rGrW 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+r4r,)r6rGrWrXr%rrr_stream_responsesz LazyZipOverHTTP._stream_response)rGrWleftrightr 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 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@r>)r2r3rCrAzip) r6rGrWr^r_lslicersliceijkrrr_merges   zLazyZipOverHTTP._merge)rGrWr cCs|~t|j|}t|j|}|||||D]D\}}|||}|||t ||j D]}|j |qdq2Wdn1s0YdS)z-Download bytes from start to end inclusively.N) rTrr3rr2rfr]rrMrr-r0write)r6rGrWr^r_responsechunkrrrrDs     zLazyZipOverHTTP._download)r>)r)N)&rrr__doc__rstrrr.r7propertyr:rboolr;r<r=r'rErJrMrBr r1rNrPrrRrr rTr5rr rr]r rfrDrrrrr!(sD       r!N)%rj__all__bisectrr contextlibrtempfilertypingrr r r r r zipfilerrpip._vendor.pkg_resourcesrZpip._vendor.requests.modelsrrpip._internal.network.sessionrpip._internal.network.utilsrrrpip._internal.utils.wheelr Exceptionrrkrr!rrrrs