a
    h=ic                      @   s8   d Z ddlmZ ddlmZ dd ZG dd deZdS )	z7Contains _ExtensionDict class to represent extensions.
    )type_checkers)FieldDescriptorc                 C   sj   t |tstd| |js*td|j |js>td|j |j| jurftd|j|jj| jjf dS )z0Verify that the given extension handle is valid.z3HasExtension() expects an extension handle, got: %sz"%s" is not an extension.z""%s" is missing a containing_type.zKExtension "%s" extends message type "%s", but this message is of type "%s".N)
isinstancer   KeyErroris_extension	full_nameZcontaining_typeZ
DESCRIPTOR)messageextension_handle r
   x/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/google/protobuf/internal/extension_dict.py_VerifyExtensionHandle&   s"    
r   c                   @   sp   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )_ExtensionDictzDict-like container for Extension fields on proto instances.

  Note that in all cases we expect extension handles to be
  FieldDescriptors.
  c                 C   s
   || _ dS )z^
    Args:
      extended_message: Message instance for which we are the Extensions dict.
    N)_extended_message)selfZextended_messager
   r
   r   __init__G   s    z_ExtensionDict.__init__c                 C   s   t | j| | jj|}|dur&|S |jtjkr@|| j}n|jtj	kr|j
}t|dsj| jj| t|j
ddsJ d|j|j
jf |j
 }z|| jj W q ty   Y q0 n|jS | jj||}|S )z8Returns the current value of the given extension handle.N_concrete_classzAUninitialized concrete class found for field %r (message type %r))r   r   _fieldsgetlabelr   LABEL_REPEATEDZ_default_constructorcpp_typeCPPTYPE_MESSAGEmessage_typehasattrZ_FACTORYZGetPrototypegetattrr   r   Z_SetListenerZ_listener_for_childrenReferenceErrordefault_value
setdefault)r   r	   resultr   r
   r
   r   __getitem__N   s6    

z_ExtensionDict.__getitem__c                 C   sH   t || jsdS | j }|j }dd |D }dd |D }||kS )NFc                 S   s   g | ]}|j r|qS r
   r   .0fieldr
   r
   r   
<listcomp>       z)_ExtensionDict.__eq__.<locals>.<listcomp>c                 S   s   g | ]}|j r|qS r
   r    r!   r
   r
   r   r$      r%   )r   	__class__r   
ListFields)r   otherZ	my_fieldsZother_fieldsr
   r
   r   __eq__w   s    

z_ExtensionDict.__eq__c                 C   s
   | |k S Nr
   )r   r(   r
   r
   r   __ne__   s    z_ExtensionDict.__ne__c                 C   s    | j  }dd |D }t|S )Nc                 S   s   g | ]}|d  j r|qS )r   r    r!   r
   r
   r   r$      r%   z*_ExtensionDict.__len__.<locals>.<listcomp>)r   r'   len)r   fieldsZextension_fieldsr
   r
   r   __len__   s    
z_ExtensionDict.__len__c                 C   s   t dd S )Nzunhashable object)	TypeErrorr   r
   r
   r   __hash__   s    z_ExtensionDict.__hash__c                 C   s\   t | j| |jtjks$|jtjkr2td|j t	
|}||| jj|< | j  dS )zlIf extension_handle specifies a non-repeated, scalar extension
    field, sets the value of that field.
    zKCannot assign to extension "%s" because it is a repeated or composite type.N)r   r   r   r   r   r   r   r/   r   r   ZGetTypeCheckerZ
CheckValuer   Z	_Modified)r   r	   valueZtype_checkerr
   r
   r   __setitem__   s    


z_ExtensionDict.__setitem__c                 C   s   | j | d S r*   )r   ZClearExtension)r   r	   r
   r
   r   __delitem__   s    z_ExtensionDict.__delitem__c                 C   s   | j j|dS )zTries to find a known extension with the specified name.

    Args:
      name: Extension full name.

    Returns:
      Extension field descriptor.
    N)r   Z_extensions_by_namer   )r   namer
   r
   r   _FindExtensionByName   s    	z#_ExtensionDict._FindExtensionByNamec                 C   s   | j j|dS )zTries to find a known extension with the field number.

    Args:
      number: Extension field number.

    Returns:
      Extension field descriptor.
    N)r   Z_extensions_by_numberr   )r   numberr
   r
   r   _FindExtensionByNumber   s    	z%_ExtensionDict._FindExtensionByNumberc                 C   s   dd | j  D S )Nc                 s   s    | ]}|d  j r|d  V  qdS )r   Nr    )r"   fr
   r
   r   	<genexpr>   s   
z*_ExtensionDict.__iter__.<locals>.<genexpr>)r   r'   r0   r
   r
   r   __iter__   s    z_ExtensionDict.__iter__c                 C   sf   t | j| || jjvrdS |jtjkr:t| jj|S |jtj	krb| jj|}|d uo`|j
S dS )NFT)r   r   r   r   r   r   boolr   r   r   Z_is_present_in_parent)r   r	   r2   r
   r
   r   __contains__   s    z_ExtensionDict.__contains__N)__name__
__module____qualname____doc__r   r   r)   r+   r.   r1   r3   r4   r6   r8   r;   r=   r
   r
   r
   r   r   ?   s   )r   N)rA   Zgoogle.protobuf.internalr   Zgoogle.protobuf.descriptorr   r   objectr   r
   r
   r
   r   <module>   s   