
    u@hL                        S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	J
r
JrJr  SSKJr  SSKJrJrJrJrJr  \" SS	5      r\	" S
5      r\	" S5      rSrSr\S 5       r\S 5       rS r\S 5       r\S 5       r\S 5       r\S 5       r \SS j5       r!\S 5       r"\SS j5       r#\SS j5       r$\%S:X  a,  S\RL                  ;   a  \'" \" 5       5        g\'" \$" 5       5        gg)    N)
namedtuple)environ)
expanduserisdirisfilejoin   __version__)_debug_random_token
_read_file_saved_tokencachedTokens)versionclientsessionenvironmentanaconda_cloudorganizationmachinez~/.condaz~/.anaconda	org_tokenmachine_tokenc                      [         $ )zE
Returns the version token, which is just the
version string itself.
r
        :lib/python3.13/site-packages/anaconda_anon_usage/tokens.pyversion_tokenr   $   s
     r   c                  >    SSK Jn   U R                  n/ n[        S5      nU H  nUR                  S	5      (       d  M  UR                  S
5      SS nUS   S:X  a  X5S'   ODUS   R                  S5      (       a+  [        R                  " US   SS 5      US'   US   (       d  M  S
R                  U5      n[        U5      (       d  M  XC:w  d  M  UR                  U5        M     U$ ! [         a-    [	        S5        [
        R                  S:X  a  SnOSnUS-  n GNf = f)z,
Returns the search path for system tokens.
r   )	constantsz'conda not installed in this environmentwin32)zC:/ProgramData/conda/.condarc)z/etc/conda/.condarcz/var/lib/conda/.condarc)z$XDG_CONFIG_HOME/conda/.condarcz~/.config/conda/.condarcz~/.conda/.condarcz
~/.condarcz$CONDARC~z	/.condarc/N$r	   )
conda.baser!   SEARCH_PATHImportErrorr   sysplatformr   endswithsplit
startswithr   getr   r   append)c_constantssearch_pathresulthomepathpartss         r   _search_pathr7   -   s   

 	8!--& Fc?D }}[))

3$8s?!H1X  %%{{58AB<0E!H8xx;;4<MM$  MG  
 	89<<7"<KLK 
 	

s   C% %3DDc                    / n[        5        Hf  n[        X05      n[        U5      (       d  M   [        XAS-   SS9nU(       d  M6  UR	                  S5       H  nXb;  d  M
  UR                  U5        M     Mh     U(       d  [        SU5        U$ )a%  
Returns an organization or machine token installed somewhere
in the conda path. Unlike most tokens, these will typically
be installed by system administrators, often by mobile device
management software. There can also be multiple tokens present
along the path, in which case we combine them
z tokenT)single_liner$   zNo %s tokens found)r7   r   r   r   r-   r0   r   )fnamewhattokensr5   fpatht_tokenstokens          r   _system_tokensr@   ^   sz     FT!e}}eH_$G8!,&MM%( -  #T*Mr   c                  "    [        [        S5      $ )z*
Returns the list of organization tokens.
r   )r@   ORG_TOKEN_NAMEr   r   r   organization_tokensrC   u   s    
 ..99r   c                  "    [        [        S5      $ )z%
Returns the list of machine tokens.
r   )r@   MACHINE_TOKEN_NAMEr   r   r   machine_tokensrF   }   s    
 ,i88r   c                  8    [        [        S5      n [        U SSS9$ )z
Returns the client token. If a token has not yet
been generated, an attempt is made to do so. If
that fails, an empty string is returned.
	aau_tokenr   T)node_tie)r   
CONFIG_DIRr   )r=   s    r   client_tokenrK      s     [)Ex$77r   c                      [        S5      $ )zR
Returns the session token, generated randomly for each
execution of the process.
r   )r   r   r   r   session_tokenrM      s     ##r   c                 \    U c  [         R                  n [        U SS5      n[        USU 5      $ )z
Returns the environment token for the given prefix, or
sys.prefix if one is not supplied. If a token has not
yet been generated, an attempt is made to do so. If that
fails, an empty string is returned.
etcrH   r   )r*   prefixr   r   )rP   r=   s     r   environment_tokenrQ      s/     ~,E}f55r   c            	         [        [        [        S5      5      n [        U S5      nU(       d  g [        R
                  " U5      nU(       a  [        U[        5      (       d  [        S5        gSu  p4UR                  S5      =(       d    0 R                  5        H  u  pV [        R
                  " [        R                  " U5      5      S   n[        R
                  " [        R                  " UR                  S	S
5      S   S-   5      5      n[        US   5      nX:  a	  US   nUnM  M     U(       d  [        S5        g [         R"                  " U5      R$                  n[        R&                  " U5      R)                  S5      R+                  S5      n	[        SU	5        U	$ ! [         a  n[        SU5         SnAgSnAff = f! [         a  n[        SXR5         SnAGMI  SnAff = f! [         a  n[        SU5         SnAgSnAff = f)a1  Retrieve Anaconda Cloud token from keyring.

Examines all entries under 'Anaconda Cloud' in the keyring and
selects the token with the latest expiration date. This handles
migration from 'anaconda.cloud' to 'anaconda.com' entries.

Returns:
    str: Base64-encoded token, or None if no valid token found.
keyringzanaconda keyringNz7Unexpected JSON decoding error parsing keyring file: %szEmpty keyring)r   NzAnaconda Cloudapi_key.   r	   z===expsubz/Unexpected error parsing keyring entry '%s': %sz'No Anaconda Cloud keyring records foundascii=z(Unexpected error retrieving username: %sz"Retrieved Anaconda Cloud token: %s)r   r   ANACONDA_DIRr   jsonloads	Exceptionr   
isinstancedictr/   itemsbase64	b64decoder-   intuuidUUIDbytesurlsafe_b64encodedecodestrip)
r=   dataexcrW   rX   keyrectdatat_expr?   s
             r   anaconda_cloud_tokenrq      s    tL)45Ee/0Dzz$ z$--HCXX./52<<>	PJJv//45i@EJJv//C0CA0F0NOPEe%E{El  ? 89iin""((-44W=CCCH /7L7  H#N  	PDcOO	P  93?sI   F" BG AG* "
G,F==G
G'G""G'*
H
4HH
c           
          [        [        5       [        5       [        5       [	        U 5      [        5       [        5       [        5       5      $ )zj
Returns the token set, in the form of a Tokens namedtuple.
Fields: version, client, session, environment
)r   r   rK   rM   rQ   rq   rC   rF   )rP   s    r   
all_tokensrs      s:     &! r   c                    S[         -   /nU(       Ga.  [        U 5      nUR                  (       a  UR                  SUR                  -   5        UR                  (       a  UR                  SUR                  -   5        UR
                  (       a  UR                  SUR
                  -   5        UR                  (       a  UR                  SUR                  -   5        UR                  (       a"  UR                  S UR                   5       5        UR                  (       a"  UR                  S UR                   5       5        O[        S5        S	R                  U5      n[        S
U5        U$ )z\
Returns the token set, formatted into the string that is
appended to the conda user agent.
zaau/zc/zs/ze/za/c              3   ,   #    U  H
  nS U-   v   M     g7f)zo/Nr   .0ts     r   	<genexpr>token_string.<locals>.<genexpr>   s     ?+>a+>   c              3   ,   #    U  H
  nS U-   v   M     g7f)zm/Nr   rv   s     r   ry   rz      s     :>a>r{   z&anaconda_anon_usage disabled by config zFull aau token string: %s)r   rs   r   r0   r   r   r   r   extendr   r   r   )rP   enabledr6   valuesr3   s        r   token_stringr      s     k!"EF#==LL-.>>LL./LL 2 223  LL 5 556
 LL?6+>+>??>>LL:6>>::78XXe_F
&/Mr   __main__z--random)N)NT)(rb   r\   r*   re   collectionsr   osr   os.pathr   r   r   r    r   utilsr   r   r   r   r   r   rJ   r[   rB   rE   r   r7   r@   rC   rF   rK   rM   rQ   rq   rs   r   __name__argvprintr   r   r   <module>r      sY     
  "  3 3  J J	
 
#
-($    - -`. : : 9 9 8 8 $ $ 
6 
6 + +\     > zSXXmoln	 r   