a
    bai                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ eeZejddd	d
dZejddddZG dd deZG dd dZdS )    )annotationsN)	Generator)TracebackType)InstallRequirement)TempDirectorystrGenerator[None, None, None])changesreturnc               
   k  s   t j}t }i }|  D ]<\}}z|| ||< W n tyJ   |||< Y n0 |||< qzBd V  W | D ].\}}||u r||= qht|tsJ |||< qhn:| D ].\}}||u r||= qt|tsJ |||< q0 d S N)osenvironobjectitemsKeyError
isinstancer   )r	   targetnon_existent_markersaved_valuesname	new_valueoriginal_value r   f/var/www/html/SiteWeb/venv/lib/python3.9/site-packages/pip/_internal/operations/build/build_tracker.pyupdate_env_context_manager   s*    
r   z#Generator[BuildTracker, None, None]r
   c               	   c  s   t jd} t t}| d u rL|tddj} |t| d t	
d|  t| }|V  W d    n1 sp0    Y  W d    n1 s0    Y  d S )NPIP_BUILD_TRACKERzbuild-tracker)kind)r   z Initialized build tracking at %s)r   r   get
contextlib	ExitStackenter_contextr   pathr   loggerdebugBuildTracker)rootctxtrackerr   r   r   get_build_tracker*   s    

r)   c                   @  s   e Zd ZdZdS )	TrackerIdz:Uniquely identifying string provided to the build tracker.N)__name__
__module____qualname____doc__r   r   r   r   r*   7   s   r*   c                   @  s   e Zd ZdZdddddZd ddd	Zd
ddddddZdddddZddddddZddddddZ	ddddZ
ejddddddZdS ) r%   a7  Ensure that an sdist cannot request itself as a setup requirement.

    When an sdist is prepared, it identifies its setup requirements in the
    context of ``BuildTracker.track()``. If a requirement shows up recursively, this
    raises an exception.

    This stops fork bombs embedded in malicious packages.r   None)r&   r
   c                 C  s   || _ i | _td| j  d S )NzCreated build tracker: %s)_root_entriesr#   r$   )selfr&   r   r   r   __init__D   s    zBuildTracker.__init__r   c                 C  s   t d| j | S )NzEntered build tracker: %s)r#   r$   r0   )r2   r   r   r   	__enter__I   s    zBuildTracker.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | None)exc_typeexc_valexc_tbr
   c                 C  s   |    d S r   )cleanup)r2   r5   r6   r7   r   r   r   __exit__M   s    zBuildTracker.__exit__r*   )keyr
   c                 C  s"   t |  }tj| j|S r   )hashlibsha224encode	hexdigestr   r"   joinr0   )r2   r:   hashedr   r   r   _entry_pathU   s    zBuildTracker._entry_pathr   )reqr:   r
   c                 C  s   |  |}z4t|}| }W d   n1 s20    Y  W n tyP   Y n0 |j d| }t||| jvsxJ t|ddd}|t| W d   n1 s0    Y  || j|< t	
d|| j dS )z,Add an InstallRequirement to build tracking.Nz is already being built: wzutf-8)encodingzAdded %s to build tracker %r)rA   openreadFileNotFoundErrorlinkLookupErrorr1   writer   r#   r$   r0   )r2   rB   r:   
entry_pathfpcontentsmessager   r   r   addY   s    

*,
zBuildTracker.addc                 C  s,   t | | | j|= td|| j dS )z1Remove an InstallRequirement from build tracking.z Removed %s from build tracker %rN)r   unlinkrA   r1   r#   r$   r0   )r2   rB   r:   r   r   r   removet   s    zBuildTracker.removec                 C  s6   t | j D ]\}}| || qtd| j d S )NzRemoved build tracker: %r)listr1   r   rQ   r#   r$   r0   )r2   r:   rB   r   r   r   r8   }   s    zBuildTracker.cleanupr   c                 c  s*   t |}| || dV  | || dS )zEnsure that `key` cannot install itself as a setup requirement.

        :raises LookupError: If `key` was already provided in a parent invocation of
                             the context introduced by this method.N)r*   rO   rQ   )r2   rB   r:   Z
tracker_idr   r   r   track   s    zBuildTracker.trackN)r+   r,   r-   r.   r3   r4   r9   rA   rO   rQ   r8   r   contextmanagerrS   r   r   r   r   r%   ;   s   	r%   )
__future__r   r   r;   loggingr   collections.abcr   typesr   Zpip._internal.req.req_installr   pip._internal.utils.temp_dirr   	getLoggerr+   r#   rT   r   r)   r   r*   r%   r   r   r   r   <module>   s   
