o
    5e                     @   s   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mZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ eeZe jdeded	 fd
dZe jded fddZG dd deZG dd dZdS )    N)TracebackType)Dict	GeneratorOptionalSetTypeUnion)Link)InstallRequirement)TempDirectorychangesreturnNNNc               
   k   s    t j}t }i }|  D ]\}}z|| ||< W n ty&   |||< Y nw |||< qz"d V  W | D ]\}}||u rA||= q5t|tsHJ |||< q5d S | D ]\}}||u r_||= qSt|tsfJ |||< qSw N)osenvironobjectitemsKeyError
isinstancestr)r   targetnon_existent_markersaved_valuesname	new_valueoriginal_value r   _/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/operations/build/build_tracker.pyupdate_env_context_manager   s0   


r   )BuildTrackerNNc               	   c   s    t jd} t C}| d u r'|tddj} |t| d t	
d|  t| }|V  W d    n1 s9w   Y  W d    d S W d    d S 1 sQw   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debugr    )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.   6   s    r.   c                   @   s   e Zd ZdZdeddfddZdddZd	eee	  d
ee	 dee
 ddfddZdedefddZdededdfddZdededdfddZdddZejdededed f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*   r   Nc                 C   s   || _ i | _td| j  d S )NzCreated build tracker: %s)_root_entriesr(   r)   )selfr*   r   r   r   __init__C   s   zBuildTracker.__init__c                 C   s   t d| j | S )NzEntered build tracker: %s)r(   r)   r3   )r5   r   r   r   	__enter__H   s   zBuildTracker.__enter__exc_typeexc_valexc_tbc                 C   s   |    d S r   )cleanup)r5   r8   r9   r:   r   r   r   __exit__L   s   zBuildTracker.__exit__keyc                 C   s"   t |  }tj| j|S r   )hashlibsha224encode	hexdigestr   r'   joinr3   )r5   r=   hashedr   r   r   _entry_pathT   s   zBuildTracker._entry_pathreqc                 C   s   |  |}zt|}| }W d   n1 sw   Y  W n	 ty(   Y nw d|j|}t||| jvs;J t|ddd}|t	| W d   n1 sTw   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)rD   openreadFileNotFoundErrorformatlinkLookupErrorr4   writer   r(   r)   r3   )r5   rE   r=   
entry_pathfpcontentsmessager   r   r   addX   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   unlinkrD   r4   r(   r)   r3   )r5   rE   r=   r   r   r   removes   s   zBuildTracker.removec                 C   s6   t | j D ]
\}}| || qtd| j d S )NzRemoved build tracker: %r)listr4   r   rU   r(   r)   r3   )r5   r=   rE   r   r   r   r;   |   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.   rS   rU   )r5   rE   r=   
tracker_idr   r   r   track   s
   zBuildTracker.track)r   r    )r   N)r/   r0   r1   r2   r   r6   r7   r   r   BaseExceptionr   r<   r.   rD   r
   rS   rU   r;   r$   contextmanagerr   rX   r   r   r   r   r    :   s&    



	 r    )r$   r>   loggingr   typesr   typingr   r   r   r   r   r   pip._internal.models.linkr	   pip._internal.req.req_installr
   pip._internal.utils.temp_dirr   	getLoggerr/   r(   rZ   r   r   r-   r.   r    r   r   r   r   <module>   s      
