
    MhO                         d dl Z d dlZ ej        d          Z ej        d          Z ej        d          ZdefdZ e            adefdZ	d Z
d	 Zd
eddfdZd
edefdZdeddfdZd ZdedefdZd Zd ZdS )    Nz^[a-zA-Z_:][a-zA-Z0-9_:]*$z^[a-zA-Z_][a-zA-Z0-9_]*$z^__.*$returnc                  j    t           j                            dd                                          dv S )z2Retrieve name validation setting from environment.!PROMETHEUS_LEGACY_NAME_VALIDATIONFalse)true1t)osenvirongetlower     \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prometheus_client/validation.py_init_legacy_validationr   	   s+    :>>=wGGMMOOSeeer   c                      t           S )z;Return the current status of the legacy validation setting._legacy_validationr   r   r   get_legacy_validationr      s
     r   c                  
    da dS )zEDisable legacy name validation, instead allowing all UTF8 characters.FNr   r   r   r   disable_legacy_validationr      s     r   c                  
    da dS )zFEnable legacy name validation instead of allowing all UTF8 characters.TNr   r   r   r   enable_legacy_validationr      s     r   namec                     | st          d          t          r,t                              |           st          d| z             	 |                     d           dS # t
          $ r t          d| z             w xY w)zRaises ValueError if the provided name is not a valid metric name.
    
    This check uses the global legacy validation setting to determine the validation scheme.
    zmetric name cannot be emptyzinvalid metric name utf-8N)
ValueErrorr   METRIC_NAME_REmatchencodeUnicodeDecodeErrorr   s    r   _validate_metric_namer#   #   s    
  86777 <##D)) 	<3d:;;;8G 8 8 8/$67778s   A A:c                 :    t                               |           duS )zRReturns true if the provided metric name conforms to the legacy validation scheme.N)r   r   r"   s    r   _is_valid_legacy_metric_namer%   4   s    %%T11r   tokc                 8   | st          d| z             | d         dk    o| d         dk    }|rt          r.t                              |           st          d| z             dS 	 |                     d           dS # t
          $ r t          d| z             w xY w)zeRaises ValueError if a parsed label name token is invalid. 
    
    UTF-8 names must be quoted.
    zinvalid label name token r   "Nr   )r   r   METRIC_LABEL_NAME_REr   r    r!   )r&   quoteds     r   !_validate_metric_label_name_tokenr,   9   s    
  <4s:;;;Vs]-s2w#~F ' #))#.. 	@83>???<

7 < < <4s:;;;<s   %A< <Bc                    t                      rZt                              |           st          d| z             t                              |           rt          d| z             dS 	 |                     d           n # t          $ r t          d| z             w xY wt                              |           rt          d| z             dS )zRaises ValueError if the provided name is not a valid label name.
    
    This check uses the global legacy validation setting to determine the validation scheme.
    zInvalid label metric name: zReserved label metric name: r   N)r   r*   r   r   RESERVED_METRIC_LABEL_NAME_REr    r!   ls    r   _validate_labelnamer1   L   s    
  A#))!,, 	@:Q>???(..q11 	A;a?@@@	A 	A	@HHW! 	@ 	@ 	@:Q>???	@(..q11 	A;a?@@@	A 	As   *B   Br0   c                 r    t                               |           dS t                              |           du S )zQReturns true if the provided label name conforms to the legacy validation scheme.NF)r*   r   r.   r/   s    r   _is_valid_legacy_labelnamer3   _   s4    !!!$$,u(..q11T99r   c                     t          |          }|D ],}t          |           || j        v rt          d|z             -|S )zRaises ValueError if any of the provided names is not a valid label name.
    
    This check uses the global legacy validation setting to determine the validation scheme.
    z Reserved label methe fric name: )tupler1   _reserved_labelnamesr   )cls
labelnamesr0   s      r   _validate_labelnamesr9   f   s]    
 z""J E EA(((?!CDDD )r   c                     d}|                                  D ]8\  }}t          |           |t          |          z  }|t          |          z  }9|dk    rt          d          dS )z-Raises ValueError if the exemplar is invalid.r      zDExemplar labels have %d UTF-8 characters, exceeding the limit of 128N)itemsr1   lenr   )exemplarruneskvs       r   _validate_exemplarrB   s   sq    E    1AQQs{{_``` {r   )r
   recompiler   r*   r.   boolr   r   r   r   r   strr#   r%   r,   r1   r3   r9   rB   r   r   r   <module>rG      s   				 				9::!rz"=>>  *
9 5 5 f f f f f
 -,.. t        8 8 8 8 8 8"2s 2t 2 2 2 2
<3 <4 < < < <&A A A&:# :$ : : : :
 
 
a a a a ar   