
    ɯei6                     p   d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZmZ erddlmZ  G d d      Z G d	 d
e      Z G d de      Ze ed d d d      e ed d d d      e ed ed d      e ed ed d      e ed d d d      iZ e       Z G d  d!e      Z G d" d#      Zd#gZy)$z?Module houses ``Parameter`` class - base class for all configs.    N)defaultdict)IntEnum)TYPE_CHECKINGAnyCallableDefaultDict
NamedTupleOptionalcast)EnvironmentVariablec                       e Zd ZU dZed   ed<   eed      ed<   eed<   	 	 dded   deed      d	ee   fd
Zdde	defdZ
y)DeprecationDescriptora  
    Describe deprecated parameter.

    Parameters
    ----------
    parameter : type[Parameter]
        Deprecated parameter.
    new_parameter : type[Parameter], optional
        If there's a replacement parameter for the deprecated one, specify it here.
    when_removed : str, optional
        If known, the exact release when the deprecated parameter is planned to be removed.
    	Parameter
_parameter_new_parameter_when_removedN	parameternew_parameterwhen_removedc                 B    || _         || _        |d| _        y || _        y )Nza future)r   r   r   )selfr   r   r   s       h/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/snowflake/snowpark/modin/config/pubsub.py__init__zDeprecationDescriptor.__init__/   s'     $++7+?Z\    use_envvar_namesreturnc                 6   |r t        d| j                        j                  n| j                  j                  }d| d| j                   d}| j
                  A|r t        d| j
                        j                  n| j
                  j                  }|d| dz  }|S )a  
        Generate a message to be used in a warning raised when using the deprecated parameter.

        Parameters
        ----------
        use_envvar_names : bool, default: False
            Whether to use environment variable names in the warning. If ``True``, both
            ``self._parameter`` and ``self._new_parameter`` have to be a type of ``EnvironmentVariable``.

        Returns
        -------
        str
        r   'z'' is deprecated and will be removed in z	 version.z Use 'z
' instead.)r   r   varname__name__r   r   )r   r   namemsgnew_names        r   deprecation_messagez)DeprecationDescriptor.deprecation_message9   s        &8@@)) 	
 $>t?Q?Q>RR[\* $ *D,?,?@HH((11 
 VH:Z00C
r   )NNF)r    
__module____qualname____doc__type__annotations__r
   strr   boolr$    r   r   r   r      s}     [!!T+.//
 6:&*	R$R  [ 12R sm	RD S r   r   c                   ^    e Zd ZU dZeegef   ed<   eegef   ed<   eegef   ed<   eed<   y)TypeDescriptora  
    Class for config data manipulating of exact type.

    Parameters
    ----------
    decode : callable
        Callable to decode config value from the raw data.
    normalize : callable
        Callable to bring different config value variations to
        the single form.
    verify : callable
        Callable to check that config value satisfies given config
        type requirements.
    help : str
        Class description string.
    decode	normalizeverifyhelpN)	r    r&   r'   r(   r   r+   objectr*   r,   r-   r   r   r/   r/   W   sB    " cUF]##&())fXt^$$
Ir   r/   c                       e Zd ZdZy)ExactStrzDClass to be used in type params where no transformations are needed.N)r    r&   r'   r(   r-   r   r   r6   r6   o   s    Nr   r6   c                 >    | j                         j                         S N)striptitlevalues    r   <lambda>r=   u   s    U[[]002 r   c                 P    t        |       j                         j                         S r8   )r+   r9   r:   r;   s    r   r=   r=   v   s    E
 0 0 2 8 8 : r   c                      yNTr-   r;   s    r   r=   r=   w       r   za case-insensitive string)r0   r1   r2   r3   c                     | S r8   r-   r;   s    r   r=   r=   {   s    U r   c                     | S r8   r-   r;   s    r   r=   r=   |   s     r   c                      yr@   r-   r;   s    r   r=   r=   }   rA   r   za stringc                 B    | j                         j                         dv S )N>   1yestrue)r9   lowerr;   s    r   r=   r=      s    U[[]0026JJ r   c                     t        | t              xs2 t        | t              xr  | j                         j	                         dv S )N>   0rF   norG   rH   false)
isinstancer,   r+   r9   rI   r;   s    r   r=   r=      s=    Zt4 
uc" R##%)QQ r   z^a boolean flag (any of 'true', 'yes' or '1' in case insensitive manner is considered positive)c                 4    t        | j                               S r8   )intr9   r;   s    r   r=   r=      s    S/ r   c                     t        | t              xs0 t        | t              xr | j                         j	                         S r8   )rN   rP   r+   r9   isdigitr;   s    r   r=   r=      s4    Zs3 @uc">u{{}'<'<'> r   zan integer valuec                    | j                  d      D ci c]R  }|j                  dd      D cg c]  }|j                          c}\  }}||j                         rt        |      n|T c}}}}S c c}w c c}}}}w N,=   )maxsplit)splitr9   rR   rP   r<   	key_valuekeyvalvs        r   r=   r=      so    "[[-
 
1:q1QRAaggiRS S[[]S3C
  S
s   A9
A4&A9
4A9
c                 8   t        | t              r| S t        |       j                  d      D ci c]R  }|j                  dd      D cg c]  }|j	                          c}\  }}||j                         rt        |      n|T c}}}}S c c}w c c}}}}w rT   )rN   dictr+   rY   r9   rR   rP   rZ   s        r   r=   r=      s    %&  
 "%U!1!1#!6 5>__SST_5U!V!'')!VHC SXC7  "Ws   B
B#&B
B
c                     t        | t              xs3 t        | t              xr! t        d | j	                  d      D              S )Nc              3   ^   K   | ]%  }|j                  d       dt        |      dz
  fv ' yw)rV   rW   N)findlen).0r[   s     r   	<genexpr>z<lambda>.<locals>.<genexpr>   s4       s#BI0B+CCs   +-rU   )rN   r`   r+   allrY   r;   s    r   r=   r=      sB    Zt4 
uc"  !&S!1  r   zba sequence of KEY=VALUE values separated by comma (Example: 'KEY1=VALUE1,KEY2=VALUE2,KEY3=VALUE3')c                       e Zd ZdZdZdZdZy)ValueSourcezEClass that describes the method of getting the value for a parameter.r   rW      N)r    r&   r'   r(   DEFAULTSET_BY_USERGOT_FROM_CFG_SOURCEr-   r   r   rj   rj      s    O GKr   rj   c                       e Zd ZU dZdZeeedf      ed<   eZ	dZ
ee   ed<   dZdZee   ed<   eZeed<   g Zeed	<    ee      Zeeef   ed
<   dZee   ed<   edefd       Zedefd       Zd!dededef fdZededdfd       Zedefd       Z edefd       Z!edefd       Z"ededdfd       Z#edededdfd       Z$ededefd       Z%ededdfd       Z&ededefd        Z' xZ(S )"r   a  
    Base class describing interface for configuration entities.

    Attributes
    ----------
    choices : Optional[Sequence[str]]
        Array with possible options of ``Parameter`` values.
    type : str
        String that denotes ``Parameter`` type.
    default : Optional[Any]
        ``Parameter`` default value.
    is_abstract : bool, default: True
        Whether or not ``Parameter`` is abstract.
    _value_source : Optional[ValueSource]
        Source of the ``Parameter`` value, should be set by
        ``ValueSource``.
    _deprecation_descriptor : Optional[DeprecationDescriptor]
        Indicate whether this parameter is deprecated.
    N.choicesdefaultT_value_source_value_subs_once_deprecation_descriptorr   c                     t               )au  
        Read the value from config storage.

        Returns
        -------
        str
            Config raw value.

        Raises
        ------
        KeyError
            If value is absent.

        Notes
        -----
        Config storage can be config file or environment variable or whatever.
        Method should be implemented in the child class.
        NotImplementedErrorclss    r   _get_raw_from_configzParameter._get_raw_from_config   s    ( "##r   c                     t               )z
        Generate user-presentable help for the option.

        Returns
        -------
        str

        Notes
        -----
        Method should be implemented in the child class.
        rx   rz   s    r   get_helpzParameter.get_help   s     "##r   r)   abstractkwc                     |t         v s
J d|        || _        || _        t        | _        g | _        t        t              | _        t        | (  di | y)a  
        Initialize subclass.

        Parameters
        ----------
        type : Any
            Type of the config.
        abstract : bool, default: False
            Whether config is abstract.
        **kw : dict
            Optional arguments for config initialization.
        zUnsupported variable type: Nr-   )_TYPE_PARAMSr)   is_abstract_UNSETrs   rt   r   listru   super__init_subclass__)r{   r)   r   r   	__class__s       r   r   zParameter.__init_subclass__   sX     |#I'B4&%II#"
	%	!'B'r   callbackc                 J    | j                   j                  |        ||        y)z
        Add `callback` to the `_subs` list and then execute it.

        Parameters
        ----------
        callback : callable
            Callable to execute.
        N)rt   append)r{   r   s     r   	subscribezParameter.subscribe  s     			"r   c                     | j                   S )z_
        Get default value of the config.

        Returns
        -------
        Any
        )rq   rz   s    r   _get_defaultzParameter._get_default"  s     {{r   c                 x    | j                   | j                          | j                   J d       | j                   S )zf
        Get value source of the config.

        Returns
        -------
        ValueSource
        z1_value_source must be initialized by now in get())rr   getrz   s    r   get_value_sourcezParameter.get_value_source-  sA     $GGI)	?>	?)   r   c                 T   | j                   2t        j                  | j                   j                         t               | j
                  t        u r	 | j                         }t        | j                     j                  |      st        d|       t        | j                     j                  |      | _        t        j                  | _        | j
                  S | j
                  S # t         $ r8 | j#                         | _        t        j$                  | _        Y | j
                  S w xY w)z
        Get config value.

        Returns
        -------
        Any
            Decoded and verified config value.
        zUnsupported raw value: )rv   warningswarnr$   FutureWarningrs   r   r|   r   r)   r2   
ValueErrorr0   rj   rn   rr   KeyErrorr   rl   )r{   raws     r   r   zParameter.get>  s     &&2MM++??A= ::	D..0
 $CHH-44S9$'>se%DEE)#((3::3?
$/$C$C!zzszz  8 --/
$/$7$7! zz8s   C& &3D'&D'r<   c                     | j                   2t        j                  | j                   j                         t               | j                  | j                  |             t        j                  | _	        y)z
        Set config value.

        Parameters
        ----------
        value : Any
            Config value to set.
        N)
rv   r   r   r$   r   _check_callbacks_put_nocallbackrj   rm   rr   )r{   r<   s     r   putzParameter.putZ  sY     &&2MM++??A= 	S0078'33r   onvaluec                     t         | j                     j                  |      }|| j                         k(  r	 ||        y| j                  |   j                  |       y)a  
        Execute `callback` if config value matches `onvalue` value.

        Otherwise accumulate callbacks associated with the given `onvalue`
        in the `_once` container.

        Parameters
        ----------
        onvalue : Any
            Config value to set.
        callback : callable
            Callable that should be executed if config value matches `onvalue`.
        N)r   r)   r1   r   ru   r   )r{   r   r   s      r   oncezParameter.oncek  sI     sxx(227;cggiSMIIg%%h/r   c                     t         | j                     j                  |      st        d|       t         | j                     j	                  |      }| j                         |c}| _        |S )z
        Set config value without executing callbacks.

        Parameters
        ----------
        value : Any
            Config value to set.

        Returns
        -------
        Any
            Replaced (old) config value.
        zUnsupported value: )r   r)   r2   r   r1   r   rs   )r{   r<   oldvalues      r   r   zParameter._put_nocallback  s`     CHH%,,U325':;;SXX&007"wwy%#*r   r   c                     || j                         k(  ry| j                  D ]
  } ||         | j                  j                  | j                         d      D ]
  } ||         y)z
        Execute all needed callbacks if config value was changed.

        Parameters
        ----------
        oldvalue : Any
            Previous (old) config value.
        Nr-   )r   rt   ru   pop)r{   r   r   s      r   r   zParameter._check_callbacks  sZ     swwy 		 	HSM			cggi4 	HSM	r   choicec                     | j                   xt        | j                     j                  |      st	        d|       t        | j                     j                  |      }|| j                   vr| xj                   |fz  c_         |S t        d      )a  
        Add a new choice for the parameter.

        Parameters
        ----------
        choice : Any
            New choice to add to the available choices.

        Returns
        -------
        Any
            Added choice normalized according to the parameter type.
        zUnsupported choice value: z8Cannot add a choice to a parameter where choices is None)rp   r   r)   r2   r   r1   	TypeError)r{   r   s     r   
add_optionzParameter.add_option  s~     ;;")008 #=fX!FGG!#((+55f=FS[[(y(MRSSr   r%   ))r    r&   r'   r(   rp   r
   tupler+   r*   r)   rq   r   r   rr   rj   r   rs   rt   r   r   ru   r   rv   r   classmethodr|   r~   r,   r`   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s   ( *.GXeCHo&-D!GXc]!K+/M8K(/FCE4$/$5E;sDy!5?CX&;<C$S $ $* $ $ $(S (D ( (* 
 
d 
 
 S   ! ! !  C  6 4 4 4 4  03 0( 0t 0 0( C C  (      T T T Tr   r   )r(   r   collectionsr   enumr   typingr   r   r   r   r	   r
   r   'snowflake.snowpark.modin.config.envvarsr   r   r/   r+   r6   r,   rP   r`   r   r4   r   rj   r   __all__r-   r   r   <module>r      s  $ F  #  X X XK7 7tZ 0Os O
 2:!(	
 n"%!	 	.J

 n	 /@
 	.



 r/=7v 
' @T @TF -r   