o
    ⹏iJ                     @   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   Y/home/ubuntu/veenaModal/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 )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   r   r   r   _validate_metric_name"   s   
r   c                 C   s   t | dkrdS t| duS )zRReturns true if the provided metric name conforms to the legacy validation scheme.r   FN)lenr   r   r   r   r   r   _is_valid_legacy_metric_name2   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 )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   lr   r   r   _validate_labelnameK   s   


r*   r)   c                 C   s0   t | dkrdS t| du rdS t| du S )zQReturns true if the provided label name conforms to the legacy validation scheme.r   FN)r   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 )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: )tupler*   _reserved_labelnamesr   )cls
labelnamesr)   r   r   r   _validate_labelnamesg   s   
r0   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*   r   r   )exemplarruneskvr   r   r   _validate_exemplart   s   r7   )r   recompiler   r$   r'   boolr   r   r   r   r   strr   r    r&   r*   r+   r0   r7   r   r   r   r   <module>   s"    


	