o
    :D©iO  ã                   @   sÄ   d dl Z d dlZe d¡Ze d¡Ze d¡Zdefdd„Zeƒ adefdd	„Z	d
d„ Z
dd„ Zdeddfdd„Zdedefdd„Zdeddfdd„Zdd„ Zdedefdd„Zdd„ Zdd„ ZdS )é    Nz^[a-zA-Z_:][a-zA-Z0-9_:]*$z^[a-zA-Z_][a-zA-Z0-9_]*$z^__.*$Úreturnc                   C   s   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© r   r   úU/var/www/Datamplify/venv/lib/python3.10/site-packages/prometheus_client/validation.pyÚ_init_legacy_validation	   s   r   c                   C   s   t S )z;Return the current status of the legacy validation setting.©Ú_legacy_validationr   r   r   r   Úget_legacy_validation   s   r   c                   C   ó   da dS )zEDisable legacy name validation, instead allowing all UTF8 characters.FNr   r   r   r   r   Údisable_legacy_validation   ó   r   c                   C   r   )zFEnable legacy name validation instead of allowing all UTF8 characters.TNr   r   r   r   r   Úenable_legacy_validation   r   r   Únamec                 C   sR   | st dƒ‚trt | ¡st d|  ƒ‚z|  d¡ W dS  ty(   t d|  ƒ‚w )z©Raises 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   r   r   r   Ú_validate_metric_name#   s   
ÿr   c                 C   s   t  | ¡duS )zRReturns true if the provided metric name conforms to the legacy validation scheme.N)r   r   r   r   r   r   Ú_is_valid_legacy_metric_name4   s   r   Útokc                 C   sv   | st d|  ƒ‚| d dko| d dk}|rtr%t | ¡s#t d|  ƒ‚dS z|  d¡ W dS  ty:   t d|  ƒ‚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    Úquotedr   r   r   Ú!_validate_metric_label_name_token9   s   
ÿr%   c                 C   sz   t ƒ rt | ¡std|  ƒ‚t | ¡rtd|  ƒ‚dS z|  d¡ W n ty/   td|  ƒ‚w t | ¡r;td|  ƒ‚dS )z¨Raises 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   ©Úlr   r   r   Ú_validate_labelnameL   s   

ÿÿ
ÿr)   r(   c                 C   s    t  | ¡du r	dS t | ¡du S )zQReturns true if the provided label name conforms to the legacy validation scheme.NF)r#   r   r&   r'   r   r   r   Ú_is_valid_legacy_labelname_   s   r*   c                 C   s4   t |ƒ}|D ]}t|ƒ || jv rtd| ƒ‚q|S )z°Raises 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: )Útupler)   Ú_reserved_labelnamesr   )ÚclsÚ
labelnamesr(   r   r   r   Ú_validate_labelnamesf   s   
ÿr/   c                 C   sJ   d}|   ¡ D ]\}}t|ƒ |t|ƒ7 }|t|ƒ7 }q|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)Úitemsr)   Úlenr   )ÚexemplarÚrunesÚkÚvr   r   r   Ú_validate_exemplars   s   ÿr7   )r   ÚreÚcompiler   r#   r&   Úboolr   r   r   r   r   Ústrr   r   r%   r)   r*   r/   r7   r   r   r   r   Ú<module>   s"    


