o
    Y۷ib                     @   sj   d dl Z d dlZd dlmZ d dlmZmZ G dd deejeef  Z	G dd deeeef  Z
dS )    N)MutableMapping)GetterSetterc                   @   sf   e Zd ZdZdd Zdejeef dedejej	e  fddZ
dejeef dej	e fd	d
ZdS )EnvironmentGettera  Getter implementation for extracting context and baggage from environment variables.

    EnvironmentGetter creates a case-insensitive lookup from the current environment
    variables at initialization time and provides simple data access without validation.

    Per the OpenTelemetry specification, environment variables are treated as immutable
    within a process. For environments where context-carrying environment variables
    change between logical requests (e.g., AWS Lambda's _X_AMZN_TRACE_ID), create a
    new EnvironmentGetter instance at the start of each request.

    Example usage:
        getter = EnvironmentGetter()
        traceparent = getter.get({}, "traceparent")
    c                 C   s   dd t j D | _d S )Nc                 S   s   i | ]	\}}|  |qS  )lower).0kvr   r   [/home/ubuntu/vllm_env/lib/python3.10/site-packages/opentelemetry/propagators/_envcarrier.py
<dictcomp>)   s    z.EnvironmentGetter.__init__.<locals>.<dictcomp>)osenvironitemscarrier)selfr   r   r   __init__&   s   zEnvironmentGetter.__init__r   keyreturnc                 C   s@   | j | }|du rdS t|tjrt|tst|S |gS )aI  Get a value from the environment carrier for the given key.

        Args:
            carrier: Not used; maintained for interface compatibility with Getter[CarrierT]
            key: The key to look up (case-insensitive)

        Returns:
            A list with a single string value if the key exists, None otherwise.
        N)r   getr   
isinstancetypingIterablestrlist)r   r   r   valr   r   r   r   -   s   zEnvironmentGetter.getc                 C   s   t | j S )zGet all keys from the environment carrier.

        Args:
            carrier: Not used; maintained for interface compatibility with Getter[CarrierT]

        Returns:
            List of all environment variable keys (lowercase).
        )r   r   keys)r   r   r   r   r   r   @   s   	zEnvironmentGetter.keysN)__name__
__module____qualname____doc__r   r   Mappingr   OptionalListr   r   r   r   r   r   r      s    
&r   c                   @   s2   e Zd ZdZdeeef dededdfddZdS )	EnvironmentSettera  Setter implementation for building environment variable dictionaries.

    EnvironmentSetter builds a dictionary of environment variables that
    can be passed to utilities like subprocess.run()

    Example usage:
        setter = EnvironmentSetter()
        env_vars = {}
        setter.set(env_vars, "traceparent", "00-trace-id-span-id-01")
        subprocess.run(myCommand, env=env_vars)
    r   r   valuer   Nc                 C   s   |||  < dS )zSet a value in the carrier dictionary for the given key.

        Args:
            carrier: Dictionary to store environment variables
            key: The key to set (will be converted to uppercase)
            value: The value to set
        N)upper)r   r   r   r%   r   r   r   setY   s   
zEnvironmentSetter.set)r   r   r   r    r   r   r'   r   r   r   r   r$   L   s    
r$   )r   r   collections.abcr   !opentelemetry.propagators.textmapr   r   r!   r   r   r$   r   r   r   r   <module>   s    6