
    7.i)                        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  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rSr\S 5       r\S 5       r S r!\S 5       r"\S 5       r#\S 5       r$\S 5       r%\S 5       r&\SS j5       r'S r(\S 5       r)\SS j5       r*\S S j5       r+\,S:X  a,  S\RZ                  ;   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	installerorganizationmachinez~/.condaz~/.anaconda	org_tokeninstaller_tokenmachine_tokenz^(?:[A-Za-z0-9]|_|-){1,36}$c                      [         $ )zE
Returns the version token, which is just the
version string itself.
r
        R/data/cameron/miniconda/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_pathr9   5   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SU R                  5       -   n[        R                  " U5      nU(       a  [        SX5        UR	                  U5        [        5        HJ  nS HA  n[        XVU -   5      n[        U5      (       d  M#  [        XqS-   SS9nUR	                  U5        MC     ML     [        [        R                  S U 5       5      5      nU(       d  [        SU5        U Vs/ s H'  n[        R                  " [        U5      (       d  M%  UPM)     snm
[        T
5      [        U5      :  a'  S	R                  U
4S
 jU 5       5      n	[        SX5        T
$ s  snf )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
ANACONDA_ANON_USAGE_z!Found %s token in environment: %s) .z tokenT)single_linec              3   6   #    U  H  o(       d  M  Uv   M     g 7fNr   .0ts     r    	<genexpr>!_system_tokens.<locals>.<genexpr>{   s     76aQ6s   
	zNo %s tokens foundz, c              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7fr@   r   )rB   rC   valids     r    rD   rE      s     @v!%AAvs   		z+One or more invalid %s tokens discarded: %s)upperr   r1   r   r2   r9   r   r   r   listdictfromkeysrematchVALID_TOKEN_RElen)fnamewhattokensenv_namet_tokenr7   pfxfpathrC   invalidrG   s             @r    _system_tokensrX   f   s    F%5Hkk(#G2DBgCU{+Ee}}$U8ONg&	   $--76778F#T* >1"((>1"=Q>E
5zCK))@v@@<dLL	 ?s   %$EEc                  "    [        [        S5      $ )z'
Returns the list of installer tokens.
r   )rX   INSTALLER_TOKEN_NAMEr   r   r    installer_tokensr[      s    
 .<<r   c                  "    [        [        S5      $ )z*
Returns the list of organization tokens.
r   )rX   ORG_TOKEN_NAMEr   r   r    organization_tokensr^      s    
 ..99r   c                  "    [        [        S5      $ )z%
Returns the list of machine tokens.
r   )rX   MACHINE_TOKEN_NAMEr   r   r    machine_tokensra      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   )rV   s    r    client_tokenrf      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_tokenrh      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.
etcrc   r   )r,   prefixr   r   )rk   rV   s     r    environment_tokenrl      s/     ~,E}f55r   c                 *   U (       d  g U R                  S5      n[        U5      S:X  a  [        U5      (       d   S5       e[        [	        S U5      5      n[        [	        [
        R                  USS 5      5      n[        US   [        5      (       d   S5       eUS   R                  S	5      S
:X  d   S5       e[        US   [        5      (       d   S5       eUS   R                  S5      n[        U[        5      (       a  US:  d   S5       e[        R                  R                  [        R                  R                  S9R!                  5       nX#:  a  [#        S[        X2-
  5      5        gUS   R                  S5      nU(       d   S5       e[$        R&                  " U5      R(                  n[*        R,                  " U5      R/                  S5      R1                  S5      nU$ ! [2         a   n[#        S[5        U5      U5         SnAgSnAff = f)a  Unpacks an Anaconda auth token and returns the encoded user ID for
potential inclusion in the user agent, along with its expiration.

The Anaconda API key takes the form of a standard OAuth2 access token,
with the additional requirement that the "sub" field is a UUID string.
This code perorms a basic set of integrity checks to confirm that this
is the case. If the checks pass, the function returns an encoded form
of "sub" as well as the "exp" value to enable sorting by expiration.
If the checks fail, the function returns (None, 0).

The signature is not fully validated as part of the check; only that it
is a base64-encoded value. Validation is left to anaconda-auth.

Returns:
  token: the token if valid; None otherwise
  exp: the expiration time
Nr=      z3 parts expectedc                 4    [         R                  " U S-   5      $ )Nz===)base64urlsafe_b64decode)xs    r    <lambda>_jwt_to_token.<locals>.<lambda>   s    6#;#;AI#Fr      r   zInvalid headertypJWTr	   zInvalid payloadexpzInvalid expiration)tzzAPI key expired %ds agosubzInvalid subscriberascii=z!Unexpected %s parsing API key: %s)r/   rO   allrI   mapjsonloads
isinstancerJ   r1   intdtdatetimenowtimezoneutc	timestampr   uuidUUIDbytesrp   urlsafe_b64encodedecodestrip	Exceptiontype)sr8   rx   r   rz   tokenexcs          r    _jwt_to_tokenr      s   $ D5zQ3u::A/AA-SFNOSU2AY/0%(D));+;;)Qx||E"e+=-==+%(D))<+<<)Ahll5!#s##aE1EE/kkooo1;;=9,c#)n=Ahll5!(((siin""((-44W=CCCH D2DIsCCDs   E%G( 0A7G( (
H2HHc                  J    SSK Jn Jn  [        S5        U R	                  SS9nUR
                  (       a#  [        UR
                  5      n[        SU5        U$  [        S
5        g	! [         a    [        S5         N#W a     N*[         a  n[        SU5         S	nANDS	nAff = f)zReturns the base64-encoded uid corresponding to the logged
in Anaconda Cloud user, if one is present.
Returns:
    str: Base64-encoded token, or None if no valid token found.
r   )	TokenInfoTokenNotFoundErrorzModule anaconda_auth loadedzanaconda.com)domainz!Retrieved Anaconda auth token: %sz"Module anaconda_auth not availablez9Unexpected error retrieving token using anaconda_auth: %sNzNo Anaconda API token found)	anaconda_auth.tokenr   r   r   loadapi_keyr   r+   r   )r   r   tinfor   r   s        r    anaconda_auth_tokenr      s    QE,-n5==!%--0E6>L  ()  534  QJCPPQs$   AA% %B"<B"	B"BB"c                     [        [        5       [        5       [        5       [	        U 5      [        5       [        5       [        5       [        5       5      $ )zj
Returns the token set, in the form of a Tokens namedtuple.
Fields: version, client, session, environment
)	r   r!   rf   rh   rl   r   r[   r^   ra   )rk   s    r    
all_tokensr     s@     &!	 	r   c                 <   S[         -   /nU(       Gaa  [        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        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i/Nr   rA   s     r    rD   token_string.<locals>.<genexpr>3  s     <+;a+;   c              3   ,   #    U  H
  nS U-   v   M     g7f)zo/Nr   rA   s     r    rD   r   5  s     ?+>a+>r   c              3   ,   #    U  H
  nS U-   v   M     g7f)zm/Nr   rA   s     r    rD   r   7  s     :>a>r   z&anaconda_anon_usage disabled by config zFull aau token string: %s)r   r   r   r2   r   r   r   r   extendr   r   r   r   )rk   enabledr8   valuesr5   s        r    token_stringr     s    k!"EF#==LL-.>>LL./LL 2 223  LL 5 556
 LL<6+;+;<<LL?6+>+>??>>LL:6>>::78XXe_F
&/Mr   __main__z--randomr@   )NT)/rp   r   r   r   rL   r,   r   collectionsr   osr   os.pathr   r   r   r   r<   r   utilsr   r   r   r   r   r   re   ANACONDA_DIRr]   rZ   r`   rN   r!   r9   rX   r[   r^   ra   rf   rh   rl   r   r   r   r   __name__argvprintr   r   r    <module>r      s      	 
  "  3 3  J J		
 
#
-(( $  0   - -`B = = : : 9 9 8 8 $ $ 
6 
6.Db * *0  "  B zSXXmoln	 r   