o
    `i                     @  s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZmZmZmZmZ ddlmZ eZeeef Zeeef Zedee f ZG dd deZdS )zCImplementation of the metadata abstraction for gRPC Asyncio Python.    )annotations)OrderedDict)
Collection)	ItemsView)Iterable)Iterator)KeysView)Sequence)
ValuesView)AnyListOptionalTupleUnion)SelfMetadatac                   @  s   e Zd ZdZdFddZedGd
dZedHddZdIddZdJddZ	dKddZ
dIddZdLddZdLdd ZdMd"d#ZdNd%d&ZdOd(d)ZdPd+d,Z	-dQdRd0d1ZdSd3d4ZdTd6d7ZdUd9d:ZdVd=d>ZdWdAdBZdXdDdEZd-S )Yr   a  Metadata abstraction for the asynchronous calls and interceptors.

    The metadata is a mapping from str -> List[str]

    Traits
        * Multiple entries are allowed for the same key
        * The order of the values by key is preserved
        * Getting by an element by key, retrieves the first mapped value
        * Supports an immutable view of the data
        * Allows partial mutation on the data without recreating the new object from scratch.
    argsMetadatumTypereturnNonec                 G  s&   t  | _|D ]
\}}| || qd S N)r   	_metadataadd)selfr   md_keymd_value r   P/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/grpc/aio/_metadata.py__init__0   s   zMetadata.__init__raw_metadatatuplec                 C  s   |r| | S |  S r   r   clsr   r   r   r   
from_tuple5   s   zMetadata.from_tuple*Union[None, Self, Iterable[MetadatumType]]r   c                 C  s.   |d u rt  S t|| r|S |r| | S |  S r   )r   
isinstancer!   r   r   r   _create=   s   
zMetadata._createkeyMetadataKeyvalueMetadataValuec                 C  s"   | j |g  | j | | d S r   )r   
setdefaultappend)r   r'   r)   r   r   r   r   L   s   zMetadata.addintc                 C  s   t tt| j S )zReturn the total number of elements that there are in the metadata,
        including multiple values for the same key.
        )summaplenr   valuesr   r   r   r   __len__P   s   zMetadata.__len__c              
   C  s>   z| j | d W S  ttfy } z|}t||d}~ww )zmWhen calling <metadata>[<key>], the first element of all those
        mapped for <key> is returned.
        r   N)r   
ValueError
IndexErrorKeyError)r   r'   e	error_msgr   r   r   __getitem__V   s   
zMetadata.__getitem__c                 C  s>   || vr|g| j |< dS | |}|g|dd | j |< dS )z_Calling metadata[<key>] = <value>
        Maps <value> to the first instance of <key>.
           N)r   get_all)r   r'   r)   current_valuesr   r   r   __setitem__`   s   
zMetadata.__setitem__c                 C  s0   |  |}|stt||dd | j|< dS )z<``del metadata[<key>]`` deletes the first mapping for <key>.r:   N)r;   r6   reprr   )r   r'   r<   r   r   r   __delitem__j   s   
zMetadata.__delitem__c                 C  s   | j |= dS )zDelete all mappings for <key>.Nr   r   r'   r   r   r   
delete_allq   s   zMetadata.delete_all+Iterator[Tuple[MetadataKey, MetadataValue]]c                 c  s.    | j  D ]\}}|D ]}||fV  qqd S r   )r   items)r   r'   r1   r)   r   r   r   __iter__u   s   zMetadata.__iter__r   c                 C  
   t | jS r   )r   r   r2   r   r   r   keysz      
zMetadata.keysr
   c                 C  rF   r   )r
   r   r2   r   r   r   r1   }   rH   zMetadata.valuesr   c                 C  rF   r   )r   r   r2   r   r   r   rD      rH   zMetadata.itemsNdefaultOptional[MetadataValue]c                 C  s"   z| | W S  t y   | Y S w r   )r6   )r   r'   rI   r   r   r   get   s
   
zMetadata.getList[MetadataValue]c                 C  s   | j |g S )zFor compatibility with other Metadata abstraction objects (like in Java),
        this would return all items under the desired <key>.
        )r   rK   rA   r   r   r   r;      s   zMetadata.get_allr1   c                 C  s   || j |< d S r   r@   )r   r'   r1   r   r   r   set_all   s   zMetadata.set_allboolc                 C  s
   || j v S r   r@   rA   r   r   r   __contains__   rH   zMetadata.__contains__otherobjectc                 C  s2   t || jr| j|jkS t |trt| |kS tS r   )r%   	__class__r   r    NotImplementedr   rP   r   r   r   __eq__   s
   
zMetadata.__eq__r   
'Metadata'c                 C  s>   t || jrtt| t|  S t |trtt| |  S tS r   )r%   rR   r   r    rS   rT   r   r   r   __add__   s
   
zMetadata.__add__strc                 C  s   t | }d| jj|S )Nz
{0}({1!r}))r    formatrR   __name__)r   viewr   r   r   __repr__   s   zMetadata.__repr__)r   r   r   r   )r   r    )r   r$   r   r   )r'   r(   r)   r*   r   r   )r   r-   )r'   r(   r   r*   )r'   r(   r   r   )r   rC   )r   r   )r   r
   )r   r   r   )r'   r(   rI   rJ   r   rJ   )r'   r(   r   rL   )r'   r(   r1   rL   r   r   )r'   r(   r   rN   )rP   rQ   r   rN   )rP   r   r   rV   )r   rX   )rZ   
__module____qualname____doc__r   classmethodr#   r&   r   r3   r9   r=   r?   rB   rE   rG   r1   rD   rK   r;   rM   rO   rU   rW   r\   r   r   r   r   r   #   s2    

















N)r_   
__future__r   collectionsr   collections.abcr   r   r   r   r   r	   r
   typingr   r   r   r   r   typing_extensionsr   rX   r(   bytesr*   r   MetadataTyper   r   r   r   r   <module>   s"   