
    XhO                        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y)    Nz^[a-zA-Z_:][a-zA-Z0-9_:]*$z^[a-zA-Z_][a-zA-Z0-9_]*$z^__.*$returnc                  b    t         j                  j                  dd      j                         dv S )z2Retrieve name validation setting from environment.!PROMETHEUS_LEGACY_NAME_VALIDATIONFalse)true1t)osenvirongetlower     P/var/www/html/myenv/lib/python3.12/site-packages/prometheus_client/validation.py_init_legacy_validationr   	   s'    ::>>=wGMM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 y)zEDisable legacy name validation, instead allowing all UTF8 characters.FNr   r   r   r   disable_legacy_validationr      s
     r   c                      da y)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        j                  |       st        d| z         	 | j	                  d       y# 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#   #   sf    
 677##D)3d:;;8G 8/$6778s   A
 
A"c                 0    t         j                  |       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                     | st        d| z         | d   dk(  xr | d   dk(  }|rt        r$t        j                  |       st        d| z         y	 | j	                  d       y# 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" "A:c                 F   t               rGt        j                  |       st        d| z         t        j                  |       rt        d| z         y	 | j                  d       t        j                  |       rt        d| z         y# t        $ r t        d| z         w xY w)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    
 #))!,:Q>??(..q1;a?@@ 2	@HHW )..q1;a?@@ 2 " 	@:Q>??	@s   B B r0   c                 \    t         j                  |       yt        j                  |       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   _   s,    !!!$,(..q1T99r   c                 x    t        |      }|D ])  }t        |       || j                  v s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   sN    
 z"J EA(((?!CDDE r   c                     d}| j                         D ],  \  }}t        |       |t        |      z  }|t        |      z  }. |dkD  rt        d      y)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   s]    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:!rzz"=>  *

9 5 f f
 -. t 8 8 8"2s 2t 2
<3 <4 <&A&:# :$ :
ar   