
    h9E                       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	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 ddlmZ dd	lmZ  ed
      Z ed      ZdZ G d de      Zej<                  Zd dZ ejB                  ejD                  ejF                  ejH                  ejJ                  dZ&d!dZ'd"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         Z0 G d d      Z1 e1       Z2d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)AbstractSpan   )AzureCloudsValidInputType	ValueType)settingsSettingsc                      e Zd ZdZy)_Unsetr   N)__name__
__module____qualname__token     M/var/www/html/engine/venv/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_boolr3   A   sM      %
++-C
00
22
9@@G
HHr   )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getr/   r0   join)r1   r2   levels      r    convert_loggingrA   d   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namer/   r0   r?   keys)r1   cloudazure_cloudss      r    convert_azure_cloudrH      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_spanrK   ImportErrorrJ   s    r    _get_opencensus_spanrN      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_spanrR   rM   rQ   s    r    _get_opentelemetry_spanrT      s&    	
 !  rO   c                 <    dt         j                  vry t               S )N
opencensus)sysmodulesrN   r   r   r    ._get_opencensus_span_if_opencensus_is_importedrY      s    3;;&!!r   c                 <    dt         j                  vry t               S )Nopentelemetry)rW   rX   rT   r   r   r    4_get_opentelemetry_span_if_opentelemetry_is_importedr\      s    ckk)"$$r   )rV   r[   z5Dict[str, Callable[[], Optional[Type[AbstractSpan]]]]_tracing_implementation_dictc                "   | t               xs
 t               S 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

    c                     t         S N)_unsetr   r   r    <lambda>z&convert_tracing_impl.<locals>.<lambda>   s     r   z7Cannot convert {} to AbstractSpan, valid values are: {}r:   )r\   rY   r,   rC   r.   r]   r>   ra   r/   r0   r?   )r1   get_wrapper_classwrapper_classs      r    convert_tracing_implre      s     }@BvFtFv	
 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    rb   z-PrioritizedSetting.__init__.<locals>.<lambda>   s    q r   )_name_env_var_system_hook_default_convertra   _user_value)selfrD   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))rk   rq   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)ro   r,   rp   r   rl   osenvironrm   rn   RuntimeErrorrk   rq   r1   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   )rq   instanceowners      r    __get__zPrioritizedSetting.__get__G  s    r   c                &    | j                  |       y r`   )	set_value)rq   r   r1   s      r    __set__zPrioritizedSetting.__set__J  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)rp   r   s     r    r   zPrioritizedSetting.set_valueM  s     !r   c                    t         | _        y)z>Unset the previous user value such that the priority is reset.N)ra   rp   ry   s    r    unset_valuezPrioritizedSetting.unset_valueX  s
    !r   c                    | j                   S r`   )rl   ry   s    r    rr   zPrioritizedSetting.env_var\      }}r   c                    | j                   S r`   )rn   ry   s    r    rt   zPrioritizedSetting.default`  r   r   )
rD   rC   rr   Optional[str]rs   z&Optional[Callable[[], ValidInputType]]rt   Union[ValidInputType, _Unset]ru   z;Optional[Callable[[Union[ValidInputType, str]], ValueType]])returnrC   r`   )r1   zOptional[ValidInputType]r   r   )r   r   r   zOptional[Any]r   z-PrioritizedSetting[ValidInputType, ValueType])r   r   r1   r   r   None)r1   r   r   r   r   r   )r   r   )r   r   )r   r   r   __doc__ra   rw   rz   r   r   r   r   r   propertyrr   rt   r   r   r    rg   rg      s    #P "&>B17OSAA A <	A
 /A MA"5T@	!"    r   rg   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_onlyry   s    r    rw   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   ry   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,   rg   rt   _config)rq   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   configry   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,   rg   updater   )rq   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   )listrE   r   )rq   r   rE   r   s       r    r   zSettings._config  s*    uzz|,Hd+r   	log_levelAZURE_LOG_LEVEL)rr   ru   rt   z(PrioritizedSetting[Union[str, int], int]tracing_enabledAZURE_TRACING_ENABLEDFz*PrioritizedSetting[Union[str, bool], bool]tracing_implementation AZURE_SDK_TRACING_IMPLEMENTATIONNzZPrioritizedSetting[Optional[Union[str, Type[AbstractSpan]]], Optional[Type[AbstractSpan]]]azure_cloudAZURE_CLOUDz8PrioritizedSetting[Union[str, AzureClouds], AzureClouds]r   )r   r-   )r1   r-   r   r   )r   Tuple[Any, ...])r   r   r   r   )r   zMapping[str, Any]r   r   )r   r   r   r   rw   r   r   setterr   r   r   r   rg   rA   loggingr7   r   __annotations__r3   r   re   r   rH   r   AZURE_PUBLIC_CLOUDr   r   r   r    r   r   e  s   L\* # # $ $ # #  #$ ;M!	;I7  CU'	CO?  	 2$		    M_#..	MKI r   r   r   )r1   zUnion[str, bool]r   r-   )r1   zUnion[str, int]r   r;   )r1   zUnion[str, AzureClouds]r   r   )r   Optional[Type[AbstractSpan]])r1   z(Optional[Union[str, Type[AbstractSpan]]]r   r   )3r   
__future__r   collectionsr   enumr   r   r|   rW   typingr   r   r   r	   r
   r   r   r   r   r   r   azure.core.tracingr   _azure_cloudsr   r   r   __all__r   r   ra   r3   r4   r5   r6   r7   r8   r=   rA   rH   rN   rT   rY   r\   r]   r   re   rg   r   r   r   r   r    <module>r      s  4 " "   	 
    , &)*K 	 #T  
I6   ]]LL]]<G,  "% ',W S  Fu!:; uph hV Z( r   