U .e @ s d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m Z ddlmZ ddl mZ ddlmZ dd lmZmZ erdd lmZmZmZmZ ddlmZ ddlmZ eeZG d d de Z!G dd de!Z"G dd de"Z#G dd de!Z$dS )zCache Management N)canonicalize_name)Link) expanduser) TempDirectory)MYPY_CHECK_RUNNING)path_to_url)InvalidWheelFilenameWheel)OptionalSetListAny) FormatControl) Pep425Tagc sP e Zd ZdZ fddZdd Zdd Zdd Zd d Zdd Z dd Z ZS )Cachea An abstract class - provides cache directories for data from links :param cache_dir: The root of the cache. :param format_control: An object of FormatControl class to limit binaries being read from the cache. :param allowed_formats: which formats of files the cache should store. ('binary' and 'source' are the only allowed values) c s8 t t| |rt|nd | _|| _|| _ddh}d S )Nsourcebinary)superr __init__r cache_dirformat_controlallowed_formats)selfr r r Z_valid_formats __class__ 7/usr/lib/python3.8/site-packages/pip/_internal/cache.pyr ( s zCache.__init__c C s |j g}|jdk r4|jdk r4|d|j|jg d|}t| }|dd |dd |dd |dd g}|S )zEGet parts of part that must be os.path.joined with cache_dir N=# ) Zurl_without_fragmentZ hash_namehashappendjoinhashlibZsha224encodeZ hexdigest)r linkZ key_partsZkey_urlZhashedpartsr r r _get_cache_path_parts2 s ,zCache._get_cache_path_partsc C s | j p| p| }|rg S t|}| j|}| j|s@g S | |}zt|W S t k r } z$|j t jt jhkrg W Y S W 5 d }~X Y nX d S N) r r r Zget_allowed_formatsr intersectionget_path_for_linkoslistdirOSErrorerrnoZENOENTZENOTDIR)r r' package_nameZ can_not_cacheZcanonical_nameZformatsrooterrr r r _get_candidatesL s( zCache._get_candidatesc C s t dS )z>Return a directory to store cached items in for link. NNotImplementedErrorr r' r r r r, e s zCache.get_path_for_linkc C s t dS )zaReturns a link to a cached item if it exists, otherwise returns the passed link. Nr5 )r r' r1 supported_tagsr r r getk s z Cache.getc C s$ | |}tj||}tt|S r* )r, r- pathr$ r r )r r' candidater2 r: r r r _link_for_candidatew s zCache._link_for_candidatec C s d S r* r r r r r cleanup~ s z Cache.cleanup)__name__ __module____qualname____doc__r r) r4 r, r9 r<