Re@sZdZddgZddlmZmZddlmZddlmZddl m Z m Z ddl m Z dd lmZdd lmZmZmZdd lmZdd lmZerdd lmZmZmZmZmZmZddlm Z ddl m!Z!ddl"m#Z#Gddde$Z%ddZ&Gddde'Z(dS)zLazy ZIP over HTTPHTTPRangeRequestUnsupporteddist_from_wheel_url) bisect_left bisect_right)contextmanager)NamedTemporaryFile) BadZipfileZipFile)CONTENT_CHUNK_SIZE)range)HEADERSraise_for_statusresponse_chunks)MYPY_CHECK_RUNNING)$pkg_resources_distribution_for_wheel)AnyDictIteratorListOptionalTuple) Distribution)Response) PipSessionc@seZdZdS)rN)__name__ __module__ __qualname__rr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/network/lazy_wheel.pyrs c Cs<t||&}t|}t|||jSWdQRXdS)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 rname)r urlsessionwheelzip_filerrrr"s  c@s!eZdZdZeddZeddZeddZdd Z d d Z ed d Z d+ddZ ddZ dddZddZdddZddZddZdd Zed!d"Zd#d$Zed%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|dt}t||jdks4t||||_|_|_t|j d|_ t |_ |j |j g|_g|_d|j jddkrtd|jdS)NheaderszContent-Lengthbytesz Accept-Rangesnonezrange request is not supported)headr r status_codeAssertionError_session_url _chunk_sizeintr%_lengthr_filetruncate_left_rightgetr _check_zip)selfr!r" chunk_sizer)rrr__init__=s     zLazyZipOverHTTP.__init__cCsdS)z!Opening mode, which is always rb.rbr)r7rrrmodeLszLazyZipOverHTTP.modecCs |jjS)zPath to the underlying file.)r1r )r7rrrr RszLazyZipOverHTTP.namecCsdS)z9Return whether random access is supported, which is True.Tr)r7rrrseekableXszLazyZipOverHTTP.seekablecCs|jjdS)zClose the file.N)r1close)r7rrrr=]szLazyZipOverHTTP.closecCs |jjS)zWhether the file is closed.)r1closed)r7rrrr>bszLazyZipOverHTTP.closedcCst||j}|j|j}}|dkr:|nt|||}td||}|j||d|jj|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. rr?)maxr.tellr0min _downloadr1read)r7sizeZ download_sizestartlengthstoprrrrDhs %zLazyZipOverHTTP.readcCsdS)z3Return whether the file is readable, which is True.Tr)r7rrrreadablewszLazyZipOverHTTP.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. )r1seek)r7offsetwhencerrrrJ|s zLazyZipOverHTTP.seekcCs |jjS)zReturn the current possition.)r1rA)r7rrrrAszLazyZipOverHTTP.tellNcCs|jj|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. )r1r2)r7rErrrr2s zLazyZipOverHTTP.truncatecCsdS)z Return False.Fr)r7rrrwritableszLazyZipOverHTTP.writablecCs|jj|S)N)r1 __enter__)r7rrrrNs zLazyZipOverHTTP.__enter__cGs|jj|S)N)r1__exit__)r7excrrrrOszLazyZipOverHTTP.__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)r7posrrr_stays  zLazyZipOverHTTP._staycCs|jd}xkttd||jD]N}|j|||j)yt|Wntk rnYnXPWdQRXq)WdS)z1Check and download until the file is a valid ZIP.r?rN)r0reversedr r.rCrRr r)r7endrFrrrr6s "  zLazyZipOverHTTP._check_zipcCsK|j}dj|||drDrIrJrAr2rMrNrOrrRr6r rXr`rCrrrrr4s(          rN))rd__all__bisectrr contextlibrtempfilerzipfilerr Zpip._vendor.requests.modelsr pip._vendor.six.movesr pip._internal.network.utilsr r rpip._internal.utils.typingrpip._internal.utils.wheelrtypingrrrrrrZpip._vendor.pkg_resourcesrrpip._internal.network.sessionr Exceptionrrobjectrrrrrs$ .