
    h9                     D    d Z ddlmZ ddlmZ d Z G d de          ZdS )z7Contains _ExtensionDict class to represent extensions.
    )type_checkers)FieldDescriptorc           	      L   t          |t                    st          d|z            |j        st          d|j        z            |j        st          d|j        z            |j        | j        ur2t          d|j        d|j        j        d| j        j        d          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.zExtension "z" extends message type "z ", but this message is of type "z".N)
isinstancer   KeyErroris_extension	full_namecontaining_type
DESCRIPTOR)messageextension_handles     i/var/www/html/prod/cognitive/venv/lib/python3.11/site-packages/google/protobuf/internal/extension_dict.py_VerifyExtensionHandler      s     
$o	6	6 %
H#$ % % % 
	& M
.1A1KK
L
LL		) 1
7%/0 1 1 1 %W-???
($...$4>>>&000	2 3 3 3 @?    c                   Z    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z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                     || _         dS )z^
    Args:
      extended_message: Message instance for which we are the Extensions dict.
    N)_extended_message)selfextended_messages     r   __init__z_ExtensionDict.__init__0   s    
 .Dr   c                    t          | j        |           | j        j                            |          }||S |j        t
          j        k    r|                    | j                  }n|j        t
          j	        k    r|j
        }t          |d          sddlm} |                    |           t          |j
        d          s ddlm} |                    |j
                   |j
                                        }	 |                    | j        j                   n# t$          $ r Y nw xY w|j        S | j        j                            ||          }|S )z8Returns the current value of the given extension handle.N_concrete_classr   )message_factory)r   r   _fieldsgetlabelr   LABEL_REPEATED_default_constructorcpp_typeCPPTYPE_MESSAGEmessage_typehasattrgoogle.protobufr   GetMessageClassr   _SetListener_listener_for_childrenReferenceErrordefault_value
setdefault)r   r   resultr"   r   s        r   __getitem__z_ExtensionDict.__getitem__7   s    413CDDD#+//0@AAFm!???44T5KLLff		"o&E	E	E%2l\#455 6333333''555%24EFF G333333''(8(EFFF,<<>>fD2IJJJJ   
 ++ #+66&" "F Ms   ?D 
D,+D,c                     t          || j                  sdS | j                                        }|j                                        }d |D             }d |D             }||k    S )NFc                      g | ]}|j         	|S  r   .0fields     r   
<listcomp>z)_ExtensionDict.__eq__.<locals>.<listcomp>h   s     DDD51CDDDDr   c                      g | ]}|j         	|S r/   r0   r1   s     r   r4   z)_ExtensionDict.__eq__.<locals>.<listcomp>i   s     JJJeu7IJEJJJr   )r   	__class__r   
ListFields)r   other	my_fieldsother_fieldss       r   __eq__z_ExtensionDict.__eq__`   sw    eT^,, U&1133I*5577L EDIDDDIJJ|JJJL$$r   c                     | |k     S Nr/   )r   r8   s     r   __ne__z_ExtensionDict.__ne__m   s    u}r   c                 j    | j                                         }d |D             }t          |          S )Nc                 ,    g | ]}|d          j         |S )r   r0   r1   s     r   r4   z*_ExtensionDict.__len__.<locals>.<listcomp>s   s$    KKK%U1X5JKKKKr   )r   r7   len)r   fieldsextension_fieldss      r   __len__z_ExtensionDict.__len__p   s9    #..00FKK6KKK   r   c                      t          d          )Nzunhashable object)	TypeErrorr   s    r   __hash__z_ExtensionDict.__hash__v   s    
'
(
((r   c                 P   t          | j        |           |j        t          j        k    s|j        t          j        k    rt          d|j        z            t          j
        |          }|                    |          | 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!   rF   r	   r   GetTypeChecker
CheckValuer   	_Modified)r   r   valuetype_checkers       r   __setitem__z_ExtensionDict.__setitem__}   s    
 413CDDD/"@@@!_%DDD.89: : : !/0@AAL 	&& 	"#34$$&&&&&r   c                 :    | j                             |           d S r=   )r   ClearExtension)r   r   s     r   __delitem__z_ExtensionDict.__delitem__   s     ))*:;;;;;r   c                 t    | j         j        }|j        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   r   filepool_extensions_by_namer   )r   name
descriptor
extensionss       r   _FindExtensionByNamez#_ExtensionDict._FindExtensionByName   s5     '2J%9*EJ>>$%%%r   c                 t    | j         j        }|j        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   r   rT   rU   _extensions_by_numberr   )r   numberrX   rY   s       r   _FindExtensionByNumberz%_ExtensionDict._FindExtensionByNumber   s5     '2J%;JGJ>>&$'''r   c                 H    d | j                                         D             S )Nc              3   @   K   | ]}|d          j         |d          V  dS )r   Nr0   )r2   fs     r   	<genexpr>z*_ExtensionDict.__iter__.<locals>.<genexpr>   sE       " "Qt "AaD " " " " " "r   )r   r7   rG   s    r   __iter__z_ExtensionDict.__iter__   s1    " "$0;;== " " " "r   c                 P   t          | j        |           || j        j        vrdS |j        t          j        k    r,t          | j        j                            |                    S |j        t          j	        k    r*| j        j                            |          }|d uo|j
        S dS )NFT)r   r   r   r   r   r   boolr   r    r!   _is_present_in_parent)r   r   rM   s      r   __contains__z_ExtensionDict.__contains__   s    413CDDDt5===U!???$(0445EFFGGG O$CCC$,001ABBe$>5#>>4r   N)__name__
__module____qualname____doc__r   r,   r;   r>   rD   rH   rO   rR   rZ   r^   rc   rg   r/   r   r   r   r   (   s         . . .' ' 'R% % %  ! ! !) ) )' ' '*< < <& & &( ( (" " "
    r   r   N)rk   google.protobuf.internalr   google.protobuf.descriptorr   r   objectr   r/   r   r   <module>ro      s     3 2 2 2 2 2 6 6 6 6 6 63 3 32Z Z Z Z ZV Z Z Z Z Zr   