
    7.i(              
       p   S SK r S SKrS SKrS SKrS SKrS SKrS SKJrJrJ	r	  S SK
Jr  S SKJrJr  \R                  R!                  S5      =(       d    Sr\" \R                  R!                  S5      5      =(       d    \r/ q0 q\" 5       r\R                  R!                  S5      =(       d    Sr\R                  R!                  S	5      =(       d    SrS
rS rSrSrSr\S-
  S-  S-   rS rS r S
S.S jr!SS jr"S r#\ RH                  " \#5        SS jr%[(        4S\&S\&S\S\\&   4S jjr'S S jr(S r)S!S jr*g)"    N)dirnameisdirisfile)RLock)ListOptional ANACONDA_ANON_USAGE_DEBUG_PREFIX ANACONDA_ANON_USAGE_DEBUGANACONDA_ANON_USAGE_READ_CHAOSANACONDA_ANON_USAGE_WRITE_CHAOSF            c                    ^  U 4S jnU$ )Nc                  
  > TR                   U [        UR                  5       5      4nU[        ;  a1  [           U[        ;  a  T" U 0 UD6[        U'   S S S 5        [        U   $ [        U   $ ! , (       d  f       [        U   $ = f)N)__name__tupleitemsCACHELOCK)argskwargskeyfuncs      Q/data/cameron/miniconda/lib/python3.13/site-packages/anaconda_anon_usage/utils.pycall_if_neededcached.<locals>.call_if_needed1   st    }}dE&,,.$9:e e#!%t!6v!6E#J  SzuSz  Szs   A,,
B )r   r   s   ` r   cachedr!   0   s    
     c                      U (       d  [         R                  5         g [         R                  5        VVs0 s H  u  pUS   U ;  d  M  X_M     snnq g s  snnf )Nr   )r   clearr   )r   kvs      r   _cache_clearr'   @   s>     "'++-D-$!1Q4t3C-DDs   AAerrorc                    U(       a"  [         (       d  SSKJn  UR                  (       + nU(       d  [         (       a#  [	        [
        U -   U-  [        R                  S9  g g )Nr   )context)file)DEBUGconda.base.contextr+   jsonprintDPREFIXsysstderr)sr)   r   r+   s       r   _debugr5   I   s=    UU 	/LL w{d"4 r"   c                     [         R                  " [        S-  S-
  S-  S-   5      n[        R                  " U5      R                  S5      S [         n[        SX5        U$ )Nr   r      asciizGenerated %s token: %s)osurandomTOKEN_LENGTHbase64urlsafe_b64encodedecoder5   )whatdataresults      r   _random_tokenrB   X   sX     ::|a'!+1A56D%%d+227;M\JF
#T2Mr"   c                  <    [          H  u  pp#[        XU5        M     g)z
Called upon the graceful exit from conda, this attempts to
write an environment token that was deferred because the
environment directory was not yet available.
N)DEFERRED_write_attempt)
must_existfpathtokenr?   s       r   _final_attemptrI   a   s     +3&
5z%0 +3r"   c                 l   U (       a"  [        U 5      (       d  [        SU 5        [        $  U(       a  [        [        R
                  S5      e[        R                  " [        U5      SS9  [        (       a  US-   n[        US5       nUR                  U5        SSS5        [        SU5        [        $ ! , (       d  f       N = f! [         af  n[        US	S5      [        R                  [        R                   [        R
                  4;   a  [        S
5        O[        SUUSS9  ["        s SnA$ SnAff = f)z^
Attempt to write the token to the given location.
Return True with success, False otherwise.
zDirectory not ready: %szTesting permissions issuesT)exist_okz
# Test commentwNzToken saved: %serrnoz(No write permissions; cannot write tokenz?Unexpected error writing token file:
  path: %s
  exception: %sr(   )r   r5   WRITE_DEFEROSErrorrM   EROFSr9   makedirsr   WRITE_NEWLINEopenwriteWRITE_SUCCESS	ExceptiongetattrEACCESEPERM
WRITE_FAIL)rF   rG   client_tokenemulate_failfpexcs         r   rE   rE   o   s    
 %
++(*5%++'CDD
GENT2='*<<L%HH\"  %(    3&5<<ekk*RR=>S	 s7   AC B2C 2
C <C 
D3AD.(D3.D3rG   r?   deferred_writesreturnc                 <    U H  u  p4pVX@:X  d  M  Xa:X  d  M  Us  $    g)a|  
Check if the deferred token write exists in the DEFERRED write array.
If the path must already exist, this helper function determines
if the token will be written in the future.

Args:
    fpath: The file path to check for.
    what: The type of token to check for.
    deferred_tokens: The list of deferred tokens to check.

Returns:
    The token if it exists, otherwise None.
Nr    )rG   r?   r_   _r]   rH   rL   s          r   _deferred_existsrc      s       +u;19L +r"   c                    [        X5      nU(       a  [        SX5        U$ [        SUR                  5       U 5        US   [        ;   a  [        SU5        g[	        U 5      (       d  [        SU5        g [        U 5       nUR                  5       nSSS5        U(       a*  WR                  5       nU(       a  UR                  5       S   n[        SUW5        U$ ! , (       d  f       NN= f! [         a  n[        SXS	S
9   SnAgSnAff = f)
Implements the saved token functionality. If the specified
file exists, and contains a token with the right format,
return it. Otherwise, generate a new one and save it in
this location. If that fails, return an empty string.
zReturning deferred %s: %sz%s path: %sr   zPretending %s is not presentz%s file is not presentNzRetrieved %s: %sz!Unexpected error reading: %s
  %sTr(   )
rc   r5   
capitalize
READ_CHAOSr   rS   readstrip
splitlinesrV   )rG   r?   	read_onlysingle_linedeferred_tokenr]   r@   r^   s           r   
_read_filern      s     &e2N*DA
=$//+U3Aw*-t4E]]'.	Qewwy zz|??,Q/D%tT2K   	Q74P	Qs1   4C) ?CAC) 
C&"C) )
D3DDc                     [         R                  " 5       =(       d    [         R                  " 5       n U (       dJ  [        [         SS5      (       a4  [         R                  " [         R
                  " 5       S   S9R                  n U (       aE  U R                  S[        R                  S9n [        R                  " U 5      n U R                  S5      n U $ )zY
Returns a base64-encoded representation of the host ID
as determined by uuid.getnode().
_generate_time_safeNr   )bytesr   )	byteorderr8   )uuid_unix_getnode_windll_getnoderW   UUIDrp   nodeto_bytesr2   rr   r<   r=   r>   )vals    r   _get_node_strrz      s    
 



8$"6"6"8C74!6==iid668;<AA
ll1l6&&s+jj!Jr"   c                 v   US-   nS=pV[        XSS9=(       d    SnUR                  SS5      tpx[        U5      [        :  a  U(       a  [	        SU5        SnU(       a  [        5       n	U S	-   n
[        U
S
SS9=(       d    SnU=(       d    U(       a  US   OSnU(       d  U(       d  O6X:w  a  [	        SU5        SnO"U(       a  [	        SU5        SnO[	        SU5        X:w  aV  U(       a	  X:X  a  SOSOSnU	=(       d    Sn	[	        SX5        [        SXS5      [        :X  a  [        R                  SXS45        U(       d  U(       as  U(       a  gU(       a
  [        5       n[        X XqS   [        ;   5      nU[        :X  a  [	        SU5        gU[        :X  a#  [	        SU5        [        R                  X Xq45        U$ )re   z tokenFT)rl   r
    r   z#Regenerating %s due to short length_hostzHost idr   Nz$Regenerating %s due to hostID changezStripping host ID from %s filezHost ID match confirmed for %s	MigratingUpdatingSavingz%s host ID: %szHost IDzReturning blank %szDeferring %s write)rn   splitlenr;   r5   rz   rE   rN   rD   appendrB   WRITE_CHAOSrZ   )rG   r?   rF   rk   node_tie
regenerateresaver[   xtracurrent_nodenpath
saved_node	true_nodeactionstatuss                  r   _saved_tokenr      s    (?DJet<BL&,,S!4L
<<'8$?
 %ydCIr
=d47	Y&94@J3T:F3T:%  !* 9z 
 (-2L#V:eU%@KOY GHV(?L
<aKAWXZ'.{" '.OOZCDr"   )random)F)FF)NFF)+atexitr<   rM   r9   r2   rs   os.pathr   r   r   	threadingr   typingr   r   environgetr1   boolr-   rD   r   r   rg   r   rR   rU   rN   rZ   MIN_ENTROPYr;   r!   r'   r5   rB   rI   registerrE   strrc   rn   rz   r   r    r"   r   <module>r      sC      	 
  * *  !
**..;
<
BRZZ^^789DW 
 	w ZZ^^<=C
 jjnn>?E2
  aA%) E ! 51  D 4<,0c]* QF >r"   