
    Xh                     b    d dl mZ d dlmZmZ dZ	 d Zd ZdedefdZ	dedefd	Z
dedefd
Zy)   )floatToGoString)_is_valid_legacy_labelname_is_valid_legacy_metric_namez:application/openmetrics-text; version=1.0.0; charset=utf-8c                 4   | j                   dk(  r|j                  j                  d      ry| j                   dv r|j                  j                  d      ry| j                   dv r|j                  j                  d      s|j                  | j                  k(  ryy)Ncounter_totalTgaugehistogram_bucket	histogramF)typenameendswith)metricsamples     \/var/www/html/myenv/lib/python3.12/site-packages/prometheus_client/openmetrics/exposition.py_is_valid_exemplar_metricr      sx    {{iFKK$8$8$B{{'(V[[-A-A)-L{{{#(<(<Y(G6;;Z`ZeZeKe    c                    g }| j                         D ]  }	 |j                  }|j                  dj                  t	        |      t        |j                                     |j                  dt	        |       d|j                   d       |j                  r+|j                  dt	        |       d|j                   d       |j                  D ]  }t        |j                        s't	        |j                        }|j                  r|dz  }nd}|j                  rlt        |j                  j                               }|dj                  |D cg c])  \  }}d	j                  t        |      t        |            + c}}      z  }|rd
|z   dz   }|j                   rNt#        ||      st%        d|j                   d      dj                  dj                  t        |j                   j                  j                               D cg c]G  \  }}d	j                  ||j'                  dd      j'                  dd      j'                  dd            I c}}            }	|j                   j(                  Edj                  |	t+        |j                   j,                        |j                   j(                        }
n2dj                  |	t+        |j                   j,                              }
nd}
d}|j(                  d|j(                   }t        |j                        rC|j                  dj                  |j                  |t+        |j,                        ||
             |j                  dj                  |t+        |j,                        ||
               |j                  d       dj                  |      j3                  d      S c c}}w c c}}w # t.        $ r}|j0                  xs d|fz   |_         d}~ww xY w)zHReturns the metrics from the registry in latest text format as a string.z# HELP {} {}
z# TYPE  
z# UNIT z,  ,z{}="{}"{}zMetric z8 has exemplars, but is not a histogram bucket or counterz{{{0}}}\\\\n"\"Nz # {} {} {}z # {} {}z{}{} {}{}{}
z
{} {}{}{}
)r   z# EOF
zutf-8)collectr   appendformatescape_metric_name_escapedocumentationr   unitsamplesr   labelssorteditemsjoinescape_label_nameexemplarr   
ValueErrorreplace	timestampr   value	Exceptionargsencode)registryoutputr   mnameslabelstrr*   kvr(   exemplarstrr0   	exceptions                r   generate_latestr>      s   F""$ A@	KKEMM*11"5)763G3G+HJ KMMG$6u$=#>a}BOP{{(:5(A'B!FKK=PRST^^ 63AFF;1!&&9Hxx D(!H88"188>>#34E )./ $1 #))-a0'!*> /!0 0H "X~3H::4VQ?(76;;-?w)xyy&--chh )/qzz/@/@/F/F/H(IK $1 #))qyyu5==dEJRRSVX]^` K/L MF zz++7&3&:&:"+AJJ,<,<=JJ00' '1&7&7"+AJJ,<,<='
 #%K	;;*"#AKK= 1I/7MM/"8"8 '0!##  MM-"6"6 '0!#	# c6AF MM)776?!!'**c/KD  	'nn5&BIN	s9   D9O.O?BOAOEOO	P'PPr8   returnc                 P    t        |       r| S dj                  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$   r8   s    r   r#   r#   a   s$     $A&==$$r   c                 P    t        |       r| S dj                  t        |             S )z{Escapes the label name and puts it in quotes iff the name does not
    conform to the legacy Prometheus character set.
    rA   )r   r"   r$   rB   s    r   r,   r,   j   s$     "!$==$$r   c                 f    | j                  dd      j                  dd      j                  dd      S )zOPerforms backslash escaping on backslash, newline, and double-quote characters.r   r   r   r   r   r   )r/   rB   s    r   r$   r$   s   s-    99T5!))$6>>sEJJr   N)utilsr   
validationr   r   CONTENT_TYPE_LATESTr   r>   strr#   r,   r$    r   r   <module>rJ      sc    $ S  8G+T%# %# %% % %Ks Ks Kr   