
    YHh                        d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ  e	d      Z ee      Z e
e e             Z G d dee         Z G d	 d
ee         Zy)    )annotationsN)	getLogger)AnyCallableGenericTypeVarcast)warn_Oc                     e Zd ZdZeddd f	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zedd       Zedd       Z	edd	       Z
e
j                  dd
       Z
e
j                  dd       Z
ddZddZddZddZddZddZddZy)OptionzHAn option that can be set using an environment variable of the same nameTNc                "    t        t        |       S N)r	   r   )xs    H/var/www/html/planif/env/lib/python3.12/site-packages/reactpy/_option.py<lambda>zOption.<lambda>   s    4A;     c                   || _         || _        || _        g | _        |t        j
                  v r |t        j
                  |         | _        |P|j                  r| j                  st        d      |j                  | _
        |j                  | j                         n|t        ur|| _
        nt        d      t        j                  | j                    d| j                           y )Nz(Parent and child options must be mutablez0Must specify either a default or a parent option=)_name_mutable
_validator_subscribersosenviron_currentmutable	TypeErrordefault_default	subscribeset_current	UNDEFINEDloggerdebugcurrent)selfnamer   r   parent	validators         r   __init__zOption.__init__   s     
#8:2::%bjj&67DMNNt|| JKK"NNDMT--.I%#DMNOO

|1T\\N34r   c                    | j                   S )z<The name of this option (used to load environment variables))r   r'   s    r   r(   zOption.name-   s     zzr   c                    | j                   S )z6Whether this option can be modified after being loaded)r   r-   s    r   r   zOption.mutable2        }}r   c                    | j                   S )zThis option's default value)r    r-   s    r   r   zOption.default7   r/   r   c                R    	 | j                   S # t        $ r | j                  cY S w xY wr   )r   AttributeErrorr    r-   s    r   r&   zOption.current<   s*    	!==  	!== 	!s    &&c                &    | j                  |       y r   )r"   r'   news     r   r&   zOption.currentC   s    r   c                $    | j                          y r   )unsetr-   s    r   r&   zOption.currentG   s    

r   c                    | j                   sd}t        |      | j                  j                  |        || j                         |S )zCRegister a callback that will be triggered when this option changesz*Immutable options cannot be subscribed to.)r   r   r   appendr&   )r'   handlermsgs      r   r!   zOption.subscribeK   s=    ||>CC.   )r   c                    t        | d      S )z7Whether this option has a value other than its default.r   )hasattrr-   s    r   is_setzOption.is_setT   s    tZ((r   c                   | j                   }||u ry| j                  s|  d}t        |      	 | j                  |      x}| _        t        j                  | j                   d| j                          ||k7  r| j                  D ]
  } ||        yy# t
        $ r!}t        d| j                   d|      |d}~ww xY w)zsSet the value of this option

        Raises a ``TypeError`` if this option is not :attr:`Option.mutable`.
        N& cannot be modified after initial loadzInvalid value for z: r   )
r&   r   r   r   r   
ValueErrorr   r$   r%   r   )r'   r5   oldr;   errorsub_funcs         r   r"   zOption.set_currentX   s    
 ll#:}}F@ACC. 	T"&//#"66C$- 	

|1T]]O45#: --  	  	T1$**RwGHeS	Ts   B 	B?B::B?c                \    | j                         s| j                  |       | j                  S )zSet the value of this option if not :meth:`Option.is_set`

        Returns the current value (a la :meth:`dict.set_default`)
        )r>   r"   r   r4   s     r   set_defaultzOption.set_defaulto   s%    
 {{}S!}}r   c                    | j                  t        j                  j                  | j                  | j
                               y)z0Reload this option from its environment variableN)r"   r   r   getr   r    r-   s    r   reloadzOption.reloadx   s'    

DMMBCr   c                    | j                   s|  d}t        |      | j                  }t        | d      rt	        | d       | j                  |k7  r$| j
                  D ]  } || j                          yy)zIRemove the current value, the default will be used until it is set again.r@   r   N)r   r   r&   r=   delattrr   )r'   r;   rB   rD   s       r   r7   zOption.unset|   so    }}F@ACC. ll4$D*%<<3 -- '&' r   c                <    d| j                    d| j                  dS )NzOption(r   ))r   r&   r-   s    r   __repr__zOption.__repr__   s     Adll%5Q77r   )r(   strr   r   r   boolr)   zOption[_O] | Noner*   zCallable[[Any], _O]returnNone)rQ   rO   )rQ   rP   rQ   r   )r5   r   rQ   rR   )rQ   rR   )r:   Callable[[_O], None]rQ   rT   )r5   r   rQ   rR   )r5   r   rQ   r   )__name__
__module____qualname____doc__r#   r+   propertyr(   r   r   r&   setterdeleterr!   r>   r"   rF   rI   r7   rN    r   r   r   r      s    R
  $()>55 5 	5
 "5 '5 
58       ! ! ^^  __ ).D
'8r   r   c                  b     e Zd ZdZd fdZej                  j                  d fd       Z xZS )DeprecatedOptionz,An option that will warn when it is accessedc               2    t        |   |i | || _        y r   )superr+   _deprecation_message)r'   messageargskwargs	__class__s       r   r+   zDeprecatedOption.__init__   s    $)&)$+!r   c                p    	 | j                   }t        |t               t        |   S # t        $ r Y w xY wr   )ra   r
   DeprecationWarningr2   r`   r&   )r'   r;   re   s     r   r&   zDeprecatedOption.current   s@    		*
 ++C ()w	  		s   ) 	55)rc   r   rb   rO   rd   r   rQ   rR   rS   )	rU   rV   rW   rX   r+   r   r&   getter__classcell__)re   s   @r   r^   r^      s)    6, ^^ r   r^   )
__future__r   r   loggingr   typingr   r   r   r   r	   reactpy._warningsr
   r   rU   r$   objectr#   r   r^   r\   r   r   <module>ro      s[    " 	  8 8 "T]	8	fh	{8WR[ {8|vbz r   