U
    X7h                     @   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 d dlmZ d dlmZ eeZe jeed ddd	Ze jed
 dddZG dd deZG dd dZdS )    N)TracebackType)Dict	GeneratorOptionalTypeUnion)InstallRequirement)TempDirectoryNNN)changesreturnc               
   k   s   t j}t }i }|  D ]>\}}z|| ||< W n tk
rL   |||< Y nX |||< qz
d V  W 5 | D ].\}}||kr||= qlt|tst|||< qlX d S N)osenvironobjectitemsKeyError
isinstancestrAssertionError)r   targetZnon_existent_markerZsaved_valuesnameZ	new_valueoriginal_value r   f/var/www/formularioweb/env/lib/python3.8/site-packages/pip/_internal/operations/build/build_tracker.pyupdate_env_context_manager   s     

r   )BuildTrackerNNr   c               
   c   st   t jd} t V}| d krL|tddj} |t| d t	
d|  t| }|V  W 5 Q R X W 5 Q R X 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ctxZ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*   5   s   r*   c                   @   s   e Zd ZdZeddddZd dddZeee	  ee	 ee
 dd	d
dZeedddZeeddddZeeddddZddddZejeee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.N)r'   r   c                 C   s   || _ i | _td| j  d S )NzCreated build tracker: %s)_root_entriesr%   r&   )selfr'   r   r   r   __init__B   s    zBuildTracker.__init__r   c                 C   s   t d| j | S )NzEntered build tracker: %s)r%   r&   r/   )r1   r   r   r   	__enter__G   s    zBuildTracker.__enter__)exc_typeexc_valexc_tbr   c                 C   s   |    d S r   )cleanup)r1   r4   r5   r6   r   r   r   __exit__K   s    zBuildTracker.__exit__)keyr   c                 C   s"   t |  }tj| j|S r   )hashlibsha224encode	hexdigestr   r$   joinr/   )r1   r9   hashedr   r   r   _entry_pathS   s    zBuildTracker._entry_path)reqr9   r   c              	   C   s   |  |}z t|}| }W 5 Q R X W n tk
r>   Y nX |j d| }t||| jksftt|ddd}|t	| W 5 Q R X || j|< t
d|| j dS )z,Add an InstallRequirement to build tracking.z is already being built: wzutf-8)encodingzAdded %s to build tracker %rN)r@   openreadFileNotFoundErrorlinkLookupErrorr0   r   writer   r%   r&   r/   )r1   rA   r9   Z
entry_pathfpcontentsmessager   r   r   addW   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   unlinkr@   r0   r%   r&   r/   )r1   rA   r9   r   r   r   remover   s    zBuildTracker.removec                 C   s6   t | j D ]\}}| || qtd| j d S )NzRemoved build tracker: %r)listr0   r   rO   r%   r&   r/   )r1   r9   rA   r   r   r   r7   {   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*   rM   rO   )r1   rA   r9   Z
tracker_idr   r   r   track   s    zBuildTracker.track)r+   r,   r-   r.   r   r2   r3   r   r   BaseExceptionr   r8   r*   r@   r   rM   rO   r7   r!   contextmanagerr   rQ   r   r   r   r   r   9   s   
	r   )r!   r:   loggingr   typesr   typingr   r   r   r   r   pip._internal.req.req_installr   pip._internal.utils.temp_dirr	   	getLoggerr+   r%   rS   r   r   r)   r*   r   r   r   r   r   <module>   s   
