
    k"gP                        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  e j                  dddg      Z
 G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z e j                  dd      Z G d de      Zd Z e j                  dd      Zd Z G d de      Zy)     N   )AbstractResolver)DirectedGraphIteratorMappingbuild_iter_viewRequirementInformationrequirementparentc                       e Zd ZdZy)ResolverExceptionzA base class for all exceptions raised by this module.

    Exceptions derived by this class should all be handled in this module. Any
    bubbling pass the resolver should be treated as a bug.
    N)__name__
__module____qualname____doc__     Y/var/www/html/djangosite/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.pyr   r      s    r   r   c                   $     e Zd Z fdZd Z xZS )RequirementsConflictedc                 :    t         t        |   |       || _        y N)superr   __init__	criterion)selfr   	__class__s     r   r   zRequirementsConflicted.__init__   s    $d4Y?"r   c                     dj                  dj                  d | j                  j                         D                    S )NzRequirements conflict: {}, c              3   2   K   | ]  }t        |        y wr   repr.0rs     r   	<genexpr>z1RequirementsConflicted.__str__.<locals>.<genexpr>        I!d1gI   )formatjoinr   iter_requirementr   s    r   __str__zRequirementsConflicted.__str__   s4    *11IIIt~~'F'F'HII
 	
r   r   r   r   r   r,   __classcell__r   s   @r   r   r      s    #
r   r   c                   $     e Zd Z fdZd Z xZS )InconsistentCandidatec                 J    t         t        |   ||       || _        || _        y r   )r   r1   r   	candidater   )r   r3   r   r   s      r   r   zInconsistentCandidate.__init__!   s#    #T3IyI""r   c                     dj                  | j                  dj                  d | j                  j	                         D                    S )Nz+Provided candidate {!r} does not satisfy {}r   c              3   2   K   | ]  }t        |        y wr   r    r"   s     r   r%   z0InconsistentCandidate.__str__.<locals>.<genexpr>)   r&   r'   )r(   r3   r)   r   r*   r+   s    r   r,   zInconsistentCandidate.__str__&   s;    <CCNNIIIt~~'F'F'HII
 	
r   r-   r/   s   @r   r1   r1       s    #

r   r1   c                   (    e Zd ZdZd Zd Zd Zd Zy)	CriterionaQ  Representation of possible resolution results of a package.

    This holds three attributes:

    * `information` is a collection of `RequirementInformation` pairs.
      Each pair is a requirement contributing to this criterion, and the
      candidate that provides the requirement.
    * `incompatibilities` is a collection of all known not-to-work candidates
      to exclude from consideration.
    * `candidates` is a collection containing all possible candidates deducted
      from the union of contributing requirements and known incompatibilities.
      It should never be empty, except when the criterion is an attribute of a
      raised `RequirementsConflicted` (in which case it is always empty).

    .. note::
        This class is intended to be externally immutable. **Do not** mutate
        any of its attribute containers.
    c                 .    || _         || _        || _        y r   
candidatesinformationincompatibilities)r   r:   r;   r<   s       r   r   zCriterion.__init__A   s    $&!2r   c                 h    dj                  d | j                  D              }dj                  |      S )Nr   c              3   F   K   | ]  \  }}d j                  ||        yw)z({!r}, via={!r})N)r(   )r#   reqr
   s      r   r%   z%Criterion.__repr__.<locals>.<genexpr>G   s)      !
V %%c62!
s   !zCriterion({}))r)   r;   r(   )r   requirementss     r   __repr__zCriterion.__repr__F   s6    yy !
#//!
 
 %%l33r   c                 (    d | j                   D        S )Nc              3   4   K   | ]  }|j                     y wr   r	   r#   is     r   r%   z-Criterion.iter_requirement.<locals>.<genexpr>N   s     8!8   r;   r+   s    r   r*   zCriterion.iter_requirementM   s    8t'7'788r   c                 (    d | j                   D        S )Nc              3   4   K   | ]  }|j                     y wr   r
   rE   s     r   r%   z(Criterion.iter_parent.<locals>.<genexpr>Q   s     3Q3rG   rH   r+   s    r   iter_parentzCriterion.iter_parentP   s    3$"2"233r   N)r   r   r   r   r   rA   r*   rL   r   r   r   r7   r7   -   s    &3
494r   r7   c                       e Zd Zy)ResolutionErrorN)r   r   r   r   r   r   rN   rN   T   s    r   rN   c                        e Zd Z fdZ xZS )ResolutionImpossiblec                 :    t         t        |   |       || _        y r   )r   rP   r   causes)r   rR   r   s     r   r   zResolutionImpossible.__init__Y   s    "D26:r   r   r   r   r   r.   r/   s   @r   rP   rP   X   s     r   rP   c                        e Zd Z fdZ xZS )ResolutionTooDeepc                 :    t         t        |   |       || _        y r   )r   rU   r   round_count)r   rW   r   s     r   r   zResolutionTooDeep.__init__`   s    /<&r   rS   r/   s   @r   rU   rU   _   s    ' 'r   rU   Statez!mapping criteria backtrack_causesc                   \    e Zd ZdZd Zed        Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zy)
ResolutionzStateful resolution object.

    This is designed as a one-off object that holds information to kick start
    the resolution process, and holds the results afterwards.
    c                 .    || _         || _        g | _        y r   )_p_r_states)r   providerreporters      r   r   zResolution.__init__p   s    r   c                 R    	 | j                   d   S # t        $ r t        d      w xY w)Nstate)r^   
IndexErrorAttributeErrorr+   s    r   rc   zResolution.stateu   s0    	*<<## 	* ))	*s    &c                     | j                   d   }t        |j                  j                         |j                  j                         |j
                  dd       }| j                   j                  |       y)zPush a new state into history.

        This new state will be used to hold resolution results of the next
        coming round.
        rb   Nmappingcriteriabacktrack_causes)r^   rX   rh   copyri   rj   append)r   baserc   s      r   _push_new_statezResolution._push_new_state|   s^     ||BLL%%']]'')!2215

 	E"r   c           
      p   | j                   j                  ||       | j                  j                  |      }|j	                  |      }|rt        |j                        }ng }| j                  j                  |t        |t        j                  d      ||gi      t        |t        j                  d      ||i            }|r1t        |j                        }|j                  t        ||             nt        ||      g}t        t!        |      ||      }|j"                  st%        |      |||<   y )N)r	   r
   )requirement_or_candidater*   r<   
identifierr@   r<   r9   )r]   adding_requirementr\   identifygetlistr<   find_matchesr   operatormethodcaller
attrgetterr;   rl   r   r7   r   r:   r   )	r   ri   r	   r
   rr   r   r<   matchesr;   s	            r   _add_to_criteriazResolution._add_to_criteria   s/   ""{6"JWW%%{%K
LL,	 $Y%@%@ A "''&&!(%%&89k]+
 .##$78./ ' 
 y445K5k6JK1+vFGK&w/#/
	
 ##(33(r   c           
      "   |sy|j                         D ]t  \  }}t        |j                  |j                  D cg c]7  }|j                  '| j
                  j                  |j                        |vr|9 c}|j                        ||<   v yc c}w )aW  Remove information from parents of criteria.

        Concretely, removes all values from each criterion's ``information``
        field that have one of ``parents`` as provider of the requirement.

        :param criteria: The criteria to update.
        :param parents: Identifiers for which to remove information from all criteria.
        N)itemsr7   r:   r;   r
   r\   rt   r<   )r   ri   parentskeyr   r;   s         r   !_remove_information_from_criteriaz,Resolution._remove_information_from_criteria   s     &nn. 	NC%$$ (1'<'<##**277++K,>,>?wN	   ++HSM	s   <Bc                 V   | j                   j                  || j                  j                  t	        | j                  j
                  t        j                  d            t	        | j                  j
                  t        j                  d            | j                  j                        S )Nr:   r;   )rr   resolutionsr:   r;   rj   )	r\   get_preferencerc   rh   r   ri   rx   rz   rj   )r   names     r   _get_preferencezResolution._get_preference   s    ww%%

**&

####L1 (

####M2 "ZZ88 & 
 	
r   c                      	  j                   j                  |   t         fd|j	                         D              S # t        $ r Y yw xY w)NFc              3   X   K   | ]!  }j                   j                  |        # yw)r	   r3   Nr\   is_satisfied_by)r#   r$   current_pinr   s     r   r%   z8Resolution._is_current_pin_satisfying.<locals>.<genexpr>   s-      
 GG##[#I
   '*)rc   rh   KeyErrorallr*   )r   r   r   r   s   `  @r   _is_current_pin_satisfyingz%Resolution._is_current_pin_satisfying   sU    	**,,T2K  
//1
 
 	
  		s   A   	AAc                     | j                   j                  j                         }| j                  j	                  |      D ]  }| j                  |||        |S )Nr3   rK   )rc   ri   rk   r\   get_dependenciesr|   )r   r3   ri   r	   s       r   _get_updated_criteriaz Resolution._get_updated_criteria   sW    ::&&++-7733i3H 	KK!!(K	!J	Kr   c                      j                   j                  |   }g }|j                  D ]  	  j                        }t         fd|j                         D              }|st        |       j
                  j                          j                   j                  j                  |        j                   j                  j                  |d         j                   j                  |<   g c S  |S # t        $ rL} j
                  j                  |j                         |j                  |j                         Y d }~d }~ww xY w)Nc              3   X   K   | ]!  }j                   j                  |        # ywr   r   )r#   r$   r3   r   s     r   r%   z7Resolution._attempt_to_pin_criterion.<locals>.<genexpr>   s-       ''A'Kr   r   )rc   ri   r:   r   r   r]   rejecting_candidater   rl   r   r*   r1   pinningupdaterh   pop)r   r   r   rR   ri   e	satisfiedr3   s   `      @r   _attempt_to_pin_criterionz$Resolution._attempt_to_pin_criterion   s   JJ''-	"-- 	I55i@  "335 I +IyAAGGOOiO0JJ&&x0 JJ""4.'0DJJt$I7	> 9 * ++AKKCakk*s   C77	E AEEc                     t        j                  d |D        d |D              }|D ch c]  } j                  j                  |       }}t	         j
                        dk\  r/ j
                  d= d}|s	  j
                  j                         }|j                  j                         \  }} j                  j                  |      D 	ch c]  }	 j                  j                  |	       }
}	|
j                  |       }|sj                  j                         D cg c]  \  }}|t!        |j"                        f c}}j%                  gf        fd} j'                           |       }|ryt	         j
                        dk\  r/yc c}w # t        t        f$ r t        |      w xY wc c}	w c c}}w )a2  Perform backjumping.

        When we enter here, the stack is like this::

            [ state Z ]
            [ state Y ]
            [ state X ]
            .... earlier states are irrelevant.

        1. No pins worked for Z, so it does not have a pin.
        2. We want to reset state Y to unpinned, and pin another candidate.
        3. State X holds what state Y was before the pin, but does not
           have the incompatibility information gathered in state Y.

        Each iteration of the loop will:

        1.  Identify Z. The incompatibility is not always caused by the latest
            state. For example, given three requirements A, B and C, with
            dependencies A1, B1 and C1, where A1 and B1 are incompatible: the
            last state might be related to C, so we want to discard the
            previous state.
        2.  Discard Z.
        3.  Discard Y but remember its incompatibility information gathered
            previously, and the failure we're dealing with right now.
        4.  Push a new state Y' based on X, and apply the incompatibility
            information from Y to Y'.
        5a. If this causes Y' to conflict, we need to backtrack again. Make Y'
            the new Z and go back to step 2.
        5b. If the incompatibilities apply cleanly, end backtracking.
        c              3   N   K   | ]  }|j                   |j                     y wr   rK   r#   cs     r   r%   z'Resolution._backjump.<locals>.<genexpr>.  s     >!)=QXX>s   %%c              3   4   K   | ]  }|j                     y wr   rD   r   s     r   r%   z'Resolution._backjump.<locals>.<genexpr>/  s     +qQ]]+rG      rb   Fc                  B   D ]  \  } }|s
	 j                   j                  |    }j                  j	                  | t        j                   j                  t        j                  d            t        j                   j                  t        j                  d      | |i            }t        |      }|s y|j                  |j                         t        |t        |j                        |      j                   j                  | <    y# t        $ r Y w xY w)Nr*   r<   rq   Fr9   T)rc   ri   r   r\   rw   r   rx   ry   rz   r   extendr<   r7   rv   r;   )kr<   r   r{   r:   incompatibilities_from_brokenr   s        r   _patch_criteriaz-Resolution._backjump.<locals>._patch_criteriaQ  s   ,I (A(, !$(JJ$7$7$:	 #gg22#$%4 JJ//$112DE& +: JJ//$//0CD 12+ 3 G "1!9J%$%,,Y-H-HI-6#-$()>)>$?*;.DJJ''*/8 / $ ! !s   D	DDT)	itertoolschainr\   rt   lenr^   r   rh   popitemrd   r   rP   r   
isdisjointri   r~   rv   r<   rl   rn   )r   rR   incompatible_reqsr$   incompatible_depsincompatible_statebroken_stater   r3   dcurrent_dependenciesr   vr   successr   s   `              @r   	_backjumpzResolution._backjump  s   > &OO>v>+F+
 ;LLQTWW--a0LL$,,1$R  "'(7#'<<#3#3#5L&2&:&:&B&B&DOD)
 "WW55i@( GG$$Q'($ ( *>)H)H%* &" )" )11779-Aq D,,-.-) *00$1DE>   "%'G G $,,1$R U M #H- 7.v667(-s   "F:7F "F;$!G F8c           	      L   | j                   rt        d      | j                  j                          t	        t        j                         i g       g| _         |D ]+  }	 | j                  | j                  j                  |d        - | j                          t        |      D ]2  }| j                  j!                  |       | j                  j                  j#                         D cg c]  \  }}| j%                  ||      s| }}}|s4| j                  j'                  | j                         | j                  c S t)        | j                  j                  j+                               t)        |      z
  }	t-        || j.                        }
| j1                  |
      }|r|D cg c]  }|j                  D ]  }|  }}}| j                  j3                  |       | j5                  |      }|| j                  j6                  d d  |st        | j                  j6                        | j                  j                  j#                         D ch c]  \  }}||	v r| j%                  ||      s| }}}| j9                  | j                  j                  |       | j                          | j                  j;                  || j                         5 t=        |      # t        $ r$}t        |j                  j                        d }~ww xY wc c}}w c c}}w c c}}w )	Nzalready resolvedrg   rK   )index)rc   )r   )rR   )r   rc   )r^   RuntimeErrorr]   startingrX   collectionsOrderedDictr|   rc   ri   r   rP   r   r;   rn   rangestarting_roundr~   r   endingsetkeysminr   r   resolving_conflictsr   rj   r   ending_roundrU   )r   r@   
max_roundsr$   r   round_indexr   r   unsatisfied_namessatisfied_namesr   failure_causesr   rF   rR   r   newly_unsatisfied_namess                    r   resolvezResolution.resolve}  s   <<122 #//1!#
  	DAD%%djj&9&91T%J	D 	 , 1	FKGG"""5 '+jj&9&9&?&?&A!"C66sIF ! ! %TZZ0zz! "$**"5"5":":"<=!A O
 (d.B.BCD!;;DAN%3KQ]]K!K!KK ++6+:..017

++A. .tzz/J/JKK +/***=*=*C*C*E+&Yo- ;;CK +' + 66JJ'')@ $$&GG  {$** Ec1	Ff  
++w * D*1;;+B+BCCD!* L+s*   (K$*L)L"L $	L-LLN)r   r   r   r   r   propertyrc   rn   r|   r   r   r   r   r   r   r   r   r   r   rZ   rZ   i   sR    
 * *#%)N2

#Jm^L,r   rZ   c                     ||v ry|| vry| |   j                         D ]I  }	 |t        |         }||v r|j                  |        yt	        | |||      s8|j                  |        y y# t        $ r Y Xw xY w)NTF)rL   idr   add_has_route_to_root)ri   r   all_keys	connectedppkeys         r   r   r     s    
i
(c]&&( 
	BqE?D 9MM#hh	BMM#
   		s   A++	A76A7Resultzmapping graph criteriac                    | j                   }|j                         D ci c]  \  }}t        |      | }}}d |t        d       <   t               }|j	                  d        d h}| j
                  j                         D ]~  \  }}t        | j
                  |||      s||vr|j	                  |       |j                         D ]8  }		 |t        |	         }
|
|vr|j	                  |
       |j                  |
|       :  t        |j                         D ci c]  \  }}||v s|| c}}|| j
                        S c c}}w # t        $ r Y w xY wc c}}w )N)rh   graphri   )rh   r~   r   r   r   ri   r   rL   r   connectr   )rc   rh   r   r   r   r   r   r   r   r   r   s              r   _build_resultr     sE   mmG%,]]_5TQ1q5H5HRXOE	IIdOI....0 %Y!%..#xKeIIcN&&( 	%A1 5 		$MM$$	%% ")--/D$!QQ)^AD + 6   Es#   D?EE
%E
	EEc                       e Zd ZdZeZddZy)Resolverz3The thing that performs the actual resolution work.c                 ~    t        | j                  | j                        }|j                  ||      }t	        |      S )a  Take a collection of constraints, spit out the resolution result.

        The return value is a representation to the final resolution result. It
        is a tuple subclass with three public members:

        * `mapping`: A dict of resolved candidates. Each key is an identifier
            of a requirement (as returned by the provider's `identify` method),
            and the value is the resolved candidate.
        * `graph`: A `DirectedGraph` instance representing the dependency tree.
            The vertices are keys of `mapping`, and each edge represents *why*
            a particular package is included. A special vertex `None` is
            included to represent parents of user-supplied requirements.
        * `criteria`: A dict of "criteria" that hold detailed information on
            how edges in the graph are derived. Each key is an identifier of a
            requirement, and the value is a `Criterion` instance.

        The following exceptions may be raised if a resolution cannot be found:

        * `ResolutionImpossible`: A resolution cannot be found for the given
            combination of requirements. The `causes` attribute of the
            exception is a list of (requirement, parent), giving the
            requirements that could not be satisfied.
        * `ResolutionTooDeep`: The dependency tree is too deeply nested and
            the resolver gave up. This is usually caused by a circular
            dependency, but you can try to resolve this by increasing the
            `max_rounds` argument.
        )r   )rZ   r_   r`   r   r   )r   r@   r   
resolutionrc   s        r   r   zResolver.resolve  s8    8  t}}=
""<J"GU##r   N)d   )r   r   r   r   r   base_exceptionr   r   r   r   r   r      s    =&N$r   r   )r   r   rx   	providersr   structsr   r   r   
namedtupler   	Exceptionr   r   r1   objectr7   rN   rP   rU   rX   rZ   r   r   r   r   r   r   r   <module>r      s       ' D D///}h7 
	 
. 


- 

$4 $4N	' 	? ' ' 	w(KL`, `,F& 
 		*B	C<#$ #$r   