
    j-              
           d dl Z 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	 d dl
mZmZ d dlmZ d dlmZ d dlmZ dd	lmZmZmZmZ dd
lmZ  edd      Z edd      Z ej8                  e      Z eee	z   dz         Z  eee	z   dz         Z! eee	z   dz         Z"dee   de#defdZ$de%de%fdZ&de%fdZ'de%ddfdZ(de%ddfdZ)de%ddfdZ*	 d+ddd e%dee%   d!eee%      de%fd"Z+d#e,d$e,d%e,de,fd&Z-dee.   fd'Z/de0fd(Z1d)e%de%fd*Z2y),    N)
ContextVar)ascii_lettersdigits)ListOptional)urlparse)AccessTokenInfo)ClientAuthenticationError   )DEFAULT_REFRESH_OFFSET!DEFAULT_TOKEN_REFRESH_RETRY_DELAYEnvironmentVariablesKnownAuthorities)TokenRefreshStatuswithin_credential_chainF)default
within_dacz-.z_-.:/z_-. tokenlast_request_timereturnc                    | t         j                  S t        t        j                               }|| j                  k\  rt         j                  S ||z
  t
        k  rt         j                  S | j                  || j                  k\  rt         j                  S | j                  |z
  t        k  rt         j                  S t         j                  S )a^  Determine the refresh status of a token.

    :param ~azure.core.credentials.AccessTokenInfo or None token: The token to evaluate.
        If None, a refresh is required.
    :param int last_request_time: The time of the last token request, as seconds since the epoch.
    :return: The refresh status of the token.
    :rtype: TokenRefreshStatus
    )
r   REQUIREDinttime
expires_onr   
NOT_NEEDED
refresh_onRECOMMENDEDr   )r   r   nows      _/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/identity/_internal/utils.pyget_refresh_statusr!   $   s     }!***
diik
C e!*** !BB!,,, #u/?/?(?!--- #!77!---(((    	authorityc                     t        |       }|j                  sd| j                  d      z   S |j                  dk7  rt        dj	                  |             | j                  d      S )zEnsure authority uses https, strip trailing spaces and /.

    :param str authority: authority to normalize
    :return: normalized authority
    :rtype: str
    :raises: ValueError if authority is not a valid https URL
    zhttps://z /httpszL'{}' is an invalid authority. The value must be a TLS protected (https) URL.)r   schemerstrip
ValueErrorformat)r#   parseds     r    normalize_authorityr+   E   sf     i F==I,,T222}}Zaabkl
 	
 D!!r"   c                      t         j                  j                  t        j                  t
        j                        } t        |       S N)osenvirongetr   AZURE_AUTHORITY_HOSTr   AZURE_PUBLIC_CLOUDr+   )r#   s    r    get_default_authorityr3   Y   s/    

3HHJZJmJmnIy))r"   scopec                 B    | rt        d | D              rt        d      y)zRaise ValueError if scope is empty or contains a character invalid for a scope

    :param str scope: scope to validate
    :raises: ValueError if scope is empty or contains a character invalid for a scope.
    c              3   ,   K   | ]  }|t         v  y wr-   )VALID_SCOPE_CHARACTERS.0cs     r    	<genexpr>z!validate_scope.<locals>.<genexpr>d   s     GA!77G   zeAn invalid scope was provided. Only alphanumeric characters, '.', '-', '_', ':', and '/' are allowed.Nanyr(   )r4   s    r    validate_scoper?   ^   s*     CGGGs
 	
 Hr"   	tenant_idc                 B    | rt        d | D              rt        d      y)zRaise ValueError if tenant_id is empty or contains a character invalid for a tenant ID.

    :param str tenant_id: tenant ID to validate
    :raises: ValueError if tenant_id is empty or contains a character invalid for a tenant ID.
    c              3   ,   K   | ]  }|t         v  y wr-   )VALID_TENANT_ID_CHARACTERSr8   s     r    r;   z%validate_tenant_id.<locals>.<genexpr>p   s     SAA%??Sr<   zInvalid tenant ID provided. You can locate your tenant ID by following the instructions here: https://learn.microsoft.com/partner-center/find-ids-and-domain-namesNr=   )r@   s    r    validate_tenant_idrD   j   s-     SSSS
 	
 Tr"   subscriptionc                 J    | rt        d | D              rt        d|  d      y)a  Raise ValueError if subscription is empty or contains a character invalid for a subscription name/ID.

    :param str subscription: subscription ID to validate
    :raises: ValueError if subscription is empty or contains a character invalid for a subscription ID.
    c              3   ,   K   | ]  }|t         v  y wr-   )VALID_SUBSCRIPTION_CHARACTERSr8   s     r    r;   z(validate_subscription.<locals>.<genexpr>}   s     \!q(EE\r<   zSubscription 'z' contains invalid characters. If this is the name of a subscription, use its ID instead. You can locate your subscription by following the instructions listed here: https://learn.microsoft.com/azure/azure-portal/get-subscription-tenant-idNr=   )rE   s    r    validate_subscriptionrI   w   s:     3\|\\\N +X X
 	
 ]r"   )additionally_allowed_tenantsdefault_tenantrJ   c                D   ||| k(  r| S | dk(  s-t         j                  j                  t        j                        rt
        j                  d| |       | S | s|S |g }d|v s||v rt
        j                  d| |       |S |s| dk(  r|S t        dj                  |            )a  Returns the correct tenant for a token request given a credential's configuration.

    :param str default_tenant: The tenant ID configured on the credential.
    :param str tenant_id: The tenant ID requested by the user.
    :keyword list[str] additionally_allowed_tenants: The list of additionally allowed tenants.
    :return: The tenant ID to use for the token request.
    :rtype: str
    :raises: ~azure.core.exceptions.ClientAuthenticationError
    adfszA token was request for a different tenant than was configured on the credential, but the configured value was used since multi tenant authentication has been disabled. Configured tenant ID: %s, Requested tenant ID %s*zA token was requested for a different tenant than was configured on the credential, and the requested tenant ID was used to authenticate. Configured tenant ID: %s, Requested tenant ID %sorganizationsa  The current credential is not configured to acquire tokens for tenant {}. To enable acquiring tokens for this tenant add it to the additionally_allowed_tenants when creating the credential, or add "*" to additionally_allowed_tenants to allow acquiring tokens for any tenant.)message)	r.   r/   r0   r   &AZURE_IDENTITY_DISABLE_MULTITENANTAUTH_LOGGERinfor
   r)   )rK   r@   rJ   _s       r    resolve_tenantrU      s      I72::>>2F2m2m#n? 	
 #+')$
**i;W.W% 	
  (No,M
#+ ,26)+<	 r"   credential_configexclude_flagsuser_excludesc           
         t         j                  j                  t        j                  d      j                         j                         }|dk(  rh d}| D ]	  }||v||<    n|dk(  rh d}| D ]	  }||v||<    n|r| j                         D ch c]  }d|v s|d    }}||vrBddgt        |      z   }	t        dt        j                   d| d	d
j                  |	       d      d}
| j                         D ]  \  }}|j                  d      |k(  s|}
 n | D ]
  }||
k7  ||<    |j                         D ]  \  }}|	|||<    |S c c}w )a  Process credential exclusions based on environment variable and user overrides.

    This method handles the AZURE_TOKEN_CREDENTIALS environment variable to determine
    which credentials should be excluded from the credential chain, and then applies
    any user-provided exclude overrides which take precedence over environment settings.

    :param credential_config: Configuration mapping for all available credentials, containing
        exclude parameter names, environment names, and default exclude settings
    :type credential_config: dict
    :param exclude_flags: Dictionary of exclude flags for each credential (will be modified)
    :type exclude_flags: dict
    :param user_excludes: User-provided exclude overrides from constructor kwargs
    :type user_excludes: dict

    :return: Dictionary of final exclude flags for each credential
    :rtype: dict

    :raises ValueError: If token_credentials_env contains an invalid credential name
     dev>   clibroker
powershelldeveloper_clishared_token_cachevisual_studio_codeprod>   environmentmanaged_identityworkload_identityenv_namezInvalid value for z: z. Valid values are: z, .N)r.   r/   r0   r   AZURE_TOKEN_CREDENTIALSstriplowervaluessortedr(   joinitems)rV   rW   rX   token_credentials_envdev_credentialscred_keyprod_credentialsconfigvalid_credentialsvalid_valuesselected_cred_key
user_values               r    process_credential_exclusionsrx      s   * JJNN+?+W+WY[\bbdjjl%v) 	FH&.o&EM(#	F	&	(S) 	GH&.6F&FM(#	G	>O>V>V>XqF\fjp\pVJ/qq (99!6?V4E-FFL$%9%Q%Q$RRTUjTk l%%)YY|%<$=Q@  ! 1 7 7 9 	Hfzz*%)>>$,!	
 * 	DH&.2C&CM(#	D !. 3 3 5 1*!&0M(#1 1 rs   	EEc                  2    	 ddl m}  | S # t        $ r Y yw xY w)zReturn the InteractiveBrowserBrokerCredential class if available, otherwise None.

    :return: InteractiveBrowserBrokerCredential class or None
    :rtype: Optional[type]
    r   "InteractiveBrowserBrokerCredentialN)azure.identity.brokerr{   ImportErrorrz   s    r    get_broker_credentialr~      s"    L11 s   
 	c                      t        j                         } t        | d| d         j                         }t        | d| d         j                         }|dk(  xr d|v S )Nsystemr   releaser   linux	microsoft)platformunamegetattrrj   )r   platform_namer   s      r    is_wslr     sY    NNEE8U1X6<<>MeYa1779GG#>w(>>r"   sc                 l    t        j                  | j                  d            }|j                  d      S )Nzutf-8)base64	b64encodeencodedecode)r   encodeds     r    encode_base64r     s*    qxx01G>>'""r"   r-   )3r   r.   r   loggingr   contextvarsr   stringr   r   typingr   r   urllib.parser   azure.core.credentialsr	   azure.core.exceptionsr
   
_constantsr   r   r   r   _enumsr   r   r   	getLogger__name__rR   	frozensetrC   r7   rH   r   r!   strr+   r3   r?   rD   rI   rU   dictrx   typer~   boolr   r    r"   r    <module>r      s  
  	    " ( ! ! 2 ;  ($%>N e4

'

H
%&}v'='DE "=6#9G#CD  )-&*@6*I J )h7 )C )Tf )B"3 "3 "(*s *
	
# 	
$ 	


# 

$ 


 
 
   $2 9=	22}2 #+49"5	2 	2j;T ;$ ;_c ;hl ;|x~ ? ?#S #S #r"   