o
    ˷eo                     @   s
  d Z dZddlZddlZddlZddl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 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 ede G dd deZejG dd deejZejG dd deejZ ejG dd deejZ!G dd  d eZ"G d!d" d"eZ#G d#d$ d$eZ$G d%d& d&eZ%G d'd( d(eZ&G d)d* d*eZ'G d+d, d,eZ(ejG d-d. d.ejZ)e"d/d0e$e#d1d2ge$e#d3d4ge$d5e#d6d7gid8e%d9d5d:fd;e'd<d=fgd>d8e%d9d5d?fd;e'd<d@fdAe&dBdCfgdDd8e%d9d5dEfdFe&d<dGfgdHdIe$e#dJdKge$e#dLdMge$d5e#dNdOgid8e%d9d5dPfd;e'd<dQfgd>d8e%d9d5dRfd;e'd<dSfdAe&dBdCfgdDd8e%d9d5dTfdFe&d<dGfgdUZ*e"dVd0dWe$e#dXdYge$e#dZd[ge$d5e#d\d]gid8e%d9d5d^fd;e'd<d_fgd>d8e%d9d5d`fd;e'd<dafdAe&dBdCfgdDd8e%d9d5dbfdFe&d<dGfgdce(dddefgdfid/dggdggdhZ+e,dikre-  dS dS )jz*Tests for google.protobuf.descriptor_pool.z"matthewtoia@google.com (Matt Toia)    N)unittest_import_pb2)unittest_import_public_pb2)unittest_pb2)descriptor_pb2)api_implementation)descriptor_pool_test1_pb2)descriptor_pool_test2_pb2)factory_test1_pb2)factory_test2_pb2)file_options_test_pb2)more_messages_pb2)no_package_pb2)testing_refleaks)
descriptor)descriptor_database)descriptor_pool)message_factory)symbol_databaseerrorc                   @   s   e 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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 )0DescriptorPoolTestBasec                 C   s   d}| j |}| |tj | ||j | d|j | d|j	 d}| j |}| |tj | ||j | d|j | d|j	 d S )N,google/protobuf/internal/factory_test1.protogoogle.protobuf.python.internalFactory1Message,google/protobuf/internal/factory_test2.protoFactory2Message)
poolFindFileByNameassertIsInstancer   FileDescriptorassertEqualnamepackageassertInmessage_types_by_name)selfname1
file_desc1name2
file_desc2 r)   d/var/www/ideatree/venv/lib/python3.10/site-packages/google/protobuf/internal/descriptor_pool_test.pytestFindFileByNameB   s   z)DescriptorPoolTestBase.testFindFileByNamec                 C   <   |  t | jd W d    d S 1 sw   Y  d S NDoes not exist)assertRaisesKeyErrorr   r   r$   r)   r)   r*   testFindFileByNameFailureQ      "z0DescriptorPoolTestBase.testFindFileByNameFailurec           	      C   s  | j d}| |tj | d|j | d|j | d|j	 | j d}| |tj | d|j | d|j | d|j	 | j d}| |tj | d|j | j d	}| |tj | d|j | j d
}| |tj | d|j t
 d	sJ t
 dsJ t
 d
sJ | j d}| |tj | d|j | j d}| |tj | d|j | j d}| |tj | d|j | t| j jd d S )N/google.protobuf.python.internal.Factory1Messager   r   r   /google.protobuf.python.internal.Factory2Messager   r   -google.protobuf.python.internal.another_field>google.protobuf.python.internal.Factory2Message.one_more_fieldprotobuf_unittest.TestServicegoogle/protobuf/unittest.proto:google.protobuf.python.internal.Factory1Message.list_valuez1google.protobuf.python.internal.FACTORY_1_VALUE_0z"protobuf_unittest.TestAllTypes.FOOz:google.protobuf.python.internal.Factory1Message.none_field)r   FindFileContainingSymbolr   r   r   r   r    r!   r"   r#   r   Defaultr/   r0   )	r$   r&   r(   
file_desc3
file_desc4
file_desc5
file_desc6
file_desc7
file_desc8r)   r)   r*   testFindFileContainingSymbolU   s   z3DescriptorPoolTestBase.testFindFileContainingSymbolc                 C   r,   r-   )r/   r0   r   r;   r1   r)   r)   r*   #testFindFileContainingSymbolFailure   r3   z:DescriptorPoolTestBase.testFindFileContainingSymbolFailurec           	      C   s  | j d}| |tj | d|j | d|j | d |j | 	|j
 |jd }| d|j | ||j |jd }| d|j | ||j | ||jd j | ||jd j | j d}| |tj | d	|j | d|j | |j |jd }| d
|j | ||j |jd }| d|j | ||j | ||jd j | ||jd j | |jd j | d|jd j | |jd j | d|jd j | |jd j | d|jd j | |jd j | 	|jd j | |jd j | d|jd j | j d}| || | |jd j | d|jd j | dt|j | dt|j | dt|jd j dD ]}| |jd |j| j | |j| |jd j qZd S )Nr4   r   r   NestedFactory1MessageNestedFactory1Enumnested_factory_1_messagenested_factory_1_enumr5   r   NestedFactory2MessageNestedFactory2Enumnested_factory_2_messagenested_factory_2_enumint_with_defaulti  double_with_defaultg{G#@string_with_defaultzhello worldbool_with_defaultenum_with_default   zEgoogle.protobuf.python.internal.Factory2Message.NestedFactory2Messagebytes_with_defaults   a c   )	oneof_intoneof_string)r   FindMessageTypeByNamer   r   
Descriptorr   r    	full_namecontaining_typeassertFalsehas_optionsnested_types
enum_typesfields_by_namemessage_type	enum_typeassertIsNone
assertTruehas_default_valuedefault_valuelenoneofsoneofs_by_namefieldscontaining_oneofr"   )	r$   msg1nested_msg1nested_enum1msg2nested_msg2nested_enum2msg3r    r)   r)   r*   testFindMessageTypeByName   s   











z0DescriptorPoolTestBase.testFindMessageTypeByNamec                 C   s   |  t| jjd |  t| jjd t dkrt}nt}|  || jj	d |  || jj
d |  || jjd |  || jjd |  || jjd |  || jjd |  || jjd |  || jjd t dkrmt}|  || jjd d S )N pythonr   )r/   	TypeErrorr   FindExtensionByNumberr0   FindMethodByNamer   TypeAttributeErrorrW   FindFieldByNameFindExtensionByNameFindEnumTypeByNameFindOneofByNameFindServiceByNamer;   r   )r$   
error_typer)   r)   r*   testFindTypeErrors   s    z)DescriptorPoolTestBase.testFindTypeErrorsc                 C   r,   r-   )r/   r0   r   rW   r1   r)   r)   r*    testFindMessageTypeByNameFailure  r3   z7DescriptorPoolTestBase.testFindMessageTypeByNameFailurec                 C   s  | j d}| |tj | d|jd j | d|jd j | |j	 | j d}| |tj | d|jd j | d|jd j | j d	}| |tj | d|jd
 j | d|jd j | j d}| |tj | d|jd j | d|jd j d S )Nz,google.protobuf.python.internal.Factory1Enumr   FACTORY_1_VALUE_0rR   FACTORY_1_VALUE_1zBgoogle.protobuf.python.internal.Factory1Message.NestedFactory1EnumNESTED_FACTORY_1_VALUE_0NESTED_FACTORY_1_VALUE_1z,google.protobuf.python.internal.Factory2EnumFACTORY_2_VALUE_0FACTORY_2_VALUE_1zBgoogle.protobuf.python.internal.Factory2Message.NestedFactory2EnumNESTED_FACTORY_2_VALUE_0NESTED_FACTORY_2_VALUE_1)
r   r|   r   r   EnumDescriptorr   values_by_namenumberr[   r\   )r$   enum1rm   enum2rp   r)   r)   r*   testFindEnumTypeByName
  sB   z-DescriptorPoolTestBase.testFindEnumTypeByNamec                 C   r,   r-   )r/   r0   r   r|   r1   r)   r)   r*   testFindEnumTypeByNameFailure(  r3   z4DescriptorPoolTestBase.testFindEnumTypeByNameFailurec                 C   sr   | j d}| |jd | |j|j | |j | t	 | j d W d    d S 1 s2w   Y  d S )Nr:   
list_valuer.   )
r   rz   r   r    labelLABEL_REPEATEDr[   r\   r/   r0   )r$   fieldr)   r)   r*   testFindFieldByName,  s   "z*DescriptorPoolTestBase.testFindFieldByNamec                 C   sV   | j d}| |jd | t | j d W d    d S 1 s$w   Y  d S )Nz;google.protobuf.python.internal.Factory2Message.oneof_fieldoneof_fieldr.   )r   r}   r   r    r/   r0   )r$   oneofr)   r)   r*   testFindOneofByName6  s   "z*DescriptorPoolTestBase.testFindOneofByNamec                 C   s~   | j d}| |jd | j d}| |jd | |jd | t | j d W d    d S 1 s8w   Y  d S )Nr7   one_more_fieldr6   another_field  r.   )r   r{   r   r    r   r/   r0   rz   )r$   	extensionr)   r)   r*   testFindExtensionByName=  s   "z.DescriptorPoolTestBase.testFindExtensionByNamec                 C   s   | j d}| j d}|jd }| j d}|jd }| j |}t||g}| |t| |d | j |}| |t| d S )Nr4   r5   r   r   r   unexpected_element)r   rW   extensions_by_namer   FindAllExtensionssetr   append)r$   factory1_messagefactory2_messager   factory_test2r   
extensionsexpected_extension_numbersr)   r)   r*   testFindAllExtensionsJ  s"   


z,DescriptorPoolTestBase.testFindAllExtensionsc                 C   s   | j d}| j d | j |d}| |jd | j |d}| |jd | t | j |d}W d    d S 1 s@w   Y  d S )Nr4   r     r   r   r   i )r   rW   r   rv   r   r    r/   r0   )r$   r   r   r)   r)   r*   testFindExtensionByNumber`  s   "z0DescriptorPoolTestBase.testFindExtensionByNumberc                 C   s   |  t | jd W d    n1 sw   Y  |  t | jd W d    n1 s1w   Y  |  t | jd W d    d S 1 sMw   Y  d S )Nr6   r7   r:   )r/   r0   r   rz   r{   r1   r)   r)   r*   testExtensionsAreNotFieldsp  s   "z1DescriptorPoolTestBase.testExtensionsAreNotFieldsc                 C   s   | j d}| |jd | t | j d W d    n1 s#w   Y  | j d}| |j| | t | j d W d    d S 1 sLw   Y  d S )Nr8   r.   z!protobuf_unittest.TestService.Fooz*protobuf_unittest.TestService.Doesnotexist)	r   r~   r   rY   r/   r0   rw   assertIscontaining_service)r$   servicemethodr)   r)   r*   testFindServicez  s   "z&DescriptorPoolTestBase.testFindServicec                 C   s8   t  }t|| _|| j || j |   d S N)	r   DescriptorDatabaser   DescriptorPoolr   Addfactory_test1_fdfactory_test2_fdrr   )r$   dbr)   r)   r*   testUserDefinedDB  s
   z(DescriptorPoolTestBase.testUserDefinedDBc                 C   s   t | trt dkrd S t | _| j| j	 }| j| j
	 }| |jd | |jd |   | jtjj}|jd jd }| |jd d S )Nrt   r   r   class	int_fieldjson_int)
isinstance#SecondaryDescriptorFromDescriptorDBr   rx   r   r   r   AddSerializedFiler   SerializeToStringr   r   r    rr   r   
DESCRIPTORserialized_pbr#   r_   	json_name)r$   file1file2	file_jsonr   r)   r)   r*   testAddSerializedFile  s,   

z,DescriptorPoolTestBase.testAddSerializedFilec                    s    fdd}|t j t jd} |t j || t tr+t	
 dkr+dS tjt jj} j|  jd}|| dS )z:Test the default value of enums which don't start at zero.c                    s&   | j d jd j} |tjj d S )NDescriptorPoolTest1nested_enum)r#   r_   re   r   r   r   BETA)file_descriptorre   r1   r)   r*   _CheckDefaultValue  s   zGDescriptorPoolTestBase.testEnumDefaultValue.<locals>._CheckDefaultValue4google/protobuf/internal/descriptor_pool_test1.protort   N)r   r   r   r<   r   r   r   r   r   r   rx   r   FileDescriptorProto
FromStringr   r   )r$   r   r   descriptor_protor)   r1   r*   testEnumDefaultValue  s$   


z+DescriptorPoolTestBase.testEnumDefaultValuec                    s   fdd  fdd}|t   t }|tjtj	j
 |tjtj	j
 |tjt j	j
 t||t jj	j}||  dS )z0Check the value returned by non-existent fields.c                    s     | |  | | d S r   )r   r   )valueexpected_valueexpected_typer1   r)   r*   _CheckValueAndType  s   zTDescriptorPoolTestBase.testDefaultValueForCustomMessages.<locals>._CheckValueAndTypec                    s   zt }W n ty   t}Y nw zt}W n ty   t}Y nw  | jdt  | jd|tf  | jdttf  | j	dttf  | j
dt  | jd|  | jdt  | j| jt d S )Nr   Frs       )long	NameErrorintunicodestroptional_int32optional_uint64optional_floatfloatoptional_doubleoptional_boolbooloptional_stringoptional_bytesbytesoptional_nested_enumFOO)msgint64unicode_type)r   r)   r*   _CheckDefaultValues  s$   zUDescriptorPoolTestBase.testDefaultValueForCustomMessages.<locals>._CheckDefaultValuesN)r   TestAllTypesr   r   r   r   r   r   r   r   r   r   r   MessageFactoryGetPrototyperW   rY   )r$   r   r   message_classr)   )r   r$   r*   !testDefaultValueForCustomMessages  s&   



z8DescriptorPoolTestBase.testDefaultValueForCustomMessagesc                 C   sF   t | trt dkrd S tjdd}| j| | j|	  d S )Nrt   some/file.protor    )
r   r   r   rx   r   r   r   r   r   r   )r$   	file_descr)   r)   r*   testAddFileDescriptor  s   
z,DescriptorPoolTestBase.testAddFileDescriptorc                 C   s   t | trt dkrd S tjtjj	}tjt
jj	}tjtjj	}| j| | j| | j| t| | j t| | j d S )Nrt   )r   r   r   rx   r   r   r   r   r   r   r   r   r   r   
TEST1_FILE	CheckFile
TEST2_FILE)r$   more_messages_desc
test1_desc
test2_descr)   r)   r*   testComplexNesting  s"   
z)DescriptorPoolTestBase.testComplexNestingc                 C   sd  t | trt dkrd S tjtjj	}t
|}d|_t dkr%d S t
| j}tj}||jd  ||jd  ||jd  ||jd  || tjdd-}td	 || | t| | |d
 jt | dt |d
 j! W d    n1 sw   Y  |"|j | #t$ |"|j W d    d S 1 sw   Y  d S )Nrt   
other_filer   ForeignEnumTestServiceoptional_int32_extensionT)recordalwaysr   z)Conflict register for file "other_file": )%r   r   r   rx   r   r   r   r   r   r   copydeepcopyr    r   _AddDescriptorr#   _AddEnumDescriptorenum_types_by_name_AddServiceDescriptorservices_by_name_AddExtensionDescriptorr   r   warningscatch_warningssimplefilterrc   rf   r   categoryRuntimeWarningr"   r   messager   r/   ru   )r$   unittest_fdconflict_fdr   r   wr)   r)   r*   testConflictRegister  sL   




"z+DescriptorPoolTestBase.testConflictRegisterN)__name__
__module____qualname__r+   r2   rC   rD   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r)   r)   r)   r*   r   @   s0    FR

 &r   c                   @      e Zd Zdd Zdd ZdS )DefaultDescriptorPoolTestc                 C   s2   t  | _tjtjj| _	tjt
jj| _d S r   )r   r<   r   r   r   r   r	   r   r   r   r
   r   r1   r)   r)   r*   setUp/  s   

zDefaultDescriptorPoolTest.setUpc                 C   s   |  | jdtj |  | jdtjj |  | jdtjjjd  |  | j	dtj
j |  | jdtjjd  |  | jdtjjjd	  |  | jd
tjjd  d S )Nr9   protobuf_unittest.TestAllTypesz-protobuf_unittest.TestAllTypes.optional_int32r   protobuf_unittest.ForeignEnumz*protobuf_unittest.optional_int32_extensionr   z*protobuf_unittest.TestAllTypes.oneof_fieldr   r8   r   )r   r   r   r   r   rW   r   rz   r_   r|   r   r{   r   r}   rh   r~   r  r1   r)   r)   r*   testFindMethods6  s@   






z)DefaultDescriptorPoolTest.testFindMethodsN)r  r  r  r  r  r)   r)   r)   r*   r  ,  s    r  c                   @   s   e Zd Zdd ZdS )CreateDescriptorPoolTestc                 C   s   t  | _tjtjj| _	tjt
jj| _| j| j	 | j| j | jtjtjj | jtjtjj | jtjtjj | jtjtjj d S r   )r   r   r   r   r   r   r	   r   r   r   r
   r   r   r   r   r   r   r1   r)   r)   r*   r  S  s*   

zCreateDescriptorPoolTest.setUpN)r  r  r  r  r)   r)   r)   r*   r  P  s    r  c                   @   r  )r   c                 C   s   t jtjj| _t jtjj| _t	
 | _| j| j | j| j | jt jtjj | jt jtjj | jt jtjj | jt jtjj tj| jd| _d S )N)descriptor_db)r   r   r   r	   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r1   r)   r)   r*   r  j  s,   
z)SecondaryDescriptorFromDescriptorDB.setUpc           	      C   s  t  }d|_d|_|j }d|_|j }d|_d|_tj	j
|_tj	j|_d|_|j }d|_|j }d|_|j }d	|_d
|_| j| | td| jjd | td| jjd | t}| jd W d    n1 suw   Y  | t|jd t dkrNd}| t}| jd W d    n1 sw   Y  | t|jd|  | t}| j d W d    n1 sw   Y  | t|jd|  | t}| j!d W d    n1 sw   Y  | t|jd|  | t}| j"d W d    n	1 sw   Y  | t|jd|  | t}| j#d W d    n	1 s<w   Y  | t|jd|  d S d S )N	collector
error_fileErrorMessagerR   nested_message_field
SubMessageMyOneofMyEnumMyEnumValuer   zcollector.ErrorMessage	none_file)z'none_file'z"Couldn't find file none_file"rt   zInvalid proto descriptor for file "error_file":\n  collector.ErrorMessage.nested_message_field: "SubMessage" is not defined.\n  collector.ErrorMessage.MyOneof: Oneof must have at least one field.\n'z:'Couldn\'t build file for message collector.ErrorMessage\nz+collector.ErrorMessage.nested_message_fieldzM'Couldn\'t build file for field collector.ErrorMessage.nested_message_field\nzcollector.MyEnumz1'Couldn\'t build file for enum collector.MyEnum\nzcollector.MyEnumValuez8'Couldn\'t build file for symbol collector.MyEnumValue\nzcollector.ErrorMessage.MyOneofz@'Couldn\'t build file for oneof collector.ErrorMessage.MyOneof\n)$r   r   r!   r    r`   addr   r   r   FieldDescriptorLABEL_OPTIONALr   TYPE_MESSAGEtype	type_name
oneof_declra   r   r   r   assertRaisesRegexr0   r   rW   r   r/   r"   r   	exceptionr   rx   r   rz   r|   r;   r}   )	r$   
file_protor`   r   r   ra   
enum_valueexc	error_msgr)   r)   r*   testErrorCollector|  s~   






	
z6SecondaryDescriptorFromDescriptorDB.testErrorCollectorN)r  r  r  r  r4  r)   r)   r)   r*   r   f  s    r   c                   @   s"   e Zd Z		dddZdd ZdS )	ProtoFileNc                 C   s*   || _ || _|| _|pg | _|pg | _d S r   )r    r!   messagesdependenciespublic_dependencies)r$   r    r!   r6  r7  r8  r)   r)   r*   __init__  s
   
zProtoFile.__init__c                 C   s   | | j}|| j|j || j|j dd |jD }|| j| dd |jD }|| j| | j D ]\}}||d || q9d S )Nc                 S      g | ]}|j qS r)   r   .0fr)   r)   r*   
<listcomp>      z'ProtoFile.CheckFile.<locals>.<listcomp>c                 S   r:  r)   r   r;  r)   r)   r*   r>    r?  )	r   r    r   r!   r7  r8  r6  items	CheckType)r$   testr   r   dependencies_namespublic_dependencies_namesr    msg_typer)   r)   r*   r     s   zProtoFile.CheckFile)NN)r  r  r  r9  r   r)   r)   r)   r*   r5    s
    
r5  c                   @   r  )EnumTypec                 C   s
   || _ d S r   )values)r$   rG  r)   r)   r*   r9    s   
zEnumType.__init__c                 C   s   |j | }|||j d|j|g}|||j |||j |||j t| jD ].\}\}}	|j	| }
|||
j |||
j
 ||	|
j |||
j |||j q.d S N.)r  r   r    joinrY   rZ   file	enumeraterG  r   indexr   r+  r"   enum_values_by_name)r$   rB  msg_descr    r   	enum_descexpected_enum_full_namerM  r   r   
value_descr)   r)   r*   rA    s   

zEnumType.CheckTypeNr  r  r  r9  rA  r)   r)   r)   r*   rF    s    rF  c                   @   s"   e Zd Z		dddZdd ZdS )MessageTypeFNc                 C   s    || _ || _|| _|pg | _d S r   )	type_dict
field_listis_extendabler   )r$   rU  rV  rW  r   r)   r)   r*   r9    s   zMessageType.__init__c           
      C   s  |d u r|j | }d|j|g}n|j| }d|j|g}|||j |||j |||j ||j| || j	|j	 | j
 D ]\}}||||| qHt| jD ]\}\}}	|	||||| qZt| jD ]\}\}}	|	||||| qod S rH  )r#   rJ  r!   nested_types_by_namerY   r   r    rZ   rK  rW  rU  r@  rA  rL  rV  
CheckFieldr   )
r$   rB  containing_type_descr    r   descexpected_full_namesubtyperM  r   r)   r)   r*   rA    s"   

zMessageType.CheckType)FNrS  r)   r)   r)   r*   rT    s
    
rT  c                   @   r  )	EnumFieldc                 C   s   || _ || _|| _d S r   )r   r,  re   )r$   r   r,  re   r)   r)   r*   r9    s   
zEnumField.__init__c           	      C   s   |j | }|j| j }|||j d|j|g}|||j |||j || j|j |t	j
j|j |t	j
j|j ||j ||j| j j|j ||j| j j |||j |||j |||j d S rH  )r_   r  r,  r   r    rJ  rY   rM  r   r   r(  	TYPE_ENUMr+  CPPTYPE_ENUMcpp_typerc   rd   r   re   r[   r\   rZ   ra   rK  )	r$   rB  rO  r    rM  r   
field_descrP  expected_field_full_namer)   r)   r*   rY    s&   

zEnumField.CheckFieldNr  r  r  r9  rY  r)   r)   r)   r*   r^    s    r^  c                   @   r  )MessageFieldc                 C      || _ || _d S r   )r   r,  )r$   r   r,  r)   r)   r*   r9  )     
zMessageField.__init__c           	      C   s   |j | }|j| j }|||j d|j|g}|||j |||j || j|j |t	j
j|j |t	j
j|j ||j |||j |||j |||j ||jd  d S rH  )r_   rX  r,  r   r    rJ  rY   rM  r   r   r(  r*  r+  CPPTYPE_MESSAGEra  r[   rd   rZ   r`   rK  re   )	r$   rB  rO  r    rM  r   rb  field_type_descrc  r)   r)   r*   rY  -  s    

zMessageField.CheckFieldNrd  r)   r)   r)   r*   re  '      re  c                   @   r  )StringFieldc                 C   rf  r   )r   re   )r$   r   re   r)   r)   r*   r9  A  rg  zStringField.__init__c                 C   s   |j | }|||j d|j|g}|||j |||j || j|j |tjj	|j
 |tjj|j ||j || j|j |||j d S rH  )r_   r   r    rJ  rY   rM  r   r   r(  TYPE_STRINGr+  CPPTYPE_STRINGra  rc   rd   re   rK  r$   rB  rO  r    rM  r   rb  rc  r)   r)   r*   rY  E  s   

zStringField.CheckFieldNrd  r)   r)   r)   r*   rk  ?  rj  rk  c                   @   r  )ExtensionFieldc                 C   rf  r   )r   extended_type)r$   r   rp  r)   r)   r*   r9  V  rg  zExtensionField.__init__c                 C   s   |j | }|||j d|j|g}|||j || j|j |||j |tjj	|j
 |tjj|j ||j ||j |||j |||j || j|jj |||j d S rH  )r   r   r    rJ  rY   r   rM  r   r(  r*  r+  rh  ra  r[   rd   rc   is_extensionextension_scoper`   rp  rZ   rK  rn  r)   r)   r*   rY  Z  s    

zExtensionField.CheckFieldNrd  r)   r)   r)   r*   ro  T  rj  ro  c                   @   s   e Zd Zdd Zee dkddd Zdd Z	ee dkdd	d
 Z
ee dkddd Zee dkddd Zdd Zdd Zdd Zdd ZdS )AddDescriptorTestc                 C   s   t  }|tjj | d||d j | 	t
 ||d  W d    n1 s.w   Y  |tjjj | d||d j | d|dj | d||d j d S )Nr  z,protobuf_unittest.TestAllTypes.NestedMessager9   )r   r   r  r   r   r   r   rW   rY   r/   r0   NestedMessager   r    r;   r$   prefixr   r)   r)   r*   _TestMessageo  sH   zAddDescriptorTest._TestMessagert   zOnly pure python allows _Add*()c                 C      |  d |  d d S Nrs   rI  )rw  r1   r)   r)   r*   testMessage     
zAddDescriptorTest.testMessagec                 C   s   t  }t dkr|tjj n|tjj | 	d|
|d j | t |
|d  W d    n1 s<w   Y  t dkrP|tjjj n|tjjj | 	d|
|d j | 	d|dj | 	d||d j d S )Ncppr  z(protobuf_unittest.ForeignEnum.NestedEnumz)protobuf_unittest.TestAllTypes.NestedEnumr9   )r   r   r   rx   AddEnumDescriptorr   r   r   r  r   r|   rY   r/   r0   r   
NestedEnumr   r    r;   ru  r)   r)   r*   	_TestEnum  sP   zAddDescriptorTest._TestEnumc                 C   rx  ry  )r  r1   r)   r)   r*   testEnum  r{  zAddDescriptorTest.testEnumc                 C   s`   t  }| t |d W d    n1 sw   Y  |tj | d|dj	 d S )Nr8   )
r   r   r/   r0   r~   r  r   _TESTSERVICEr   rY   r$   r   r)   r)   r*   testService  s   
zAddDescriptorTest.testServicec                 C   sb   t  }|tj | d|dj | t	 |
d W d    d S 1 s*w   Y  d S )Nr9   r  )r   r   _AddFileDescriptorr   r   r   r   r    r/   r0   r;   r  r)   r)   r*   testFile  s   "zAddDescriptorTest.testFilec                 C   sR   t  }tjj}| t|j| t }tj	| |
| | || d S r   )r   r   r   r   r    r/   r0   r   r   CopyToProtor   rc   )r$   r   proto_file_namer   r)   r)   r*   testEmptyDescriptorPool  s   
z)AddDescriptorTest.testEmptyDescriptorPoolc                 C   s
  t  }tjddd}|jjdd || | |dj	d | |
dj	d tjdd}|jjdd}|jjd	d
tjjtjjd |jjdd}|jjddd |jjdd t  }|| | d|
dj	 | d|dj	 | d|dj	 d S )Nr   r!   )r    r!   Messager   zpackage.Messagezsome/filename/container.proto
TopMessagebbrR   )r    r   r+  r   TopEnumFOREIGN_FOO   )r    r   
TopService)r   r   r   r   r`   r'  r   r   r   r    rW   r   FieldDescriptorProto
TYPE_INT32r)  ra   r   r   r|   r~   )r$   r   r   r0  message_proto
enum_protor)   r)   r*   testCustomDescriptorPool  sD   


z*AddDescriptorTest.testCustomDescriptorPoolc                 C   sp   t  }d}tj|d}tj}d|jj| _|	| |
|}| }| d|j| j | ||  d S )Nz9file_descriptor_options_with_custom_descriptor_pool.protor   foo)r   r   r   r   r   foo_optionsoptions
Extensionsfoo_namer   r   
GetOptionsr   r   )r$   r   	file_namefile_descriptor_protoextension_idr   r  r)   r)   r*   1testFileDescriptorOptionsWithCustomDescriptorPool  s   

zCAddDescriptorTest.testFileDescriptorOptionsWithCustomDescriptorPoolc                 C   s*  t  }t dkr| t |d W d    n1 sw   Y  | t |d W d    n1 s9w   Y  | t |d W d    n1 sSw   Y  | t |	d W d    n1 smw   Y  | t |
d W d    d S 1 sw   Y  d S | t |d W d    n1 sw   Y  | t |d W d    n1 sw   Y  | t |d W d    n1 sw   Y  | t |d W d    n1 sw   Y  | t |d W d    d S 1 sw   Y  d S )Nrt   r   )r   r   r   rx   r/   ru   AddDescriptorr}  AddServiceDescriptorAddExtensionDescriptorAddFileDescriptorr  r  r  r  r  r  r)   r)   r*   testAddTypeError  s@   "$z"AddDescriptorTest.testAddTypeErrorN)r  r  r  rw  unittestskipIfr   rx   rz  r  r  r  r  r  r  r  r  r)   r)   r)   r*   rs  l  s.    
$

	
rs  r   r   )ALPHArR   )r   rT   )EPSILON   )ZETA   r~  )ETA   )THETA   r   rR   r  nested_fieldrT   theta)r~  DeepNestedMessager  betadeep_nested_message   r  )r~  rt  r   nested_messagert  T)rW  )GAMMAr  )DELTAr  )IOTA	   )KAPPA
   )LAMBDA   )MU   r  lambdar  deltar  )r   DescriptorPoolTest2z4google/protobuf/internal/descriptor_pool_test2.protoDescriptorPoolTest3)NU   )XI   )OMICRON   )PI   )RHO   )SIGMA   r  sigmar  nur  descriptor_pool_testr   r   )r   z,google/protobuf/internal/more_messages.proto)r7  r8  __main__).__doc__
__author__r  osr  r	  google.protobufr   r   r   r   google.protobuf.internalr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r  DeprecationWarningobjectr   TestCaser  r  r   r5  rF  rT  r^  re  rk  ro  rs  r   r   r  mainr)   r)   r)   r*   <module>   s     o#Z  B

	

	.

	
 