U ÀÒ.e³ ã @ sþ d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m Z ddlmZ ddl mZ ddlmZ dd lmZmZ er°dd lmZmZmZmZ ddlmZ ddlmZ e e¡ZG 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)ÚInvalidWheelFilenameÚWheel)ÚOptionalÚSetÚListÚAny)Ú FormatControl)Ú Pep425Tagc sP e Zd ZdZ‡ fdd„Zdd„ 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 )NÚsourceÚbinary)Úsuperr Ú__init__r Ú cache_dirÚformat_controlÚallowed_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_nameÚhashÚappendÚjoinÚhashlibZsha224ÚencodeZ hexdigest)r ÚlinkZ key_partsZkey_urlZhashedÚpartsr 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 jhkr†g W Y ¢S ‚ W 5 d }~X Y nX d S ©N) r r r Zget_allowed_formatsr ÚintersectionÚget_path_for_linkÚosÚlistdirÚOSErrorÚerrnoZENOENTZENOTDIR)r r' Úpackage_nameZ can_not_cacheZcanonical_nameZformatsÚrootÚerrr r r Ú_get_candidatesL s( ÿýÿ zCache._get_candidatesc C s t ƒ ‚dS )z>Return a directory to store cached items in for link. N©ÚNotImplementedError©r 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<