<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
h                 @   s  d Z dZddlZddlZyddlZW n ek
r@   ddlZY nX 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 G dd deZG dd deejZG dd deejZ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%G d*d+ d+ejZ&ed,d-e!e dmdnge!e dodpge!d6e dqdrgid;e"d/d6d7fd<e$d1d=fgd>d;e"d/d6d4fd<e$d1d?fd@e#dAdBfgdCd;e"d/d6d0fdDe#d1dEfgdFdGe!e dsdtge!e dudvge!d6e dwdxgid;e"d/d6dQfd<e$d1dSfgd>d;e"d/d6dKfd<e$d1dTfd@e#dAdBfgdCd;e"d/d6dHfdDe#d1dEfgdUZ'edVd-dWe!e dydzge!e d{d|ge!d6e d}d~gid;e"d/d6d`fd<e$d1ddfgd>d;e"d/d6d^fd<e$d1defd@e#dAdBfgdCd;e"d/d6dZfdDe#d1dEfgdfe%dgdhfgdiid,djgdjgdkZ(e)dlkrej*  dS )z*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)
descriptor)descriptor_database)descriptor_pool)message_factory)symbol_databasec               @   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-S ).DescriptorPoolTestBasec             C   s   d}| j j|}| j|tj | j||j | jd|j | jd|j	 d}| j j|}| j|tj | j||j | jd|j | jd|j	 d S )Nz,google/protobuf/internal/factory_test1.protozgoogle.protobuf.python.internalFactory1Messagez,google/protobuf/internal/factory_test2.protoFactory2Message)
poolFindFileByNameassertIsInstancer   FileDescriptorassertEqualnamepackageassertInmessage_types_by_name)selfZname1
file_desc1Zname2
file_desc2 r!   */usr/lib/python3.6/descriptor_pool_test.pytestFindFileByNameA   s    z)DescriptorPoolTestBase.testFindFileByNamec          	   C   s&   | j t | jjd W d Q R X d S )NzDoes not exist)assertRaisesKeyErrorr   r   )r   r!   r!   r"   testFindFileByNameFailureP   s    z0DescriptorPoolTestBase.testFindFileByNameFailurec             C   s  | j jd}| j|tj | jd|j | jd|j | jd|j	 | j jd}| j|tj | jd|j | jd|j | jd|j	 | j jd}| j|tj | jd|j | j jd	}| j|tj | jd|j | j jd
}| j|tj | jd|j d S )Nz/google.protobuf.python.internal.Factory1Messagez,google/protobuf/internal/factory_test1.protozgoogle.protobuf.python.internalr   z/google.protobuf.python.internal.Factory2Messagez,google/protobuf/internal/factory_test2.protor   z-google.protobuf.python.internal.another_fieldz>google.protobuf.python.internal.Factory2Message.one_more_fieldzprotobuf_unittest.TestServicezgoogle/protobuf/unittest.proto)
r   FindFileContainingSymbolr   r   r   r   r   r   r   r   )r   r   r    Z
file_desc3Z
file_desc4Z
file_desc5r!   r!   r"   testFindFileContainingSymbolT   s:    z3DescriptorPoolTestBase.testFindFileContainingSymbolc          	   C   s&   | j t | jjd W d Q R X d S )NzDoes not exist)r$   r%   r   r'   )r   r!   r!   r"   #testFindFileContainingSymbolFailurey   s    z:DescriptorPoolTestBase.testFindFileContainingSymbolFailurec       	      C   s  | j jd}| j|tj | jd|j | jd|j | jd |j | j	|j
 |jd }| jd|j | j||j |jd }| jd|j | j||j | j||jd j | j||jd j | j jd}| j|tj | jd	|j | jd|j | j|j |jd }| jd
|j | j||j |jd }| jd|j | j||j | j||jd j | j||jd j | j|jd j | jd|jd j | j|jd j | jd|jd j | j|jd j | jd|jd j | j|jd j | j	|jd j | j|jd j | jd|jd j | j jd}| j|| | j|jd j | jd|jd j | jdt|j | jdt|j | jdt|jd j xBdD ]:}| j|jd |j| j | j|j| |jd j qW d S )Nz/google.protobuf.python.internal.Factory1Messager   r   ZNestedFactory1MessageZNestedFactory1EnumZnested_factory_1_messageZnested_factory_1_enumz/google.protobuf.python.internal.Factory2Messager   ZNestedFactory2MessageZNestedFactory2EnumZnested_factory_2_messageZnested_factory_2_enumZint_with_defaulti  Zdouble_with_defaultg{G#@Zstring_with_defaultzhello worldZbool_with_defaultZenum_with_default   zEgoogle.protobuf.python.internal.Factory2Message.NestedFactory2MessageZbytes_with_defaults   a c   	oneof_intoneof_string)r,   r-   )r   FindMessageTypeByNamer   r   Z
Descriptorr   r   	full_namecontaining_typeassertFalsehas_optionsZnested_typesZ
enum_typesfields_by_namemessage_type	enum_typeZassertIsNone
assertTruehas_default_valuedefault_valuelenZoneofsoneofs_by_nameZfieldsZcontaining_oneofr   )	r   Zmsg1Znested_msg1nested_enum1Zmsg2Znested_msg2nested_enum2Zmsg3r   r!   r!   r"   testFindMessageTypeByName}   s    












z0DescriptorPoolTestBase.testFindMessageTypeByNamec             C   s   | j t| jjd tj dkrH| j t| jjd | j t| jjd t}nt}| j || jj	d | j || jj
d | j || jjd | j || jjd | j || jjd | j || jjd | j || jjd tj dkrt}| j || jjd d S )N cppr   python)r$   	TypeErrorr   FindExtensionByNumberr   TypeZFindMethodByNamer%   AttributeErrorr.   FindFieldByNameFindExtensionByNameFindEnumTypeByNameFindOneofByNameFindServiceByNamer'   r   )r   Z
error_typer!   r!   r"   testFindTypeErrors   s     z)DescriptorPoolTestBase.testFindTypeErrorsc          	   C   s&   | j t | jjd W d Q R X d S )NzDoes not exist)r$   r%   r   r.   )r   r!   r!   r"    testFindMessageTypeByNameFailure   s    z7DescriptorPoolTestBase.testFindMessageTypeByNameFailurec             C   s  | j jd}| j|tj | jd|jd j | jd|jd j | j|j	 | j jd}| j|tj | jd|jd j | jd|jd j | j jd	}| j|tj | jd|jd
 j | jd|jd j | j jd}| j|tj | jd|jd j | jd|jd j d S )Nz,google.protobuf.python.internal.Factory1Enumr   ZFACTORY_1_VALUE_0r*   ZFACTORY_1_VALUE_1zBgoogle.protobuf.python.internal.Factory1Message.NestedFactory1EnumZNESTED_FACTORY_1_VALUE_0ZNESTED_FACTORY_1_VALUE_1z,google.protobuf.python.internal.Factory2EnumZFACTORY_2_VALUE_0ZFACTORY_2_VALUE_1zBgoogle.protobuf.python.internal.Factory2Message.NestedFactory2EnumZNESTED_FACTORY_2_VALUE_0ZNESTED_FACTORY_2_VALUE_1)
r   rG   r   r   ZEnumDescriptorr   values_by_namenumberr1   r2   )r   Zenum1r;   Zenum2r<   r!   r!   r"   testFindEnumTypeByName   s2    z-DescriptorPoolTestBase.testFindEnumTypeByNamec          	   C   s&   | j t | jjd W d Q R X d S )NzDoes not exist)r$   r%   r   rG   )r   r!   r!   r"   testFindEnumTypeByNameFailure  s    z4DescriptorPoolTestBase.testFindEnumTypeByNameFailurec          	   C   sv   t | trtj dkrd S | jjd}| j|jd | j|j|j	 | j
|j | jt | jjd W d Q R X d S )Nr?   z:google.protobuf.python.internal.Factory1Message.list_valueZ
list_valuezDoes not exist)
isinstance#SecondaryDescriptorFromDescriptorDBr   rC   r   rE   r   r   labelZLABEL_REPEATEDr1   r2   r$   r%   )r   fieldr!   r!   r"   testFindFieldByName
  s    
z*DescriptorPoolTestBase.testFindFieldByNamec          	   C   sZ   t | trtj dkrd S | jjd}| j|jd | jt	 | jjd W d Q R X d S )Nr?   z;google.protobuf.python.internal.Factory2Message.oneof_fieldoneof_fieldzDoes not exist)
rP   rQ   r   rC   r   rH   r   r   r$   r%   )r   Zoneofr!   r!   r"   testFindOneofByName  s    
z*DescriptorPoolTestBase.testFindOneofByNamec          	   C   s   t | trtj dkrd S | jjd}| j|jd | jjd}| j|jd | j|jd | j	t
 | jjd W d Q R X d S )Nr?   z>google.protobuf.python.internal.Factory2Message.one_more_fieldone_more_fieldz-google.protobuf.python.internal.another_fieldanother_fieldi  zDoes not exist)rP   rQ   r   rC   r   rF   r   r   rM   r$   r%   rE   )r   	extensionr!   r!   r"   testFindExtensionByName%  s    
z.DescriptorPoolTestBase.testFindExtensionByNamec             C   s   | j jd}| j jd}|jd }| j j| | j jd}|jd }| j j| | j j|}t||g}| j|t| |jd | j j|}| j|t| d S )Nz/google.protobuf.python.internal.Factory1Messagez/google.protobuf.python.internal.Factory2MessagerW   z,google/protobuf/internal/factory_test2.protorX   Zunexpected_element)	r   r.   extensions_by_nameAddExtensionDescriptorr   ZFindAllExtensionssetr   append)r   factory1_messagefactory2_messagerW   factory_test2rX   
extensionsZexpected_extension_numbersr!   r!   r"   testFindAllExtensions7  s     


z,DescriptorPoolTestBase.testFindAllExtensionsc          
   C   s   | j jd}| j jd}|jd }| j j| | j jd}|jd }| j j| | j j|d}| j|jd | j j|d}| j|jd | jt	 | j j|d}W d Q R X d S )	Nz/google.protobuf.python.internal.Factory1Messagez/google.protobuf.python.internal.Factory2MessagerW   z,google/protobuf/internal/factory_test2.protorX   i  i  i )
r   r.   r[   r\   r   rB   r   r   r$   r%   )r   r_   r`   rW   ra   rX   rY   r!   r!   r"   testFindExtensionByNumberO  s     

z0DescriptorPoolTestBase.testFindExtensionByNumberc             C   sj   | j t | jjd W d Q R X | j t | jjd W d Q R X | j t | jjd W d Q R X d S )Nz-google.protobuf.python.internal.another_fieldz>google.protobuf.python.internal.Factory2Message.one_more_fieldz:google.protobuf.python.internal.Factory1Message.list_value)r$   r%   r   rE   rF   )r   r!   r!   r"   testExtensionsAreNotFieldsf  s    z1DescriptorPoolTestBase.testExtensionsAreNotFieldsc          	   C   s@   | j jd}| j|jd | jt | j jd W d Q R X d S )Nzprotobuf_unittest.TestServicezDoes not exist)r   rI   r   r/   r$   r%   )r   servicer!   r!   r"   testFindServicep  s    z&DescriptorPoolTestBase.testFindServicec             C   s8   t j }tj|| _|j| j |j| j | j  d S )N)	r   DescriptorDatabaser   DescriptorPoolr   Addfactory_test1_fdfactory_test2_fdr=   )r   dbr!   r!   r"   testUserDefinedDBv  s
    z(DescriptorPoolTestBase.testUserDefinedDBc             C   sT   t | trtj dkrd S tj | _| jj| jj	  | jj| j
j	  | j  d S )Nr?   )rP   rQ   r   rC   r   ri   r   AddSerializedFilerk   SerializeToStringrl   r=   )r   r!   r!   r"   testAddSerializedFile}  s    

z,DescriptorPoolTestBase.testAddSerializedFilec                s    fdd}|t j tj jjd} j|t j || t trVt	j
 dkrVdS tjjt jj} 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} j|tjj d S )NDescriptorPoolTest1nested_enum)r   r3   r8   r   r   rr   BETA)file_descriptorr8   )r   r!   r"   _CheckDefaultValue  s
    zGDescriptorPoolTestBase.testEnumDefaultValue.<locals>._CheckDefaultValuez4google/protobuf/internal/descriptor_pool_test1.protor?   N)r   
DESCRIPTORr   Defaultr   r   assertIsrP   rQ   r   rC   r   FileDescriptorProto
FromStringserialized_pbrj   )r   rv   ru   Zdescriptor_protor!   )r   r"   testEnumDefaultValue  s    



z+DescriptorPoolTestBase.testEnumDefaultValuec                s   fdd  fdd}|t j  tj }|jtjjtj	j
 |jtjjtj	j
 |jtjjt j	j
 tj|j|jt jj	j}||  dS )z0Check the value returned by non-existent fields.c                s    j | |  j| | d S )N)r   r   )valueZexpected_valueZexpected_type)r   r!   r"   _CheckValueAndType  s    zTDescriptorPoolTestBase.testDefaultValueForCustomMessages.<locals>._CheckValueAndTypec                s   yt }W n tk
r    t }Y nX yt}W n tk
rB   t}Y nX  | 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   Fr>       )int	NameErrorstroptional_int32Zoptional_uint64Zoptional_floatfloatZoptional_doubleZoptional_boolboolZoptional_stringZoptional_bytesbytesZoptional_nested_enumZFOO)msgZint64Zunicode_type)r   r!   r"   _CheckDefaultValues  s     

zUDescriptorPoolTestBase.testDefaultValueForCustomMessages.<locals>._CheckDefaultValuesN)r   TestAllTypesr   ri   rj   r   rz   r{   r   rw   r|   r   r   ZMessageFactoryZGetPrototyper.   r/   )r   r   r   Zmessage_classr!   )r   r   r"   !testDefaultValueForCustomMessages  s    



z8DescriptorPoolTestBase.testDefaultValueForCustomMessagesc             C   sF   t | trtj dkrd S tjdd}| jj| | jj|j	  d S )Nr?   zsome/file.proto)r   )
rP   rQ   r   rC   r   rz   r   rj   ro   rp   )r   	file_descr!   r!   r"   testAddFileDescriptor  s    
z,DescriptorPoolTestBase.testAddFileDescriptorc             C   s   t | trtj dkrd S tjjtjj	}tjjt
jj	}tjjtjj	}| jj| | jj| | jj| tj| | j tj| | j d S )Nr?   )rP   rQ   r   rC   r   rz   r{   r   rw   r|   r   r   r   rj   
TEST1_FILE	CheckFile
TEST2_FILE)r   Zmore_messages_descZ
test1_descZ
test2_descr!   r!   r"   testComplexNesting  s    



z)DescriptorPoolTestBase.testComplexNestingN)__name__
__module____qualname__r#   r&   r(   r)   r=   rJ   rK   rN   rO   rT   rV   rZ   rc   rd   re   rg   rn   rq   r}   r   r   r   r!   r!   r!   r"   r   ?   s,   %R
 &r   c               @   s   e Zd Zdd Zdd ZdS )DefaultDescriptorPoolTestc             C   s2   t j | _tjjtjj| _	tjjt
jj| _d S )N)r   rx   r   r   rz   r{   r	   rw   r|   rk   r
   rl   )r   r!   r!   r"   setUp  s
    
zDefaultDescriptorPoolTest.setUpc             C   s   | j | jjdtj | j | jjdtjj | j | jjdtjjjd  | j | jj	dtj
j | j | jjdtjjd  | j | jjdtjjjd	  | j | jjd
tjjd  d S )Nzgoogle/protobuf/unittest.protozprotobuf_unittest.TestAllTypesz-protobuf_unittest.TestAllTypes.optional_int32r   zprotobuf_unittest.ForeignEnumz*protobuf_unittest.optional_int32_extensionZoptional_int32_extensionz*protobuf_unittest.TestAllTypes.oneof_fieldrU   zprotobuf_unittest.TestServiceZTestService)ry   r   r   r   rw   r.   r   rE   r3   rG   ForeignEnumrF   r[   rH   r:   rI   Zservices_by_name)r   r!   r!   r"   testFindMethods  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 j | _tjjtjj| _	tjjt
jj| _| jj| j	 | jj| j | jjtjjtjj | jjtjjtjj | jjtjjtjj d S )N)r   ri   r   r   rz   r{   r	   rw   r|   rk   r
   rl   rj   r   r   r   )r   r!   r!   r"   r     s    
zCreateDescriptorPoolTest.setUpN)r   r   r   r   r!   r!   r!   r"   r     s   r   c               @   s   e Zd Zdd ZdS )rQ   c             C   s   t jjtjj| _t jjtjj| _t	j
 }|j| j |j| j |jt jjtjj |jt jjtjj |jt jjtjj tj|d| _d S )N)Zdescriptor_db)r   rz   r{   r	   rw   r|   rk   r
   rl   r   rh   rj   r   r   r   r   ri   r   )r   rm   r!   r!   r"   r   (  s    


z)SecondaryDescriptorFromDescriptorDB.setUpN)r   r   r   r   r!   r!   r!   r"   rQ   %  s   rQ   c               @   s   e Zd ZdddZdd ZdS )	ProtoFileNc             C   s*   || _ || _|| _|pg | _|p"g | _d S )N)r   r   messagesdependenciespublic_dependencies)r   r   r   r   r   r   r!   r!   r"   __init__;  s
    
zProtoFile.__init__c             C   s   |j | j}|j| j|j |j| j|j dd |jD }|j| j| dd |jD }|j| j| x*t| jj D ]\}}|j	|d || qxW d S )Nc             S   s   g | ]
}|j qS r!   )r   ).0fr!   r!   r"   
<listcomp>G  s    z'ProtoFile.CheckFile.<locals>.<listcomp>c             S   s   g | ]
}|j qS r!   )r   )r   r   r!   r!   r"   r   I  s    )
r   r   r   r   r   r   listr   items	CheckType)r   testr   r   Zdependencies_namesZpublic_dependencies_namesr   Zmsg_typer!   r!   r"   r   C  s    zProtoFile.CheckFile)NN)r   r   r   r   r   r!   r!   r!   r"   r   9  s    
r   c               @   s   e Zd Zdd Zdd ZdS )EnumTypec             C   s
   || _ d S )N)values)r   r   r!   r!   r"   r   Q  s    zEnumType.__init__c             C   s   |j | }|j||j dj|j|g}|j||j |j||j |j||j xjt| jD ]\\}\}}	|j	| }
|j||
j |j||
j
 |j|	|
j |j||
j |j||j q^W d S )N.)enum_types_by_namer   r   joinr/   r0   file	enumerater   rL   indexrM   typer   Zenum_values_by_name)r   r   msg_descr   r   	enum_descZexpected_enum_full_namer   r~   rM   Z
value_descr!   r!   r"   r   T  s    

zEnumType.CheckTypeN)r   r   r   r   r   r!   r!   r!   r"   r   O  s   r   c               @   s   e Zd ZdddZdd ZdS )MessageTypeFNc             C   s    || _ || _|| _|pg | _d S )N)	type_dict
field_listis_extendablerb   )r   r   r   r   rb   r!   r!   r"   r   f  s    zMessageType.__init__c       
      C   s  |d kr$|j | }dj|j|g}n|j| }dj|j|g}|j||j |j||j |j||j |j|j| |j| j	|j	 x*t
| jj D ]\}}|j|||| qW x,t| jD ]\}\}}	|	j||||| qW x,t| jD ]\}\}}	|	j||||| qW d S )Nr   )r   r   r   nested_types_by_namer/   r   r   r0   r   r   r   r   r   r   r   r   
CheckFieldrb   )
r   r   Zcontaining_type_descr   r   ZdescZexpected_full_namesubtyper   rS   r!   r!   r"   r   m  s     

zMessageType.CheckType)FN)r   r   r   r   r   r!   r!   r!   r"   r   d  s    
r   c               @   s   e Zd Zdd Zdd ZdS )	EnumFieldc             C   s   || _ || _|| _d S )N)rM   	type_namer8   )r   rM   r   r8   r!   r!   r"   r     s    zEnumField.__init__c       	      C   s   |j | }|j| j }|j||j dj|j|g}|j||j |j||j |j| j|j |jt	j
j|j |jt	j
j|j |j|j |j|j| j j|j |j|j| j j |j||j |j||j |j||j d S )Nr   )r3   r   r   r   r   r   r/   r   rM   r   FieldDescriptorZ	TYPE_ENUMr   ZCPPTYPE_ENUMcpp_typer6   r7   rL   r8   r1   r2   r0   r5   r   )	r   r   r   r   r   r   
field_descr   expected_field_full_namer!   r!   r"   r     s"    

zEnumField.CheckFieldN)r   r   r   r   r   r!   r!   r!   r"   r     s   r   c               @   s   e Zd Zdd Zdd ZdS )MessageFieldc             C   s   || _ || _d S )N)rM   r   )r   rM   r   r!   r!   r"   r     s    zMessageField.__init__c       	      C   s   |j | }|j| j }|j||j dj|j|g}|j||j |j||j |j| j|j |jt	j
j|j |jt	j
j|j |j|j |j||j |j||j |j||j tj dkr|jtt|d d S )Nr   r?   r8   )r3   r   r   r   r   r   r/   r   rM   r   r   TYPE_MESSAGEr   CPPTYPE_MESSAGEr   r1   r7   r0   r4   r   r   rC   r$   NotImplementedErrorgetattr)	r   r   r   r   r   r   r   Zfield_type_descr   r!   r!   r"   r     s"    

zMessageField.CheckFieldN)r   r   r   r   r   r!   r!   r!   r"   r     s   r   c               @   s   e Zd Zdd Zdd ZdS )StringFieldc             C   s   || _ || _d S )N)rM   r8   )r   rM   r8   r!   r!   r"   r     s    zStringField.__init__c             C   s   |j | }|j||j dj|j|g}|j||j |j||j |j| j|j |jtjj	|j
 |jtjj|j |j|j |j| j|j |j||j d S )Nr   )r3   r   r   r   r/   r   rM   r   r   ZTYPE_STRINGr   ZCPPTYPE_STRINGr   r6   r7   r8   r   )r   r   r   r   r   r   r   r   r!   r!   r"   r     s    

zStringField.CheckFieldN)r   r   r   r   r   r!   r!   r!   r"   r     s   r   c               @   s   e Zd Zdd Zdd ZdS )ExtensionFieldc             C   s   || _ || _d S )N)rM   extended_type)r   rM   r   r!   r!   r"   r     s    zExtensionField.__init__c             C   s   |j | }|j||j dj|j|g}|j||j |j| j|j |j||j |jtjj	|j
 |jtjj|j |j|j |j|j |j||j |j||j |j| j|jj |j||j d S )Nr   )r[   r   r   r   r/   rM   r   r   r   r   r   r   r   r1   r7   r6   Zis_extensionZextension_scoper4   r   r0   r   )r   r   r   r   r   r   r   r   r!   r!   r"   r     s    

zExtensionField.CheckFieldN)r   r   r   r   r   r!   r!   r!   r"   r     s   r   c               @   s   e Zd Zdd Zejej dkddd Zdd Z	ejej dkdd	d
 Z
ejej dkddd Zejej dkddd Zdd Zdd Zdd Zdd ZdS )AddDescriptorTestc             C   s   t j }|jtjj | jd|j|d j | j	t
 |j|d  W d Q R X |jtjjj | jd|j|d j | jd|jdj | jd|j|d j d S )Nzprotobuf_unittest.TestAllTypesz,protobuf_unittest.TestAllTypes.NestedMessagezgoogle/protobuf/unittest.proto)r   ri   AddDescriptorr   r   rw   r   r.   r/   r$   r%   NestedMessager   r   r'   )r   prefixr   r!   r!   r"   _TestMessage  s,    
zAddDescriptorTest._TestMessager?   z7With the cpp implementation, Add() must be called firstc             C   s   | j d | j d d S )Nr>   r   )r   )r   r!   r!   r"   testMessage  s    
zAddDescriptorTest.testMessagec             C   s   t j }|jtjj | jd|j|d j | j	t
 |j|d  W d Q R X |jtjjj | jd|j|d j | jd|jdj | jd|j|d j d S )Nzprotobuf_unittest.ForeignEnumz(protobuf_unittest.ForeignEnum.NestedEnumz)protobuf_unittest.TestAllTypes.NestedEnumzgoogle/protobuf/unittest.proto)r   ri   AddEnumDescriptorr   r   rw   r   rG   r/   r$   r%   r   
NestedEnumr   r   r'   )r   r   r   r!   r!   r"   	_TestEnum  s,    
zAddDescriptorTest._TestEnumc             C   s   | j d | j d d S )Nr>   r   )r   )r   r!   r!   r"   testEnum,  s    
zAddDescriptorTest.testEnumc             C   sL   t j }| jt |jd W d Q R X |jtj | jd|jdj	 d S )Nzprotobuf_unittest.TestService)
r   ri   r$   r%   rI   AddServiceDescriptorr   Z_TESTSERVICEr   r/   )r   r   r!   r!   r"   testService2  s    zAddDescriptorTest.testServicec          	   C   sL   t j }|jtj | jd|jdj | jt	 |j
d W d Q R X d S )Nzgoogle/protobuf/unittest.protozprotobuf_unittest.TestAllTypes)r   ri   AddFileDescriptorr   rw   r   r   r   r$   r%   r'   )r   r   r!   r!   r"   testFile=  s    
zAddDescriptorTest.testFilec             C   sR   t j }tjj}| jt|j| tj }tjj	| |j
| | j|j| d S )N)r   ri   r   rw   r   r$   r%   r   rz   ZCopyToProtorj   r6   )r   r   Zproto_file_nameru   r!   r!   r"   testEmptyDescriptorPoolM  s    
z)AddDescriptorTest.testEmptyDescriptorPoolc             C   s
  t j }tjddd}|jjdd |j| | j|jdj	d | j|j
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 j }|j| | jd|j
dj	 | jd|jdj	 | jd|jdj	 d S )Nzsome/file.protor   )r   r   ZMessage)r   zpackage.Messagezsome/filename/container.protoZ
TopMessageZbbr*   )r   rM   r   rR   ZTopEnumZFOREIGN_FOO   )r   rM   Z
TopService)r   ri   r   rz   r4   addrj   r   r   r   r.   rS   ZFieldDescriptorProtoZ
TYPE_INT32ZLABEL_OPTIONALr5   r~   rf   rG   rI   )r   r   r   Z
file_protoZmessage_protoZ
enum_protor!   r!   r"   testCustomDescriptorPoolY  s6    


z*AddDescriptorTest.testCustomDescriptorPoolc             C   sp   t j }d}tj|d}tj}d|jj| _|j	| |j
|}|j }| jd|j| j | j||j  d S )Nz9file_descriptor_options_with_custom_descriptor_pool.proto)r   Zfoo)r   ri   r   rz   r   Zfoo_optionsoptionsZ
ExtensionsZfoo_namerj   r   Z
GetOptionsr   ry   )r   r   	file_nameZfile_descriptor_protoZextension_idru   r   r!   r!   r"   1testFileDescriptorOptionsWithCustomDescriptorPoolx  s    

zCAddDescriptorTest.testFileDescriptorOptionsWithCustomDescriptorPoolc          %   C   s   t j }| jt |jd W d Q R X | jt |jd W d Q R X | jt |jd W d Q R X | jt |jd W d Q R X | jt |jd W d Q R X d S )Nr   )	r   ri   r$   rA   r   r   r   r\   r   )r   r   r!   r!   r"   testAddTypeError  s    z"AddDescriptorTest.testAddTypeErrorN)r   r   r   r   unittestZskipIfr   rC   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   r     s   
r   z4google/protobuf/internal/descriptor_pool_test1.protozgoogle.protobuf.python.internalALPHAr*   rt   r+   EPSILON   ZETA   r   ETA   THETA   rs   Znested_fieldZtheta)r   DeepNestedMessageZbetaZdeep_nested_message   r   )r   r   Znested_messager   T)r   GAMMADELTAr   IOTA	   KAPPA
   LAMBDA   MU   lambdaZdelta)rr   ZDescriptorPoolTest2z4google/protobuf/internal/descriptor_pool_test2.protoZDescriptorPoolTest3NU   XI   OMICRON   PI   RHO   SIGMA   ZsigmaZnuZdescriptor_pool_testi  rr   )rb   z,google/protobuf/internal/more_messages.proto)r   r   __main__)r   r*   )rt   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   )r   r   )r   r   )r   r   )+__doc__
__author__ossysZ	unittest2r   ImportErrorZgoogle.protobufr   r   r   r   Zgoogle.protobuf.internalr   r   r   r	   r
   r   r   r   r   r   r   r   objectr   ZTestCaser   r   rQ   r   r   r   r   r   r   r   r   r   r   r   mainr!   r!   r!   r"   <module>    s      3#  0







