o
    :Di                     @   sl   d dl mZ d dlmZmZ dZ	 dd Zdd Zded	efd
dZ	ded	efddZ
ded	efddZdS )   )floatToGoString)_is_valid_legacy_labelname_is_valid_legacy_metric_namez:application/openmetrics-text; version=1.0.0; charset=utf-8c                 C   s^   | j dkr|jdrdS | j dv r|jdrdS | j dv r%|jds+|j| jkr-dS dS )Ncounter_totalTgaugehistogram_bucket	histogramF)typenameendswith)metricsample r   a/var/www/Datamplify/venv/lib/python3.10/site-packages/prometheus_client/openmetrics/exposition.py_is_valid_exemplar_metric   s   "r   c                 C   s  g }|   D ]}z|j}|dt|t|j |dt| d|j d |jr;|dt| d|j d |j	D ]}t
|jsRt|j}|jrQ|d7 }nd}|jrjt|j }|dd	d
 |D 7 }|rrd| d }|jrt||std|j ddddd
 t|jj D }|jjdurd|t|jj|jj}nd|t|jj}nd}d}	|jdurd|j }	t
|jr|d|j|t|j|	| q>|d|t|j|	| q>W q ty }
 z
|
jpd|f |
_ d}
~
ww |d d|dS )zHReturns the metrics from the registry in latest text format as a string.z# HELP {} {}
z# TYPE  
z# UNIT z,  ,c                 S   s$   g | ]\}}d  t|t|qS ){}="{}")formatescape_label_name_escape.0kvr   r   r   
<listcomp>-   s
    z#generate_latest.<locals>.<listcomp>{}zMetric z8 has exemplars, but is not a histogram bucket or counterz{{{0}}}c              	   S   s4   g | ]\}}d  ||ddddddqS )r   \\\r   \n"\")r   replacer   r   r   r   r   7   s
    Nz # {} {} {}z # {} {}z{}{} {}{}{}
z
{} {}{}{}
)r   z# EOF
zutf-8)collectr   appendr   escape_metric_namer   documentationr
   unitsamplesr   labelssorteditemsjoinexemplarr   
ValueError	timestampr   value	Exceptionargsencode)registryoutputr   mnameslabelstrr/   r-   exemplarstrr3   	exceptionr   r   r   generate_latest   s   







7
r?   r;   returnc                 C      t | r| S dt| S )z|Escapes the metric name and puts it in quotes iff the name does not
    conform to the legacy Prometheus character set.
    "{}")r   r   r   r;   r   r   r   r)   a      r)   c                 C   rA   )z{Escapes the label name and puts it in quotes iff the name does not
    conform to the legacy Prometheus character set.
    rB   )r   r   r   rC   r   r   r   r   j   rD   r   c                 C   s   |  dd dd ddS )zOPerforms backslash escaping on backslash, newline, and double-quote characters.r!   r"   r   r#   r$   r%   )r&   rC   r   r   r   r   s   s   r   N)utilsr   
validationr   r   CONTENT_TYPE_LATESTr   r?   strr)   r   r   r   r   r   r   <module>   s   
J		