o
    #f)                  	   @   sd  d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlmZ d dlmZmZmZ e
dZeeZeeZeeZeeZ		dd
ee deeef fddZdded
ee dee fddZddeded
ee defddZdded
ee defddZdd
ee defddZdede fddZ!dede fddZ"dedede fddZ#d	S )     )	getLogger)compile)MappingProxyType)MappingOptional)
create_key	get_value	set_value)Context)_BAGGAGE_PROPERTY_FORMAT_KEY_FORMAT_VALUE_FORMATbaggageNcontextreturnc                 C   s&   t t| d}t|trt|S ti S )zReturns the name/value pairs in the Baggage

    Args:
        context: The Context to use. If not set, uses current Context

    Returns:
        The name/value pairs in the Baggage
    r   )r   _BAGGAGE_KEY
isinstancedictr   )r   r    r   Z/home/ubuntu/dev/venv/lib/python3.10/site-packages/mysql/opentelemetry/baggage/__init__.pyget_all$   s   
r   namec                 C   s   t |d| S )a=  Provides access to the value for a name/value pair in the
    Baggage

    Args:
        name: The name of the value to retrieve
        context: The Context to use. If not set, uses current Context

    Returns:
        The value associated with the given name, or null if the given name is
        not present.
    r   )r   get)r   r   r   r   r   get_baggage5   s   r   valuec                 C   s$   t t|d}||| < tt||dS )zSets a value in the Baggage

    Args:
        name: The name of the value to set
        value: The value to set
        context: The Context to use. If not set, uses current Context

    Returns:
        A Context with the value updated
    r   )r   r   r	   r   )r   r   r   r   r   r   r   set_baggageD   s   r   c                 C   s(   t t|d}|| d tt||dS )zRemoves a value from the Baggage

    Args:
        name: The name of the value to remove
        context: The Context to use. If not set, uses current Context

    Returns:
        A Context with the name/value removed
    r   N)r   r   popr	   r   )r   r   r   r   r   r   remove_baggageT   s   
r   c                 C   s   t ti | dS )zRemoves all values from the Baggage

    Args:
        context: The Context to use. If not set, uses current Context

    Returns:
        A Context with all baggage entries removed
    r   )r	   r   r   r   r   r   cleard   s   	r   c                 C   s   t t| d uS N)_KEY_PATTERN	fullmatchstr)r   r   r   r   _is_valid_keyp   s   r$   c                 C   sZ   t | d}t|d d u}t|dkr+|dd  D ]}t|d u r*d} |S q|S )N;r      F)r#   split_VALUE_PATTERNr"   len_PROPERT_PATTERN)r   partsis_valid_valuepropertyr   r   r   _is_valid_valuet   s   r.   keyc                 C   s   t | ot|S r    )r$   r.   )r/   r   r   r   r   _is_valid_pair   s   r0   r    )$loggingr   rer   typesr   typingr   r   mysql.opentelemetry.contextr   r   r	   #mysql.opentelemetry.context.contextr
   mysql.opentelemetry.util.rer   r   r   r   __name___loggerr!   r(   r*   r#   objectr   r   r   r   r   boolr$   r.   r0   r   r   r   r   <module>   s2   

  