Ë
    ¹ÿj­„  ã                   óê  — d Z ddl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
 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 ddlZ ej(                  ej*                  ¬«        ej,                  e«      ZdZdZed	   Z G d
„ de«      Z G d„ de«      Z G d„ d«      Z G d„ d«      Z G d„ d«      Z  G d„ d«      Z! G d„ d«      Z"ddedeee#e#f      fd„Z$	 	 d dedeee#e#f      dee#   fd„Z% G d„ d«      Z&y)!zxFirebase Remote Config Module.
This module has required APIs for the clients to use Firebase Remote Config with python.
é    N)ÚDictÚOptionalÚLiteralÚUnionÚAny)ÚEnum)ÚAppÚ_http_clientÚ_utils)ÚlevelÚ_remoteconfigé
   )ÚdefaultÚremoteÚstaticc                   ó    — e Zd ZdZdZdZdZdZy)ÚPercentConditionOperatorzFEnum representing the available operators for percent conditions.
    ÚLESS_OR_EQUALÚGREATER_THANÚBETWEENÚUNKNOWNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   © ó    úV/root/telegram-saas/.venv/lib/python3.12/site-packages/firebase_admin/remote_config.pyr   r   '   s   „ ñà#€MØ!€LØ€GØ�Gr   r   c                   óT   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZy)ÚCustomSignalOperatorzLEnum representing the available operators for custom signal conditions.
    ÚSTRING_CONTAINSÚSTRING_DOES_NOT_CONTAINÚSTRING_EXACTLY_MATCHESÚSTRING_CONTAINS_REGEXÚNUMERIC_LESS_THANÚNUMERIC_LESS_EQUALÚNUMERIC_EQUALÚNUMERIC_NOT_EQUALÚNUMERIC_GREATER_THANÚNUMERIC_GREATER_EQUALÚSEMANTIC_VERSION_LESS_THANÚSEMANTIC_VERSION_LESS_EQUALÚSEMANTIC_VERSION_EQUALÚSEMANTIC_VERSION_NOT_EQUALÚSEMANTIC_VERSION_GREATER_THANÚSEMANTIC_VERSION_GREATER_EQUALr   N)r   r   r   r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   r   r   r   r    r    /   sj   „ ñà'€OØ7ÐØ5ÐØ3ÐØ+ÐØ-ÐØ#€MØ+ÐØ1ÐØ3ÐØ!=ÐØ"?ÐØ5ÐØ!=ÐØ$CÐ!Ø%EÐ"Ø�Gr   r    c                   óf   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
y)	Ú_ServerTemplateDataz>Parses, validates and encapsulates template data and metadata.c                 óJ  — d|v r|d   �|d   | _         nt        d«      ‚i | _         d|v r|d   �|d   | _        nt        d«      ‚g | _        d| _        d|v r
|d   | _        d| _        d|v rt        |d   t        «      r
|d   | _        t        j                  |«      | _	        y)	zîInitializes a new ServerTemplateData instance.

        Args:
            template_data: The data to be parsed for getting the parameters and conditions.

        Raises:
            ValueError: If the template data is not valid.
        Ú
parametersNz2Remote Config parameters must be a non-null objectÚ
conditionsz2Remote Config conditions must be a non-null objectÚ ÚversionÚetag)
Ú_parametersÚ
ValueErrorÚ_conditionsÚ_versionÚ_etagÚ
isinstanceÚstrÚjsonÚdumpsÚ_template_data_json)ÚselfÚtemplate_datas     r   Ú__init__z_ServerTemplateData.__init__F   sÁ   € ð ˜=Ñ(Ø˜\Ñ*Ð6Ø#0°Ñ#>�Õ ä Ð!UÓVÐVà!ˆDÔà˜=Ñ(Ø˜\Ñ*Ð6Ø#0°Ñ#>�Õ ä Ð!UÓVÐVà!ˆDÔàˆŒØ˜Ñ%Ø)¨)Ñ4ˆDŒMàˆŒ
Ø�]Ñ"¤z°-ÀÑ2GÌÔ'MØ& vÑ.ˆDŒJä#'§:¡:¨mÓ#<ˆÕ r   c                 ó   — | j                   S ©N)r9   ©rC   s    r   r4   z_ServerTemplateData.parametersi   ó   € à×ÑÐr   c                 ó   — | j                   S rG   )r=   rH   s    r   r8   z_ServerTemplateData.etagm   s   € à�z‰zÐr   c                 ó   — | j                   S rG   )r<   rH   s    r   r7   z_ServerTemplateData.versionq   s   € à�}‰}Ðr   c                 ó   — | j                   S rG   )r;   rH   s    r   r5   z_ServerTemplateData.conditionsu   rI   r   c                 ó   — | j                   S rG   )rB   rH   s    r   Útemplate_data_jsonz&_ServerTemplateData.template_data_jsony   s   € à×'Ñ'Ð'r   N)r   r   r   r   rE   Úpropertyr4   r8   r7   r5   rN   r   r   r   r2   r2   D   so   „ ÙHò!=ðF ñ ó ð ð ñó ðð ñó ðð ñ ó ð ð ñ(ó ñ(r   r2   c                   óv   — e Zd ZdZddedeeeef      fd„Zd„ Z	ddeeee
eef   f      dd	fd
„Zdefd„Zd„ Zy)ÚServerTemplatezZRepresents a Server Template with implementations for loading and evaluating the template.NÚappÚdefault_configc                 óä   — t        j                  |t        t        «      | _        d| _        i | _        t        j                  «       | _	        |�#|D ]  }t        ||   «      | j                  |<   Œ yy)a  Initializes a ServerTemplate instance.

        Args:
          app: App instance to be used. This is optional and the default app instance will
                be used if not present.
          default_config: The default config to be used in the evaluated config.
        N)r   Úget_app_serviceÚ_REMOTE_CONFIG_ATTRIBUTEÚ_RemoteConfigServiceÚ_rc_serviceÚ_cacheÚ_stringified_default_configÚ	threadingÚRLockÚ_lockr?   )rC   rR   rS   Úkeys       r   rE   zServerTemplate.__init__€   sw   € ô "×1Ñ1°#Ü2JÔL`óbˆÔð ˆŒØ;=ˆÔ(Ü—_‘_Ó&ˆŒ
ð
 Ð%Ø%ò Q�Ü8;¸NÈ3Ñ<OÓ8P�×0Ñ0°Ò5ñQð &r   c              ƒ   ó¤   K  — | j                   j                  «       ƒ d{  –—† }| j                  5  || _        ddd«       y7 Œ!# 1 sw Y   yxY w­w)z0Fetches the server template and caches the data.N)rX   Úget_server_templater]   rY   )rC   Úrc_server_templates     r   ÚloadzServerTemplate.load—   sL   è ø€ à#'×#3Ñ#3×#GÑ#GÓ#I×IÐØ�Z‰Zñ 	-Ø,ˆDŒK÷	-ð 	-ð Jø÷	-ð 	-üs%   ‚A A¡A±A¹
AÁAÁ	AÚcontextÚreturnÚServerConfigc                 óÂ  — | j                   st        d«      ‚|xs i }i }| j                  5  | j                   j                  }| j                   j                  }ddd«       | j
                  �1| j
                  j                  «       D ]  \  }}t        d|«      ||<   Œ t        ||«      | _	        t        | j                  j                  «       ¬«      S # 1 sw Y   Œ}xY w)a"  Evaluates the cached server template to produce a ServerConfig.

        Args:
          context: A dictionary of values to use for evaluating conditions.

        Returns:
          A ServerConfig object.
        Raises:
            ValueError: If the input arguments are invalid.
        zmNo Remote Config Server template in cache.
                            Call load() before calling evaluate().Nr   )Úconfig_values)rY   r:   r]   r5   r4   rZ   ÚitemsÚ_ValueÚ_ConditionEvaluatorÚ
_evaluatorre   Úevaluate)rC   rc   rg   Útemplate_conditionsÚtemplate_parametersr^   Úvalues          r   rl   zServerTemplate.evaluate�   sÜ   € ð �{Š{Üð Fó Gð Gà’-˜RˆØˆà�Z‰Zñ 	9Ø"&§+¡+×"8Ñ"8ÐØ"&§+¡+×"8Ñ"8Ð÷	9ð
 ×+Ñ+Ð7Ø"×>Ñ>×DÑDÓFò >‘
��UÜ%+¨I°uÓ%=�˜cÒ"ð>ä-Ð.AØ.AÀ7Ø.;ó=ˆŒô ¨$¯/©/×*BÑ*BÓ*DÔEÐE÷	9ð 	9ús   ¬-CÃCrN   c                 ó”   — t        j                  |«      }t        |«      }| j                  5  || _        ddd«       y# 1 sw Y   yxY w)z¾Updates the cache to store the given template is of type ServerTemplateData.

        Args:
          template_data_json: A json string representing ServerTemplateData to be cached.
        N)r@   Úloadsr2   r]   rY   )rC   rN   Útemplate_data_maprD   s       r   ÚsetzServerTemplate.set¼   sB   € ô !ŸJ™JÐ'9Ó:ÐÜ+Ð,=Ó>ˆà�Z‰Zñ 	(Ø'ˆDŒK÷	(÷ 	(ñ 	(ús	   ­>¾Ac                 ó¤   — | j                   st        d«      ‚| j                  5  | j                   j                  }ddd«       |S # 1 sw Y   S xY w)zRProvides the server template in a JSON format to be used for initialization later.zkNo Remote Config Server template in cache.
                            Call load() before calling toJSON().N)rY   r:   r]   rN   )rC   Útemplate_jsons     r   Úto_jsonzServerTemplate.to_jsonÈ   sP   € à�{Š{Üð Dó Eð Eà�Z‰Zñ 	;Ø ŸK™K×:Ñ:ˆM÷	;àÐ÷	;àÐús   ¤AÁA©NNrG   )r   r   r   r   r	   r   r   r?   rE   rb   r   Úintrl   rs   rv   r   r   r   rQ   rQ   ~   sl   „ ÙdñQ˜Cð Q¸ÀÀcÈ3ÀhÁÑ8Pó Qò.-ñF ¨¨c°5¸¸c¸±?Ð.BÑ)CÑ Dð FÐP^ó Fð>
( có 
(ór   rQ   c                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
re   z.Represents a Remote Config Server Side Config.c                 ó   — || _         y rG   )Ú_config_values)rC   rg   s     r   rE   zServerConfig.__init__Ô   s
   € Ø+ˆÕr   c                 ó@   — | j                  |«      j                  «       S )úReturns the value as a boolean.)Ú
_get_valueÚ
as_boolean©rC   r^   s     r   Úget_booleanzServerConfig.get_boolean×   ó   € à�‰˜sÓ#×.Ñ.Ó0Ð0r   c                 ó@   — | j                  |«      j                  «       S )úReturns the value as a string.)r~   Ú	as_stringr€   s     r   Ú
get_stringzServerConfig.get_stringÛ   s   € à�‰˜sÓ#×-Ñ-Ó/Ð/r   c                 ó@   — | j                  |«      j                  «       S )z Returns the value as an integer.)r~   Úas_intr€   s     r   Úget_intzServerConfig.get_intß   s   € à�‰˜sÓ#×*Ñ*Ó,Ð,r   c                 ó@   — | j                  |«      j                  «       S )zReturns the value as a float.)r~   Úas_floatr€   s     r   Ú	get_floatzServerConfig.get_floatã   s   € à�‰˜sÓ#×,Ñ,Ó.Ð.r   c                 ó@   — | j                  |«      j                  «       S ©z Returns the source of the value.)r~   Ú
get_sourcer€   s     r   Úget_value_sourcezServerConfig.get_value_sourceç   r‚   r   c                 óL   — | j                   j                  |t        d«      «      S )Nr   )r{   Úgetri   r€   s     r   r~   zServerConfig._get_valueë   s    € Ø×"Ñ"×&Ñ& s¬F°8Ó,<Ó=Ð=r   N)r   r   r   r   rE   r�   r†   r‰   rŒ   r�   r~   r   r   r   re   re   Ò   s(   „ Ù8ò,ò1ò0ò-ò/ò1ó>r   re   c                   ó8   — e Zd ZdZd„ Zd„ Zd„ Zedefd„«       Z	y)rW   zhInternal class that facilitates sending requests to the Firebase Remote
        Config backend API.
    c                 ó  — d}|j                   | _        |j                  j                  «       }ddt        j
                  › �i}|j                  j                  dt        j                  «      }t        j                  ||||¬«      | _        y)zÐInitialize a JsonHttpClient with necessary inputs.

        Args:
            app: App instance to be used for fetching app specific details required
                for initializing the http client.
        z+https://firebaseremoteconfig.googleapis.comzX-FIREBASE-CLIENTzfire-admin-python/ÚhttpTimeout)Ú
credentialÚbase_urlÚheadersÚtimeoutN)Ú
project_idÚ_project_idr–   Úget_credentialÚfirebase_adminÚ__version__Úoptionsr’   r
   ÚDEFAULT_TIMEOUT_SECONDSÚJsonHttpClientÚ_client)rC   rR   Úremote_config_base_urlÚapp_credentialÚ
rc_headersr™   s         r   rE   z_RemoteConfigService.__init__ó   s|   € ð "OÐØŸ>™>ˆÔØŸ™×6Ñ6Ó8ˆàÐ#5´n×6PÑ6PÐ5QÐ!RðVˆ
à—+‘+—/‘/ -´×1UÑ1UÓVˆä#×2Ñ2¸nØ<RØ;EÈwôXˆ�r   c              ƒ   ód  K  — 	 t        j                  «       }|j                  d| j                  j                  d| j                  «       «      ƒ d{  –—† \  }}|j                  d«      |d<   t        |«      S 7 Œ&# t        j                  j                  $ r}| j                  |«      ‚d}~ww xY w­w)z™Requests for a server template and converts the response to an instance of
        ServerTemplateData for storing the template parameters and conditions.Nr’   r8   )ÚasyncioÚget_event_loopÚrun_in_executorr¢   Úheaders_and_bodyÚ_get_urlÚrequestsÚ
exceptionsÚRequestExceptionÚ_handle_remote_config_errorr’   r2   )rC   Úloopr˜   rD   Úerrors        r   r`   z(_RemoteConfigService.get_server_template  s£   è ø€ ð	:Ü×)Ñ)Ó+ˆDØ+/×+?Ñ+?ÀØ@DÇÁ×@]Ñ@]Ø@EÀtÇ}Á}Ãó,X÷ &XÑ"ˆG�]ð
 !(§¡¨FÓ 3ˆ�fÑÜ" =Ó1Ð1ð&Xùô ×"Ñ"×3Ñ3ò 	:Ø×2Ñ2°5Ó9Ð9ûð	:üs;   ‚B0„AA: ÁA8ÁA: ÁB0Á8A: Á:B-ÂB(Â(B-Â-B0c                 ó"   — d| j                   › d�S )zJReturns project prefix for url, in the format of /v1/projects/${projectId}z/v1/projects/z./namespaces/firebase-server/serverRemoteConfig)r›   rH   s    r   r«   z_RemoteConfigService._get_url  s   € à˜t×/Ñ/Ð0Ð0^Ð_Ð_r   r±   c                 ó,   — t        j                  |«      S )z5Handles errors received from the Cloud Functions API.)r   Ú#handle_platform_error_from_requests)Úclsr±   s     r   r¯   z0_RemoteConfigService._handle_remote_config_error  s   € ô ×9Ñ9¸%Ó@Ð@r   N)
r   r   r   r   rE   r`   r«   Úclassmethodr   r¯   r   r   r   rW   rW   ï   s6   „ ñòXò$2ò`ð ðA°ò Aó ñAr   rW   c                   óÆ   — e Zd ZdZd„ Zd„ Zdeeef   fd„Z		 dde
defd„Z	 dde
defd„Z	 dde
defd	„Zdefd
„Zdede
fd„Zdefd„Zdefd„Zdefd„Zdefd„Zdefd„Zy)rj   z_Internal class that facilitates sending requests to the Firebase Remote
    Config backend API.c                 ó<   — || _         || _        || _        || _        y rG   )Ú_contextr;   r9   r{   )rC   r5   r4   rc   rg   s        r   rE   z_ConditionEvaluator.__init__  s!   € ØˆŒØ%ˆÔØ%ˆÔØ+ˆÕr   c                 óä  — | j                  | j                  | j                  «      }| j                  �r2| j                  j	                  «       D �]  \  }}|j                  di «      }|j                  di «      }d}|r&|j	                  «       D ]  \  }}||v sŒ|sŒ||   } n |r(|j                  d«      rt        j                  d|«       Œ|r+|j                  d«      }	t        d|	«      | j                  |<   Œ¬|st        j                  d|«       ŒÅ|j                  d«      rt        j                  d|«       Œít        d|j                  d«      «      | j                  |<   �Œ | j                  S )	z]Internal function that evaluates the cached server template to produce
        a ServerConfigÚconditionalValuesÚdefaultValueNÚuseInAppDefaultz'Using in-app default value for key '%s'ro   r   z#No default value found for key '%s')Úevaluate_conditionsr;   r¹   r9   rh   r’   ÚloggerÚinfori   r{   Úwarning)
rC   Úevaluated_conditionsr^   Ú	parameterÚconditional_valuesÚdefault_valueÚparameter_value_wrapperÚcondition_nameÚcondition_evaluationÚparameter_values
             r   rl   z_ConditionEvaluator.evaluate%  sn  € ð  $×7Ñ7¸×8HÑ8HÈ$Ï-É-ÓXÐð ×ÓØ"&×"2Ñ"2×"8Ñ"8Ó":ó X‘��YØ%.§]¡]Ð3FÈÓ%KÐ"Ø )§¡¨n¸bÓ A�Ø*.Ð'ñ (Ø@T×@ZÑ@ZÓ@\ò "Ñ<˜Ð(<Ø)Ð-?Ò?ÒDXØ6HÈÑ6XÐ3Ù!ð"ñ
 +Ð/F×/JÑ/JÐK\Ô/]Ü—K‘KÐ IÈ3ÔOØá*Ø&=×&AÑ&AÀ'Ó&J�OÜ/5°hÀÓ/P�D×'Ñ'¨Ñ,Øá$Ü—N‘NÐ#HÈ#ÔNØà ×$Ñ$Ð%6Ô7Ü—K‘KÐ IÈ3ÔOØÜ+1°(¸M×<MÑ<MÈgÓ<VÓ+W�×#Ñ# CÓ(ð9Xð: ×"Ñ"Ð"r   rd   c                 ó~   — i }|D ]5  }| j                  |j                  d«      |«      ||j                  d«      <   Œ7 |S )a%  Evaluates a list of conditions and returns a dictionary of results.

        Args:
          conditions: A list of NamedCondition objects.
          context: An EvaluationContext object.

        Returns:
          A dictionary that maps condition names to boolean evaluation results.
        Ú	conditionÚname)Úevaluate_conditionr’   )rC   r5   rc   rÂ   rË   s        r   r¾   z'_ConditionEvaluator.evaluate_conditionsK  sN   € ð  "ÐØ#ò 	ˆIØ:>×:QÑ:QØ—‘˜kÓ*¨Gó;Ð  §¡¨vÓ!6Ò7ð	ð $Ð#r   Únesting_levelc                 óT  — |t         k\  rt        j                  d«       y|j                  d«      �%| j	                  |j                  d«      ||dz   «      S |j                  d«      �%| j                  |j                  d«      ||dz   «      S |j                  d«      �y|j                  d«      �y|j                  d	«      �!| j                  |j                  d	«      |«      S |j                  d
«      �!| j                  |j                  d
«      |«      S t        j                  d«       y)a  Recursively evaluates a condition.

        Args:
          condition: The condition to evaluate.
          context: An EvaluationContext object.
          nesting_level: The current recursion depth.

        Returns:
          The boolean result of the condition evaluation.
        z+Maximum condition recursion depth exceeded.FÚorConditioné   ÚandConditionÚtrueTÚfalseÚpercentÚcustomSignalz#Unknown condition type encountered.)ÚMAX_CONDITION_RECURSION_DEPTHr¿   rÁ   r’   Úevaluate_or_conditionÚevaluate_and_conditionÚevaluate_percent_conditionÚ evaluate_custom_signal_condition)rC   rË   rc   rÎ   s       r   rÍ   z&_ConditionEvaluator.evaluate_condition\  s  € ð Ô9Ò9Ü�N‰NÐHÔIØØ�=‰=˜Ó'Ð3Ø×-Ñ-¨i¯m©m¸MÓ.JØ.5°}ÀqÑ7HóJð Jà�=‰=˜Ó(Ð4Ø×.Ñ.¨y¯}©}¸^Ó/LØ/6¸ÈÑ8IóKð Kà�=‰=˜Ó Ð,ØØ�=‰=˜Ó!Ð-ØØ�=‰=˜Ó#Ð/Ø×2Ñ2°9·=±=ÀÓ3KÈWÓUÐUØ�=‰=˜Ó(Ð4Ø×8Ñ8¸¿¹À~Ó9VÐX_Ó`Ð`Ü�‰Ð<Ô=Ør   c                 óp   — |j                  d«      xs g }|D ]  }| j                  |||dz   «      }|sŒ y y)a&  Evaluates an OR condition.

        Args:
          or_condition: The OR condition to evaluate.
          context: An EvaluationContext object.
          nesting_level: The current recursion depth.

        Returns:
          True if any of the subconditions are true, False otherwise.
        r5   rÑ   TF©r’   rÍ   )rC   Úor_conditionrc   rÎ   Úsub_conditionsÚsub_conditionÚresults          r   rØ   z)_ConditionEvaluator.evaluate_or_condition|  sM   € ð &×)Ñ)¨,Ó7Ò=¸2ˆØ+ò 	ˆMØ×,Ñ,¨]¸GÀ]ÐUVÑEVÓWˆFÚÙð	ð r   c                 óp   — |j                  d«      xs g }|D ]  }| j                  |||dz   «      }|rŒ y y)a(  Evaluates an AND condition.

        Args:
          and_condition: The AND condition to evaluate.
          context: An EvaluationContext object.
          nesting_level: The current recursion depth.

        Returns:
          True if all of the subconditions are met; False otherwise.
        r5   rÑ   FTrÝ   )rC   Úand_conditionrc   rÎ   rß   rà   rá   s          r   rÙ   z*_ConditionEvaluator.evaluate_and_condition�  sM   € ð '×*Ñ*¨<Ó8Ò>¸BˆØ+ò 	ˆMØ×,Ñ,¨]¸GÀ]ÐUVÑEVÓWˆFÚÙð	ð r   c                 óð  — |j                  d«      st        j                  d«       y|j                  d«      }|j                  d«      }|j                  d«      }|j                  d«      }|st        j                  d«       y|r+|j                  d	«      xs d
}|j                  d«      xs d
}nd
}d
}|r|}	nd
}	|r|› d�nd}
|
› |j                  d«      › �}| j                  |«      }|dz  }|t        j
                  j                  k(  r||	k  S |t        j                  j                  k(  r||	kD  S |t        j                  j                  k(  r||cxk  xr |k  S c S t        j                  d|«       y)zñEvaluates a percent condition.

        Args:
          percent_condition: The percent condition to evaluate.
          context: An EvaluationContext object.

        Returns:
          True if the condition is met, False otherwise.
        Úrandomization_idzEMissing randomization_id in context for evaluating percent condition.FÚseedÚpercentOperatorÚmicroPercentÚmicroPercentRangez/Missing percent operator for percent condition.ÚmicroPercentUpperBoundr   ÚmicroPercentLowerBoundú.r6   i áõzUnknown percent operator: %s)	r’   r¿   rÁ   Úhash_seeded_randomization_idr   r   ro   r   r   )rC   Úpercent_conditionrc   ræ   Úpercent_operatorÚmicro_percentÚmicro_percent_rangeÚnorm_percent_upper_boundÚnorm_percent_lower_boundÚnorm_micro_percentÚseed_prefixÚstring_to_hashÚhash64Úinstance_micro_percentiles                 r   rÚ   z._ConditionEvaluator.evaluate_percent_condition¤  s‹  € ð �{‰{Ð-Ô.Ü�N‰NÐbÔcØà ×$Ñ$ VÓ,ˆØ,×0Ñ0Ð1BÓCÐØ)×-Ñ-¨nÓ=ˆØ/×3Ñ3Ð4GÓHÐÙÜ�N‰NÐLÔMØÙØ':×'>Ñ'>Ð?WÓ'XÒ']Ð\]Ð$Ø':×'>Ñ'>Ð?WÓ'XÒ']Ð\]Ñ$à'(Ð$Ø'(Ð$ÙØ!.Ñà!"ÐÙ$(˜˜˜a‘j¨bˆØ'˜=¨¯©Ð5GÓ)HÐ(IÐJˆà×2Ñ2°>ÓBˆØ$*¨mÑ$<Ð!ØÔ7×EÑE×KÑKÒKØ,Ð0BÑBÐBØÔ7×DÑD×JÑJÒJØ,Ð/AÑAÐAØÔ7×?Ñ?×EÑEÒEØ+Ð.GÖcÐKcÑcÐcÑcÐcÜ�‰Ð5Ð7GÔHØr   Úseeded_randomization_idc                 ó´   — t        j                  «       }|j                  |j                  d«      «       |j	                  «       }t        t        |d«      «      S )z¯Hashes a seeded randomization ID.

        Args:
          seeded_randomization_id: The seeded randomization ID to hash.

        Returns:
          The hashed value.
        zutf-8é   )ÚhashlibÚsha256ÚupdateÚencodeÚ	hexdigestÚabsrx   )rC   rù   Úhash_objectr÷   s       r   rí   z0_ConditionEvaluator.hash_seeded_randomization_idÑ  sI   € ô —n‘nÓ&ˆØ×ÑÐ2×9Ñ9¸'ÓBÔCØ×&Ñ&Ó(ˆÜ”3�v˜r“?Ó#Ð#r   c                 óô  — |j                  d«      xs i }|j                  d«      xs i }|j                  d«      xs i }t        |||g«      st        j                  d«       y|sy|j                  |«      xs i }|st        j	                  d|«       y|t
        j                  j                  k(  r| j                  ||d„ «      S |t
        j                  j                  k(  r| j                  ||d„ «       S |t
        j                  j                  k(  r| j                  ||d	„ «      S |t
        j                  j                  k(  r!| j                  ||t        j                  «      S |t
        j                  j                  k(  r| j                  ||d
   |d„ «      S |t
        j                   j                  k(  r| j                  ||d
   |d„ «      S |t
        j"                  j                  k(  r| j                  ||d
   |d„ «      S |t
        j$                  j                  k(  r| j                  ||d
   |d„ «      S |t
        j&                  j                  k(  r| j                  ||d
   |d„ «      S |t
        j(                  j                  k(  r| j                  ||d
   |d„ «      S |t
        j*                  j                  k(  r| j-                  ||d
   |d„ «      S |t
        j.                  j                  k(  r| j-                  ||d
   |d„ «      S |t
        j0                  j                  k(  r| j-                  ||d
   |d„ «      S |t
        j2                  j                  k(  r| j-                  ||d
   |d„ «      S |t
        j4                  j                  k(  r| j-                  ||d
   |d„ «      S |t
        j6                  j                  k(  r| j-                  ||d
   |d„ «      S t        j                  d|«       y)a  Evaluates a custom signal condition.

        Args:
          custom_signal_condition: The custom signal condition to evaluate.
          context: An EvaluationContext object.

        Returns:
          True if the condition is met, False otherwise.
        ÚcustomSignalOperatorÚcustomSignalKeyÚtargetCustomSignalValueszDMissing operator, key, or target values for custom signal condition.Fz,Custom signal value not found in context: %sc                 ó
   — | |v S rG   r   ©ÚtargetÚactuals     r   ú<lambda>zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>þ  s   € ÀÈ&Ð@P€ r   c                 ó
   — | |v S rG   r   r  s     r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>  s   € ÀFÈfÐDT€ r   c                 óD   — | j                  «       |j                  «       k(  S rG   )Ústripr  s     r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>  s   € ÀÇÁÃÐRX×R^ÑR^ÓR`Ñ@`€ r   r   c                 ó   — | dk  S ©Nr   r   ©Úrs    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>  ó
   € °1°q±5€ r   c                 ó   — | dk  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>  ó
   € °1¸±6€ r   c                 ó   — | dk(  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>  r  r   c                 ó   — | dk7  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>   r  r   c                 ó   — | dkD  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>%  r  r   c                 ó   — | dk\  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>*  r  r   c                 ó   — | dk  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>1  ó
   € ¸QÀ¹U€ r   c                 ó   — | dk  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>6  ó
   € ¸QÀ!¹V€ r   c                 ó   — | dk(  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>;  r  r   c                 ó   — | dk7  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>@  r  r   c                 ó   — | dkD  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>E  r  r   c                 ó   — | dk\  S r  r   r  s    r   r  zF_ConditionEvaluator.evaluate_custom_signal_condition.<locals>.<lambda>J  r  r   z"Unknown custom signal operator: %s)r’   Úallr¿   rÁ   Údebugr    r!   ro   Ú_compare_stringsr"   r#   r$   ÚreÚsearchr%   Ú_compare_numbersr&   r'   r(   r)   r*   r+   Ú_compare_semantic_versionsr,   r-   r.   r/   r0   )rC   Úcustom_signal_conditionrc   Úcustom_signal_operatorÚcustom_signal_keyÚtarget_custom_signal_valuesÚactual_custom_signal_values          r   rÛ   z4_ConditionEvaluator.evaluate_custom_signal_conditionß  s`  € ð "9×!<Ñ!<Ð=SÓ!TÒ!ZÐXZÐØ3×7Ñ7Ð8IÓJÒPÈbÐà#×'Ñ'Ð(BÓCÒIÀrð 	$ô Ð*Ð,=Ð?ZÐ[Ô\Ü�N‰NÐaÔbØá*ØØ%,§[¡[Ð1BÓ%CÒ%IÀrÐ"á)Ü�L‰LÐGÐIZÔ[Øà!Ô%9×%IÑ%I×%OÑ%OÒOØ×(Ñ(Ð)DØ)CÙ)PóRð Rð "Ô%9×%QÑ%Q×%WÑ%WÒWØ×,Ñ,Ð-HØ-GÙ-TóVð Vð Vð "Ô%9×%PÑ%P×%VÑ%VÒVØ×(Ñ(Ð)DØ)CÙ)`óbð bð "Ô%9×%OÑ%O×%UÑ%UÒUØ×(Ñ(Ð)DØ)CÜ)+¯©ó4ð 4ð
 "Ô%9×%KÑ%K×%QÑ%QÒQØ×(Ñ(Ð):Ø)DÀQÑ)GØ)CÙ)8ó:ð :ð "Ô%9×%LÑ%L×%RÑ%RÒRØ×(Ñ(Ð):Ø)DÀQÑ)GØ)CÙ)9ó;ð ;ð "Ô%9×%GÑ%G×%MÑ%MÒMØ×(Ñ(Ð):Ø)DÀQÑ)GØ)CÙ)9ó;ð ;ð "Ô%9×%KÑ%K×%QÑ%QÒQØ×(Ñ(Ð):Ø)DÀQÑ)GØ)CÙ)9ó;ð ;ð "Ô%9×%NÑ%N×%TÑ%TÒTØ×(Ñ(Ð):Ø)DÀQÑ)GØ)CÙ)8ó:ð :ð "Ô%9×%OÑ%O×%UÑ%UÒUØ×(Ñ(Ð):Ø)DÀQÑ)GØ)CÙ)9ó;ð ;ð "Ô%9×%TÑ%T×%ZÑ%ZÒZØ×2Ñ2Ð3DØ3NÈqÑ3QØ3MÙ3BóDð Dð "Ô%9×%UÑ%U×%[Ñ%[Ò[Ø×2Ñ2Ð3DØ3NÈqÑ3QØ3MÙ3CóEð Eð "Ô%9×%PÑ%P×%VÑ%VÒVØ×2Ñ2Ð3DØ3NÈqÑ3QØ3MÙ3CóEð Eð "Ô%9×%TÑ%T×%ZÑ%ZÒZØ×2Ñ2Ð3DØ3NÈqÑ3QØ3MÙ3CóEð Eð "Ô%9×%WÑ%W×%]Ñ%]Ò]Ø×2Ñ2Ð3DØ3NÈqÑ3QØ3MÙ3BóDð Dð "Ô%9×%XÑ%X×%^Ñ%^Ò^Ø×2Ñ2Ð3DØ3NÈqÑ3QØ3MÙ3CóEð Eô 	�‰Ð;Ð=SÔTØr   c                 ó:   — |D ]  } ||t        |«      «      sŒ y y)aj  Compares the actual string value of a signal against a list of target values.

        Args:
            target_values: A list of target string values.
            actual_value: The actual value to compare, which can be a string or number.
            predicate_fn: A function that takes two string arguments (target and actual)
                            and returns a boolean indicating whether
                            the target matches the actual value.

        Returns:
            bool: True if the predicate function returns True for any target value in the list,
                False otherwise.
        TF)r?   )rC   Útarget_valuesÚactual_valueÚpredicate_fnr	  s        r   r$  z$_ConditionEvaluator._compare_stringsN  s*   € ð $ò 	ˆFÙ˜F¤C¨Ó$5Õ6Ùð	ð r   c                 óª   — 	 t        |«      }t        |«      }||k  rdn||kD  rdnd} ||«      S # t        $ r t        j                  d|«       Y yw xY w)NéÿÿÿÿrÑ   r   z>Invalid numeric value for comparison for custom signal key %s.F)Úfloatr:   r¿   rÁ   )rC   r+  Útarget_valuer0  r1  r	  r
  rá   s           r   r'  z$_ConditionEvaluator._compare_numbersb  s_   € ð	Ü˜<Ó(ˆFÜ˜<Ó(ˆFØ! Fš?‘R°V¸f²_±È!ˆFÙ Ó'Ð'øÜò 	Ü�N‰NÐ[Ø,ô.áð	ús   ‚-0 °AÁAc                 óN   — | j                  |t        |«      t        |«      |«      S )a§  Compares the actual semantic version value of a signal against a target value.
        Calls the predicate function with -1, 0, 1 if actual is less than, equal to,
        or greater than target.

        Args:
        custom_signal_key: The custom signal for which the evaluation is being performed.
        target_values: A list of target string values.
        actual_value: The actual value to compare, which can be a string or number.
        predicate_fn: A function that takes an integer (-1, 0, or 1) and returns a boolean.

        Returns:
            bool: True if the predicate function returns True for the result of the comparison,
        False otherwise.
        )Ú_compare_versionsr?   )rC   r+  r5  r0  r1  s        r   r(  z._ConditionEvaluator._compare_semantic_versionsm  s-   € ð  ×%Ñ%Ð&7¼¸\Ó9JÜ&)¨,Ó&7¸óGð 	Gr   c                 ód  — 	 |j                  d«      D �cg c]  }t        |«      ‘Œ }}|j                  d«      D �cg c]  }t        |«      ‘Œ }}t        t        |«      t        |«      «      }|j	                  dg|t        |«      z
  z  «       |j	                  dg|t        |«      z
  z  «       t        ||«      D ]<  \  }	}
t        |	dk  |
dk  f«      rt        ‚|	|
k  r
 |d«      c S |	|
kD  sŒ4 |d«      c S   |d«      S c c}w c c}w # t        $ r t        j                  d|«       Y yw xY w)aµ  Compares two semantic version strings.

        Args:
            custom_signal_key: The custom singal for which the evaluation is being performed.
            sem_version_1: The first semantic version string.
            sem_version_2: The second semantic version string.
            predicate_fn: A function that takes an integer and returns a boolean.

        Returns:
            bool: The result of the predicate function.
        rì   r   r3  rÑ   zHInvalid semantic version format for comparison for custom signal key %s.F)
Úsplitrx   ÚmaxÚlenÚextendÚzipÚanyr:   r¿   rÁ   )rC   r+  Úsem_version_1Úsem_version_2r1  ÚpartÚv1_partsÚv2_partsÚ
max_lengthÚpart1Úpart2s              r   r7  z%_ConditionEvaluator._compare_versions€  s,  € ð	Ø.;×.AÑ.AÀ#Ó.FÖG dœ˜D�	ÐGˆHÐGØ.;×.AÑ.AÀ#Ó.FÖG dœ˜D�	ÐGˆHÐGÜœS ›]¬C°«MÓ:ˆJØ�O‰O˜Q˜C :´°H³Ñ#=Ñ>Ô?Ø�O‰O˜Q˜C :´°H³Ñ#=Ñ>Ô?ä # H¨hÓ 7ò +‘��uÜ˜ ™	 5¨1¡9Ð-Ô.Ü$Ð$Ø˜5’=Ù'¨Ó+Ò+Ø˜5“=Ù'¨›?Ò*ð+ñ   “?Ð"ùò HùÚGøô ò 	Ü�N‰NØZØ!ô#ñ ð		ús?   ‚D •D§D ¼DÁBD Ã*D Ã0	D Ã:D Ä
D ÄD/Ä.D/N)r   )r   r   r   r   rE   rl   r   r?   Úboolr¾   rx   rÍ   rØ   rÙ   rÚ   rí   rÛ   r$  r'  r(  r7  r   r   r   rj   rj     sÛ   „ ñò,ò$#ðL$¸¸cÀ4¸i¹ó $ð$ 12ñØ*-ðØ6:óðD 45ñà-0ðà9=óð, 56ñà.1ðà:>óð(,Ø/3ó,ðZ$ÀCð $ÈCó $ðmØ59ómð^ÈTó ð(	Ð_có 	ðGØPTóGð& ØIMô r   rj   rR   rS   c              ƒ   ó\   K  — t        | |¬«      }|j                  «       ƒ d{  –—†  |S 7 Œ­w)a“  Initializes a new ServerTemplate instance and fetches the server template.

    Args:
        app: App instance to be used. This is optional and the default app instance will
            be used if not present.
        default_config: The default config to be used in the evaluated config.

    Returns:
        ServerTemplate: An object having the cached server template to be used for evaluation.
    ©rR   rS   N)Úinit_server_templaterb   )rR   rS   Útemplates      r   r`   r`   ¢  s-   è ø€ ô $¨¸NÔK€HØ
�-‰-‹/×ÐØ€Oð ús   ‚!,£*¤,rN   c                 óF   — t        | |¬«      }|�|j                  |«       |S )aÜ  Initializes a new ServerTemplate instance.

    Args:
        app: App instance to be used. This is optional and the default app instance will
            be used if not present.
        default_config: The default config to be used in the evaluated config.
        template_data_json: An optional template data JSON to be set on initialization.

    Returns:
        ServerTemplate: A new ServerTemplate instance initialized with an optional
        template and config.
    rI  )rQ   rs   )rR   rS   rN   rK  s       r   rJ  rJ  ±  s(   € ô  #°nÔE€HØÐ%Ø�‰Ð'Ô(Ø€Or   c                   óx   — e Zd ZdZdZdZdZdZg d¢Zefde	de
fd	„Zd
e
fd„Zd
efd„Zd
efd„Zd
efd„Zd
e	fd„Zy)ri   z3Represents a value fetched from Remote Config.
    Fr6   r   g        )Ú1rÓ   ÚtÚyesÚyÚonÚsourcero   c                 ó    — || _         || _        y)a™  Initializes a Value instance.

        Args:
          source: The source of the value (e.g., 'default', 'remote', 'static').
          "static" indicates the value was defined by a static constant.
          "default" indicates the value was defined by default config.
          "remote" indicates the value was defined by config produced by evaluating a template.
          value: The string value.
        N)rS  ro   )rC   rS  ro   s      r   rE   z_Value.__init__Í  s   € ð ˆŒØˆ�
r   rd   c                 ób   — | j                   dk(  r| j                  S t        | j                  «      S )r„   r   )rS  ÚDEFAULT_VALUE_FOR_STRINGr?   ro   rH   s    r   r…   z_Value.as_stringÚ  s(   € à�;‰;˜(Ò"Ø×0Ñ0Ð0Ü�4—:‘:‹Ðr   c                 ó–   — | j                   dk(  r| j                  S t        | j                  «      j	                  «       | j
                  v S )r}   r   )rS  ÚDEFAULT_VALUE_FOR_BOOLEANr?   ro   ÚlowerÚBOOLEAN_TRUTHY_VALUESrH   s    r   r   z_Value.as_booleanà  s<   € à�;‰;˜(Ò"Ø×1Ñ1Ð1Ü�4—:‘:‹×$Ñ$Ó&¨$×*DÑ*DÐDÐDr   c                 óš   — | j                   dk(  r| j                  S 	 t        | j                  «      S # t        $ r | j                  cY S w xY w©zReturns the value as a number.r   )rS  ÚDEFAULT_VALUE_FOR_INTEGERrx   ro   r:   rH   s    r   rˆ   z_Value.as_intæ  sH   € à�;‰;˜(Ò"Ø×1Ñ1Ð1ð	2Ü�t—z‘z“?Ð"øÜò 	2Ø×1Ñ1Ò1ð	2úó   �2 ²A
Á	A
c                 óš   — | j                   dk(  r| j                  S 	 t        | j                  «      S # t        $ r | j                  cY S w xY wr\  )rS  ÚDEFAULT_VALUE_FOR_FLOAT_NUMBERr4  ro   r:   rH   s    r   r‹   z_Value.as_floatï  sI   € à�;‰;˜(Ò"Ø×6Ñ6Ð6ð	7Ü˜Ÿ™Ó$Ð$øÜò 	7Ø×6Ñ6Ò6ð	7úr^  c                 ó   — | j                   S rŽ   )rS  rH   s    r   r�   z_Value.get_sourceø  s   € à�{‰{Ðr   N)r   r   r   r   rX  rV  r]  r`  rZ  ÚValueSourcer?   rE   r…   rG  r   r4  rˆ   r‹   r�   r   r   r   ri   ri   Ä  sy   „ ñà %ÐØ!ÐØ !ÐØ%(Ð"Ú@Ðà9Qñ ˜{ð °3ó ð˜3ó ðE˜Dó Eð2˜ó 2ð7˜%ó 7ð˜Kô r   ri   rw   )NNN)'r   r§   r@   Úloggingr[   Útypingr   r   r   r   r   Úenumr   r%  rü   r¬   r�   r	   r
   r   ÚbasicConfigÚINFOÚ	getLoggerr   r¿   rV   r×   rb  r   r    r2   rQ   re   rW   rj   r?   r`   rJ  ri   r   r   r   ú<module>ri     s'  ðñó Û Û Û ß 6Õ 6Ý Û 	Û Û ß 4Ñ 4Û ð €× Ñ ˜'Ÿ,™,Õ 'Ø	ˆ×	Ñ	˜8Ó	$€à*Ð Ø "Ð ØÐ3Ñ4€ô˜tô ô˜4ô ÷*7(ñ 7(÷tQñ Q÷h>ñ >÷:*Añ *A÷ZDñ DñL 3ð ¸xÈÈSÐRUÈXÉÑ?Wó ð VZØ=Añ˜cð ¸(À4ÈÈSÈÁ>Ñ:Rð Ø-5°c©]ó÷&6ò 6r   