
    ]h	F                       U d Z ddlmZ ddlmZ ddlmZ ddlZddlZddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZ ddlmZ erdd	lmZ  ed
      Z ed      ZdZ G d de      Zej<                  ZddZ d dZ!ejD                  ejF                  ejH                  ejJ                  ejL                  dZ'd!dZ(d"dZ)d#dZ*d#dZ+e*e+dZ,de-d<   d$dZ. G d deeef         Z/ G d d      Z0 e0       Z1de-d<   y)%zIProvide access to settings for globally used Azure configuration values.
    )annotations)
namedtuple)EnumN)TypeOptionalCallableUnionDictAnyTypeVarTupleGenericMappingListTYPE_CHECKING   )AzureClouds)AbstractSpanValidInputType	ValueType)settingsSettingsc                      e Zd ZdZy)_Unsetr   N)__name__
__module____qualname__token     Y/var/www/core.comfia.cic-ware.com/crm/lib/python3.12/site-packages/azure/core/settings.pyr   r   <   s    Er    r   c                    t        | t              r| S | j                         }|dv ry|dv ryt        dj	                  |             )a  Convert a string to True or False

    If a boolean is passed in, it is returned as-is. Otherwise the function
    maps the following strings, ignoring case:

    * "yes", "1", "on" -> True
    " "no", "0", "off" -> False

    :param value: the value to convert
    :type value: str or bool
    :returns: A boolean value matching the intent of the input
    :rtype: bool
    :raises ValueError: If conversion to bool fails

    )yes1ontrueTrueT)no0offfalseFalseFz"Cannot convert {} to boolean value)
isinstanceboollower
ValueErrorformat)valuevals     r!   convert_boolr4   C   sM      %
++-C
00
22
9@@G
HHr    c                H    | t         j                         ryyt        |       S )a  Convert tracing value to bool with regard to tracing implementation.

    :param value: the value to convert
    :type value: str or bool or None
    :returns: A boolean value matching the intent of the input
    :rtype: bool
    :raises ValueError: If conversion to bool fails
    TF)r   tracing_implementationr4   )r2   s    r!   convert_tracing_enabledr7   ]   s(     } **,r    )CRITICALERRORWARNINGINFODEBUGc                    t        | t              r| S | j                         }t        j	                  |      }|s.t        dj                  | dj                  t                          |S )a  Convert a string to a Python logging level

    If a log level is passed in, it is returned as-is. Otherwise the function
    understands the following strings, ignoring case:

    * "critical"
    * "error"
    * "warning"
    * "info"
    * "debug"

    :param value: the value to convert
    :type value: str or int
    :returns: A log level as an int. See the logging module for details.
    :rtype: int
    :raises ValueError: If conversion to log level fails

    z4Cannot convert {} to log level, valid values are: {}, )r-   intupper_levelsgetr0   r1   join)r2   r3   levels      r!   convert_loggingrE   x   s]    & % 
++-CKKEOVVW\^b^g^gho^pqrrLr    c           	     B   t        | t              r| S t        | t              r_t        D ci c]  }|j                  | }}| |v r||    S t	        dj                  | dj                  |j                                           t	        dj                  |             c c}w )zConvert a string to an Azure Cloud

    :param value: the value to convert
    :type value: string
    :returns: An AzureClouds enum value
    :rtype: AzureClouds
    :raises ValueError: If conversion to AzureClouds fails

    z6Cannot convert {} to Azure Cloud, valid values are: {}r>   z Cannot convert {} to Azure Cloud)r-   r   strnamer0   r1   rC   keys)r2   cloudazure_cloudss      r!   convert_azure_cloudrL      s     %%%7BCe

E)CCL &&DKKESWS\S\]i]n]n]pSqr
 	
 7>>uE
FF Ds   Bc                 2    	 ddl m}  | S # t        $ r Y yw xY w)zReturns the OpenCensusSpan if the opencensus tracing plugin is installed else returns None.

    :rtype: type[AbstractSpan] or None
    :returns: OpenCensusSpan type or None
    r   OpenCensusSpanN)&azure.core.tracing.ext.opencensus_spanrO   ImportErrorrN   s    r!   _get_opencensus_spanrR      s&    	
     
 	c                 2    	 ddl m}  | S # t        $ r Y yw xY w)zReturns the OpenTelemetrySpan if the opentelemetry tracing plugin is installed else returns None.

    :rtype: type[AbstractSpan] or None
    :returns: OpenTelemetrySpan type or None
    r   OpenTelemetrySpanN))azure.core.tracing.ext.opentelemetry_spanrV   rQ   rU   s    r!   _get_opentelemetry_spanrX      s&    	
 !  rS   )
opencensusopentelemetryz5Dict[str, Callable[[], Optional[Type[AbstractSpan]]]]_tracing_implementation_dictc                    | yt        | t              s| S | j                         } t        j	                  | d       } |       }|t
        u r.t        dj                  | dj                  t                          |S )ao  Convert a string to AbstractSpan

    If a AbstractSpan is passed in, it is returned as-is. Otherwise the function
    understands the following strings, ignoring case:

    * "opencensus"
    * "opentelemetry"

    :param value: the value to convert
    :type value: string
    :returns: AbstractSpan
    :raises ValueError: If conversion to AbstractSpan fails

    Nc                     t         S N)_unsetr   r    r!   <lambda>z&convert_tracing_impl.<locals>.<lambda>   s     r    z7Cannot convert {} to AbstractSpan, valid values are: {}r>   )	r-   rG   r/   r[   rB   r_   r0   r1   rC   )r2   get_wrapper_classwrapper_classs      r!   convert_tracing_implrc      s{     }eS!KKME488OARATMELLtyy!=>
 	

 r    c                      e Zd ZdZddedf	 	 	 	 	 	 	 	 	 ddZddZdddZdddZddZ	ddZ
dd	Zedd
       Zedd       Zy)PrioritizedSettinga  Return a value for a global setting according to configuration precedence.

    The following methods are searched in order for the setting:

    4. immediate values
    3. previously user-set value
    2. environment variable
    1. system setting
    0. implicit default

    If a value cannot be determined, a RuntimeError is raised.

    The ``env_var`` argument specifies the name of an environment to check for
    setting values, e.g. ``"AZURE_LOG_LEVEL"``.
    If a ``convert`` function is provided, the result will be converted before being used.

    The optional ``system_hook`` can be used to specify a function that will
    attempt to look up a value for the setting from system-wide configurations.
    If a ``convert`` function is provided, the hook result will be converted before being used.

    The optional ``default`` argument specified an implicit default value for
    the setting that is returned if no other methods provide a value. If a ``convert`` function is provided,
    ``default`` will be converted before being used.

    A ``convert`` argument may be provided to convert values before they are
    returned. For instance to concert log levels in environment variables
    to ``logging`` module values. If a ``convert`` function is provided, it must support
    str as valid input type.

    :param str name: the name of the setting
    :param str env_var: the name of an environment variable to check for the setting
    :param callable system_hook: a function that will attempt to look up a value for the setting
    :param default: an implicit default value for the setting
    :type default: any
    :param callable convert: a function to convert values before they are returned
    Nc                n    || _         || _        || _        || _        d }|r|n|| _        t
        | _        y )Nc                    | S r^   r   )xs    r!   r`   z-PrioritizedSetting.__init__.<locals>.<lambda>&  s    q r    )_name_env_var_system_hook_default_convertr_   _user_value)selfrH   env_varsystem_hookdefaultconvertnoop_converts          r!   __init__zPrioritizedSetting.__init__  s:     
'-8V]7co:@r    c                     d| j                   z  S )NzPrioritizedSetting(%r))ri   ro   s    r!   __repr__zPrioritizedSetting.__repr__*  s    '$**44r    c                *   || j                  |      S t        | j                  t              s| j                  | j                        S | j                  rH| j                  t
        j                  v r,| j                  t
        j                  | j                           S | j                  r| j                  | j                               S t        | j                  t              s| j                  | j                        S t        d| j                  z        )a   Return the setting value according to the standard precedence.

        :param value: value
        :type value: str or int or float or None
        :returns: the value of the setting
        :rtype: str or int or float
        :raises RuntimeError: if no value can be determined
        z(No configured value found for setting %r)rm   r-   rn   r   rj   osenvironrk   rl   RuntimeErrorri   ro   r2   s     r!   __call__zPrioritizedSetting.__call__-  s     =='' $**F3==!1!122 ==T]]bjj8==DMM!:;; ==!2!2!455 $--0==//E

RSSr    c                    | S r^   r   )ro   instanceowners      r!   __get__zPrioritizedSetting.__get__M  s    r    c                &    | j                  |       y r^   )	set_value)ro   r   r2   s      r!   __set__zPrioritizedSetting.__set__P  s    ur    c                    || _         y)a  Specify a value for this setting programmatically.

        A value set this way takes precedence over all other methods except
        immediate values.

        :param value: a user-set value for this setting
        :type value: str or int or float
        N)rn   r}   s     r!   r   zPrioritizedSetting.set_valueS  s     !r    c                    t         | _        y)z>Unset the previous user value such that the priority is reset.N)r_   rn   rw   s    r!   unset_valuezPrioritizedSetting.unset_value^  s
    !r    c                    | j                   S r^   )rj   rw   s    r!   rp   zPrioritizedSetting.env_varb      }}r    c                    | j                   S r^   )rl   rw   s    r!   rr   zPrioritizedSetting.defaultf  r   r    )
rH   rG   rp   Optional[str]rq   z&Optional[Callable[[], ValidInputType]]rr   Union[ValidInputType, _Unset]rs   z;Optional[Callable[[Union[ValidInputType, str]], ValueType]])returnrG   r^   )r2   zOptional[ValidInputType]r   r   )r   r   r   zOptional[Any]r   z-PrioritizedSetting[ValidInputType, ValueType])r   r   r2   r   r   None)r2   r   r   r   r   r   )r   r   )r   r   )r   r   r   __doc__r_   ru   rx   r~   r   r   r   r   propertyrp   rr   r   r    r!   re   re      s    #P "&>B17OSAA A <	A
 /A MA"5T@	!"    r    re   c                  6   e Zd ZU dZddZedd       Zej                  dd       Zedd       Zedd       Z	ddZ
ddZ ed	d
eej                        Zded	<    edded      Zded<    edded      Zded<    eddeej0                        Zded<   y)r   a]
  Settings for globally used Azure configuration values.

    You probably don't want to create an instance of this class, but call the singleton instance:

    .. code-block:: python

        from azure.core.settings import settings
        settings.log_level = log_level = logging.DEBUG

    The following methods are searched in order for a setting:

    4. immediate values
    3. previously user-set value
    2. environment variable
    1. system setting
    0. implicit default

    An implicit default is (optionally) defined by the setting attribute itself.

    A system setting value can be obtained from registries or other OS configuration
    for settings that support that method.

    An environment variable value is obtained from ``os.environ``

    User-set values many be specified by assigning to the attribute:

    .. code-block:: python

        settings.log_level = log_level = logging.DEBUG

    Immediate values are (optionally) provided when the setting is retrieved:

    .. code-block:: python

        settings.log_level(logging.DEBUG())

    Immediate values are most often useful to provide from optional arguments
    to client functions. If the argument value is not None, it will be returned
    as-is. Otherwise, the setting searches other methods according to the
    precedence rules.

    Immutable configuration snapshots can be created with the following methods:

    * settings.defaults returns the base defaultsvalues , ignoring any environment or system
      or user settings

    * settings.current returns the current computation of settings including prioritization
      of configuration sources, unless defaults_only is set to True (in which case the result
      is identical to settings.defaults)

    * settings.config can be called with specific values to override what settings.current
      would provide

    .. code-block:: python

        # return current settings with log level overridden
        settings.config(log_level=logging.DEBUG)

    :cvar log_level: a log level to use across all Azure client SDKs (AZURE_LOG_LEVEL)
    :type log_level: PrioritizedSetting
    :cvar tracing_enabled: Whether tracing should be enabled across Azure SDKs (AZURE_TRACING_ENABLED)
    :type tracing_enabled: PrioritizedSetting
    :cvar tracing_implementation: The tracing implementation to use (AZURE_SDK_TRACING_IMPLEMENTATION)
    :type tracing_implementation: PrioritizedSetting

    :Example:

    >>> import logging
    >>> from azure.core.settings import settings
    >>> settings.log_level = logging.DEBUG
    >>> settings.log_level()
    10

    >>> settings.log_level(logging.WARN)
    30

    c                    d| _         y )NF_defaults_onlyrw   s    r!   ru   zSettings.__init__  s
    $)r    c                    | j                   S )zWhether to ignore environment and system settings and return only base default values.

        :rtype: bool
        :returns: Whether to ignore environment and system settings and return only base default values.
        r   rw   s    r!   defaults_onlyzSettings.defaults_only  s     """r    c                    || _         y r^   r   r}   s     r!   r   zSettings.defaults_only  s
    #r    c                    | j                   j                  j                         D ci c]#  \  }}t        |t              s||j
                  % }}}| j                  |      S c c}}w )zReturn implicit default values for all settings, ignoring environment and system.

        :rtype: namedtuple
        :returns: The implicit default values for all settings
        )	__class____dict__itemsr-   re   rr   _config)ro   kvpropss       r!   defaultszSettings.defaults  sV     -1NN,C,C,I,I,Kq&1azZ[]oOpAIIqq||E"" rs   A$A$c                R    | j                   r| j                  S | j                         S )zReturn the current values for all settings.

        :rtype: namedtuple
        :returns: The current values for all settings
        )r   r   configrw   s    r!   currentzSettings.current  s#     == {{}r    c                    | j                   j                  j                         D ci c]  \  }}t        |t              s| |         }}}|j                  |       | j                  |      S c c}}w )a  Return the currently computed settings, with values overridden by parameter values.

        :rtype: namedtuple
        :returns: The current values for all settings, with values overridden by parameter values

        Examples:

        .. code-block:: python

           # return current settings with log level overridden
           settings.config(log_level=logging.DEBUG)

        )r   r   r   r-   re   updater   )ro   kwargsr   r   r   s        r!   r   zSettings.config  s`     '+nn&=&=&C&C&EkFQTUWiIjACkkV||E"" ls   A0
A0c                \    t        |j                               }t        d|      } |di |S )NConfigr   )listrI   r   )ro   r   rI   r   s       r!   r   zSettings._config  s*    uzz|,Hd+r    	log_levelAZURE_LOG_LEVEL)rp   rs   rr   z(PrioritizedSetting[Union[str, int], int]tracing_enabledAZURE_TRACING_ENABLEDNz4PrioritizedSetting[Optional[Union[str, bool]], bool]r6    AZURE_SDK_TRACING_IMPLEMENTATIONzZPrioritizedSetting[Optional[Union[str, Type[AbstractSpan]]], Optional[Type[AbstractSpan]]]azure_cloudAZURE_CLOUDz8PrioritizedSetting[Union[str, AzureClouds], AzureClouds]r   )r   r.   )r2   r.   r   r   )r   Tuple[Any, ...])r   r   r   r   )r   zMapping[str, Any]r   r   )r   r   r   r   ru   r   r   setterr   r   r   r   re   rE   loggingr;   r   __annotations__r7   r   rc   r6   rL   r   AZURE_PUBLIC_CLOUDr   r   r    r!   r   r   k  s   L\* # # $ $ # #  #$ ;M!	;I7  M_''	MOI  	 2$		    M_#..	MKI r    r   r   )r2   zUnion[str, bool]r   r.   )r2   zOptional[Union[str, bool]]r   r.   )r2   zUnion[str, int]r   r?   )r2   zUnion[str, AzureClouds]r   r   )r   Optional[Type[AbstractSpan]])r2   z(Optional[Union[str, Type[AbstractSpan]]]r   r   )2r   
__future__r   collectionsr   enumr   r   rz   typingr   r   r   r	   r
   r   r   r   r   r   r   r   _azure_cloudsr   azure.core.tracingr   r   r   __all__r   r   r_   r4   r7   r8   r9   r:   r;   r<   rA   rE   rL   rR   rX   r[   r   rc   re   r   r   r   r    r!   <module>r      s  4 " "   	    '/)*K 	 #T  
I4&   ]]LL]]<G, " ',W S Bu!:; uph hV Z( r    