a lj @ sT d Z ddlZddlZddlZddlZddlmZmZmZ ddl m Z mZ ddlm Z ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZmZmZ ddlmZmZmZ e e!Z"eee# d ddZ$eee%ee& dddZ'e%e%dddZ(e%e%e%dddZ)eee%dddZ*eeedddZ+G dd d Z,G d!d" d"Z-dS )#z)Download files with progress indicators. N)IterableOptionalTuple)CONTENT_CHUNK_SIZEResponse)DownloadProgressProvider)NetworkConnectionError)PyPI)Link) is_from_cache) PipSession)HEADERSraise_for_statusresponse_chunks)format_sizeredact_auth_from_urlsplitext)respreturnc C s0 zt | jd W S tttfy* Y d S 0 d S )Nzcontent-length)intheaders ValueErrorKeyError TypeError)r r B/usr/lib/python3.9/site-packages/pip/_internal/network/download.py_get_http_response_size s r )r linkprogress_barr c C s t | }|jtjkr|j}n|j}t|}|r>d|t|}t | rTt d| nt d| t t jkrtd}n*t | rd}n|sd}n|dkrd}nd}t| t}|s|S t||d|S )Nz{} ({})zUsing cached %szDownloading %sFTi@ )max)r netlocr Zfile_storage_domainZshow_urlZurl_without_fragmentr formatr r loggerinfoZgetEffectiveLevelloggingINFOr r r )r r r Ztotal_lengthurlZ logged_urlZ show_progresschunksr r r _prepare_download s. r( )filenamer c C s t j| S )zJ Sanitize the "filename" value from a Content-Disposition header. )ospathbasename)r) r r r sanitize_content_filenameG s r- )content_dispositiondefault_filenamer c C s, t | \}}|d}|r$t|}|p*|S )z Parse the "filename" value from a Content-Disposition header, and return the default filename if the result is empty. r) )cgiZparse_headergetr- )r. r/ Z_typeparamsr) r r r parse_content_dispositionN s r3 )r r r c C s |j }| jd}|r t||}t|d }|sPt| jdd}|rP||7 }|s~|j| jkr~tj | jd }|r~||7 }|S )zoGet an ideal filename from the given HTTP response, falling back to the link filename if not provided. zcontent-disposition zcontent-type ) r) r r1 r3 r mimetypesZguess_extensionr&