R`i_ d Z ddlZddlmZ ddlmZ ddlmZmZmZm Z ddl mZ ddlm Z ddlmZ dd lmZmZ dd lmZ dedefd Zeded fd Z G d de Zy)zHTTP cache implementation. N)contextmanager)datetime)BinaryIO GeneratorOptionalUnion)SeparateBodyBaseCache)SeparateBodyFileCache)Response)adjacent_tmp_filereplace) ensure_dirresponsereturnc t | dd S )N from_cacheF)getattr)r s /builddir/build/BUILDROOT/alt-python312-pip-23.3.1-3.el8.x86_64/opt/alt/python312/lib/python3.12/site-packages/pip/_internal/network/cache.py is_from_cacher s 8\511 )NNNc # 4 K d y# t $ r Y yw xY ww)zvIf we can't access the cache then we can just skip caching and process requests as if caching wasn't enabled. N)OSError r r suppressed_cache_errorsr s s c e Zd ZdZdeddf fdZdedefdZdedee fd Z d ededdfdZ dded edeee df ddfdZdeddfdZdedee fdZdededdfdZ xZS ) SafeFileCacheaG A file based cache which is safe to use even when the target directory may not be accessible or writable. There is a race condition when two processes try to write and/or read the same entry at the same time, since each entry consists of two separate files (https://github.com/psf/cachecontrol/issues/324). We therefore have additional logic that makes sure that both files to be present before returning an entry; this fixes the read side of the race condition. For the write side, we assume that the server will only ever return the same data for the same URL, which ought to be the case for files pip is downloading. PyPI does not have a mechanism to swap out a wheel for another wheel, for example. If this assumption is not true, the CacheControl issue will need to be fixed. directoryr Nc B |J d t | || _ y )Nz!Cache directory must not be None.)super__init__r )selfr __class__s r r zSafeFileCache.__init__2 s' $I&II$ "r namec t j | }t |d d |gz }t j j | j g| S )N )r encodelistospathjoinr )r! r# hashedpartss r _get_cache_pathzSafeFileCache._get_cache_path7 sG '--d3VBQZ F8+ww||DNN3U33r keyc d | j | }|dz }t j j | rt j j | sy t 5 t |d 5 }|j cd d d cd d d S # 1 sw Y nxY w d d d y # 1 sw Y y xY wN.bodyrb)r- r( r) existsr openread)r! r. metadata_path body_pathfs r getzSafeFileCache.get? s ,,S1 !G+ }-"''..2K $ &mT*avvx +* ' &*** ' & &s$ B&-B= B&B B&&B/r) datac t 5 t t j j | t | 5 }|j | d d d t j | d d d y # 1 sw Y (xY w# 1 sw Y y xY wN) r r r( r) dirnamer writer r# )r! r) r: r8 s r _writezSafeFileCache._writeI sa $ &rwwt,-"4(A ) AFFD! ' & )( ' &s" 4BA8B8B =BB valueexpiresc J | j | }| j || y r<