U
    4Je)                     @   sH  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 ee eeef d
ddZd!eee ee dddZd"eeee edddZd#eee edddZd$ee ed
ddZee dddZ!ee dddZ"eee d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   H/tmp/pip-unpacked-wheel-7_167w8m/mysql/opentelemetry/baggage/__init__.pyget_all$   s    
r   )namer   r   c                 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   )r   valuer   r   c                 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   )r   r   c                 C   s   t t| d k	S N)_KEY_PATTERN	fullmatchstr)r   r   r   r   _is_valid_keyp   s    r$   )r   r   c                 C   sX   t | d}t|d d k	}t|dkrT|dd  D ]}t|d kr8d} qTq8|S )N;r      F)r#   split_VALUE_PATTERNr"   len_PROPERT_PATTERN)r   partsZis_valid_valuepropertyr   r   r   _is_valid_valuet   s    r-   )keyr   r   c                 C   s   t | ot|S r    )r$   r-   )r.   r   r   r   r   _is_valid_pair   s    r/   )N)N)N)N)N)$loggingr   rer   typesr   typingr   r   Zmysql.opentelemetry.contextr   r   r	   Z#mysql.opentelemetry.context.contextr
   Zmysql.opentelemetry.util.rer   r   r   r   __name__Z_loggerr!   r(   r*   r#   objectr   r   r   r   r   boolr$   r-   r/   r   r   r   r   <module>   s.    
