� S�Ljc@stdZddlZddlZddlZddlZddlZyddlZWnek rqddlZnXddl m Z ddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZejZdefd��YZdefd��YZdefd��YZdefd��YZ defd��YZ!defd��YZ"defd ��YZ#d!efd"��YZ$d#efd$��YZ%d%efd&��YZ&e'd'krpej(�ndS((siUnittest for reflection.py, which also indirectly tests the output of the pure-Python protocol compiler. i����N(tunittest_import_pb2(tunittest_mset_pb2(t unittest_pb2(tdescriptor_pb2(t descriptor(tmessage(t reflection(t text_format(tapi_implementation(tmore_extensions_pb2(tmore_messages_pb2(tmessage_set_extensions_pb2(t wire_format(t test_util(ttesting_refleaks(tdecodert _MiniDecodercBskeZdZd�Zd�ZeZeZeZeZd�Z e Z d�Z d�Z d�Z d�ZRS(s�Decodes a stream of values from a string. Once upon a time we actually had a class called decoder.Decoder. Then we got rid of it during a redesign that made decoding much, much faster overall. But a couple tests in this file used it to check that the serialized form of a message was correct. So, this class implements just the methods that were used by said tests, so that we don't have to rewrite the tests. cCs||_d|_dS(Ni(t_bytest_pos(tselftbytes((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt__init__Os cCs%tj|j|j�\}|_|S(N(Rt _DecodeVarintRR(Rtresult((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt ReadVarintSs!cCstj|j��S(N(R t ZigZagDecodeR(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt ReadSInt64\scCstj|j��S(N(R t UnpackTagR(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytReadFieldNumberAndWireTypeascCs=tjd|j|j|jd!�d}|jd7_|S(Nsd=�Z?d>�Z@d?�ZAd@�ZBdA�ZCdB�ZDdC�ZEdD�ZFdE�ZGdF�ZHdG�ZIdH�ZJdI�ZKdJ�ZLdK�ZMdL�ZNdM�ZOdN�ZPd[dO�ZRdP�ZSeTjUeVjW�dQkp eVjX�dRkdS�dT��ZYdU�ZZdV�Z[dW�Z\dX�Z]dY�Z^dZ�Z_RS(\cCsU|jt|�t|��x2tt|��D]}|j||||�q/WdS(N(t assertEqualR!trange(Rtvaluestothersti((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytassertListsEqualtsc Cswtjdddddddd�}|jd|j�|jd|j�|jd|j�|j|jd��dS(Ntoptional_int32itoptional_doubleg +�)K@toptional_stringtoptional_float( Rt TestAllTypestNoneR,R2R3R4t assertFalsetHasField(Rtproto((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestScalarConstructorys  c Cs�tjdddddgdddgd tttgd d gd d�}|jddddgt|j��|jddgt|j��|jtttgt|j ��|jd gt|j ��|jgt|j ��dS( Ntrepeated_int32iiiitrepeated_doubleg�G�z��?g +�)K@t repeated_booltrepeated_stringR4trepeated_float( RR6tTruetFalseR7R,tlistR<R=R>R?R@(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedScalarConstructor�s    %"c Cs�tjdtjjdtjj�tjjdtjj�gdtjdd�tjdd�tjdd�gdtjj�tjjd d �tjjd d �g�}|jtjjdtjj�tjjdtjj�gt|j ��|jtjdd�tjdd�tjdd�gt|j ��|jtjj�tjjd d �tjjd d �gt|j ��dS( Ntrepeated_nested_messagetbbtrepeated_foreign_messagetci����i �i t repeatedgrouptaii( RR6t NestedMessagetFOOtBARtForeignMessaget RepeatedGroupR,RCRERGRI(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt testRepeatedCompositeConstructor�s6         cCs�tjdddddddgdtttgdtjjd tjj�tjjd tjj�gd tjd d �tjd d �tjd d�gdd�}|j d|j �|j d|j �|j ddgt |j ��|j tttgt |j��|j tjjd tjj�tjjd tjj�gt |j��|j tjd d �tjd d �tjd d�gt |j��|j|jd��dS(NR2iR4R=g�G�z��?g +�)K@R>RERFRGRHi����i �i toptional_nested_message(RR6RARBRKRLRMRNR7R,R2R4RCR=R>RERGR8R9(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestMixedConstructor�s:      "   cCs�|jttjdd�|jttjdd�|jttjdd�|jttjdd�|jttjddg�|jttjdd�|jttjddg�|jttjdd�|jttjddg�dS( NR2tfooR4i�RQR<R?RE(t assertRaisest TypeErrorRR6(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestConstructorTypeError�s$cCs�tjdd�}|jd|j��tjdtjj��}|jd|j��tjddg�}|jd|j��tjdtjj�g�}|jd|j��dS(NR2i iRQiR<RE(RR6R,tByteSizeRK(RR((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt(testConstructorInvalidatesCachedByteSize�s  cCs�tj�}|j|jd� �|jd|j�|j|jd� �d|_|j|jd��|jd�|j|jd� �dS(NR2ii(RR6t assertTrueR9R,R2t ClearField(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestSimpleHasBits�s   csG�fd�}|dd�|dd�|dd�|dd �dS( Ncs�tj�}t||�}t||�}�jd|��j|j|� ��j|j|� �d}t|||��j|t||��|}�j|j|���j|j|��|j|�t||�}�j|j|� ��j|j|� ��jdt||���j||k �t|||��j|j|� ��j|j|� ��jdt||��dS(Nii(RR6tgetattrR,RYR9tsetattrRZ(tcomposite_field_nametscalar_field_nameR:tcomposite_fieldtoriginal_scalar_valuetnew_valtold_composite_field(R(sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytTestCompositeHasBits.s,  t optionalgroupRJRQRFtoptional_foreign_messageRHtoptional_import_messagetd((RRd((RsL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt!testHasBitsWithSinglyNestedScalar s "*   cCs%tj�}|j}~d|_dS(Ni(RR6RQRF(RR:tnested((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestReferencesToNestedMessage]s  cCsrtj�}|j}|jd�|j||jk �d|_|j|jd� �|jd|jj�dS(NRQii(RR6RQRZRYRFR9R,(RR:Rj((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt0testDisconnectingNestedMessageBeforeSettingFieldes    cCsKtj�}|j}|jd�~~tj�tj�}|j}dS(NRQ(RR6RQRZtgctcollect(RR:Rj((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt5testGetDefaultMessageAfterDisconnectingDefaultMessagens     cCs�tj�}|j}d|_|j|jd��|jd�|jd|j�|jd|jj�|j||jk �d|_|j|jd� �|jd|jj�dS(NiRQii(RR6RQRFRYR9RZR,(RR:Rj((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt/testDisconnectingNestedMessageAfterSettingField{s     cCsKtj�}|j|jd� �|jd�|j|jd� �dS(NRQ(RR6RYR9RZ(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt0testDisconnectingNestedMessageBeforeGettingField�s  cCsotj�}tj�}d|j_|j|�|j|jd��|jd�|j|jd� �dS(NiRQ(RR6RQRFt MergeFromRYR9RZ(Rtproto1tproto2((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt(testDisconnectingNestedMessageAfterMerge�s     cCsLtj�dkrdStj�}d|j_|jd�~tj�dS(Ntpythonitoptional_lazy_message( RtTypeRR6RwRFRZRmRn(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt"testDisconnectingLazyNestedMessage�s   cCs�tj�}|jjjd�|jdg|jj�|j|jd��|jd�|j|jd� �|jj j �|j|jd��dS(NiRQ( RtTestNestedMessageHasBitsRQtnestedmessage_repeated_int32tappendR,RYR9RZt%nestedmessage_repeated_foreignmessagetadd(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt&testHasBitsWhenModifyingRepeatedFields�s  cCsqtj�}|j|jd� �|jd|jjjjjj�|j|jd� �d|jjjjj_|jd|jjjjjj�|j|jd��|j|jjd��|j|jjjd��|j|jjjjd��|j|jjjjjd��|j|jjjjjjd� �|j|jjjjjjd��dS(NRFiiRJR2(RtTestMutualRecursionARYR9R,RFRJR2(Rtrecursive_proto((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt!testHasBitsForManyLevelsOfNesting�s """&cCs�tj�}d|_d|_d|_|j}|j|jjddf|jjddf|jjddfg|j ��d|j_ |j|jjddf|jjddf|jjddf|jjd|fg|j ��dS( NiiRSR2toptional_fixed32R4i{RQ( RR6R�R2R4RQR,t DESCRIPTORtfields_by_namet ListFieldsRF(RR:tnested_message((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestSingularListFields�s$         c Cs tj�}|jjd�|jjd�|jjd�|jjddg�|jjg�|jjd�|jjd�td�D��d |_|j |j |j j d d f|j j d ddgf|j j d dgf|j j d dddddgfg|j ��dS(Niii RStbartbazcss|]}t|�VqdS(N(tstr(t.0tx((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pys �siiR2R<trepeated_fixed32R?t0t1(RR6R�R|R<R?textendR-R2R>R,R�R�R�(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedListFields�s"    cCsztj�}d|jtjQR�(RtTestRequiredForeignR-R�R~tCopyFromRTt IndexError(RR0Rt((R:sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestClearRemovesChildrenHs    cCs�tj�}|jtt|dd�|jtt|ddg�|jtt|dd�|jtt|jdd�|jtt|jdd�|jtt|dd�dS( NR<i RQiRFi"tsome_attributeR�(RR6RTtAttributeErrorR]RER@(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestDisallowedAssignmentsSs    cCs�tj�}|jtt|dd�|jtt|dd�|jtt|dd�|jtt|dd�|jtt|dd�|jtt|dd�|jtt|d d�tj�d kr�|jtt|dd�n d|_dS( NR2g�������?RSR4i R�R�R5R3Rv(RR6RTRUR]RRxR�(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestSingleScalarTypeSafetyhs cs���fd�}|ddt�|dd t�|ddt�y t}Wntk ret}nXtjd�dkr�|dd|�n|ddt�|d d|�|d d|�|d d|�|d d|�d S(s}Verifies setting of scalar integers. Args: integer_fn: A function to wrap the integers that will be assigned. cs}tj�}�|�}t|||��jt||�|�tj�}|j|j���jt||�|�dS(N(RR6R]tassertIsInstanceR\tParseFromStringtSerializeToString(t field_nametvaluet expected_typeR:Rt(t integer_fnR(sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytTestGetAndDeserialize}s   R2iiR�tLiiR�i<R�Ni@i@lli@li@l(tinttlongt NameErrorRtcalcsize(RR�R�t integer_64((R�RsL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytassertIntegerTypesws    cCs|jd��dS(NcSs|S(N((R�((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyR��R�(R�(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestIntegerTypes�scCs|jtj�dS(N(R�R tNonStandardInteger(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestNonStandardIntegerTypes�scCs]tj�}|jt��d|_WdQX|jtd��tjdd�|_WdQXdS(Nt2tmy_errori( RR6RTRUR�tassertRaisesRegexpt RuntimeErrorR R�(Rtpb((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestIllegalValuesForIntegers�s  cs���fd�}|ddd�|ddd�|ddd�|d dd �tj�}�jttf���d�|_Wd QXtj�}�d�|_�jd|j�d S(s�Verifies bounds checking for scalar integer fields. Args: integer_fn: A function to wrap the integers that will be assigned. cs�tj�}�|�}�|�}t|||��j|t||��t|||��j|t||���jttft|||d��jttft|||d�dS(Ni(RR6R]R,R\RTR�RU(R�t expected_mint expected_maxR�(R�R(sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytTestMinAndMaxIntegers�s    R2iiR�il��R�i?R�l����Nll����ll��ll����ll����ll����(RR6RTR�RUR�toptional_nested_enumR,(RR�R�R�((R�RsL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytassetIntegerBoundsChecking�s   cCs|jd��dS(NcSs|S(N((R�((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyR��R�(R�(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestSingleScalarBoundsChecking�scCs|jtj�dS(N(R�R R�(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt)testNonStandardSingleScalarBoundsChecking�scCs'tj�}|jt|jjd�|jt|jjd�|jt|jd�|jt|jd�|jjd�d|jd<|jt|jj dd�|jt|jj dd�|jt|jj dg�|jt|jj dd�|jjd �|jt|jj dd�dS( Ng�������?RSi iii�tabctindexR�( RR6RTRUR<R|R?trepeated_bytesR�t __setitem__(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedScalarTypeSafety�s   cCswtj�}|jd|j�d|_|jd|j�d|_|jd|j�d|_|jd|j�dS(Niil���l����(RR6R,R2R�(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt!testSingleScalarGettersAndSetters�s    cCsstj�}|jd�d|_|j|jd��|jd�|jd|j�|j|jd� �dS(NR2ii(RR6RZR2RYR9R,(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestSingleScalarClearField�s    cCs�tj�}|jd|j�|jdtjj�|jd|j�|jdtjj�|jd|j�|jdtjj�dS(Niii(RR6R,RLRMtBAZ(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt testEnums�s cCs~|jdtjjtj��|jdtjjtj��|jdtjjtj��|jttjjd�tj �}|jd|j j|j ��|jdtj j j|j ��|jd|j j|j ��|jdtj j j|j ��|jd|j j|j ��|jdtj j j|j ��|jt|j jd�|jttj j jd�dS(Nt FOREIGN_FOOR�t FOREIGN_BAZi0,RLRMR�(R,Rt ForeignEnumtNameR�R�RRTR�R6t NestedEnumRLRMR�(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt testEnum_Names2             cCs~|jtjtjjd��|jtjtjjd��|jtjtjjd��|jttjjd�tj �}|j|j |j jd��|j|j tj j jd��|j|j |j jd��|j|j tj j jd��|j|j |j jd��|j|j tj j jd��|jt|j jd�|jttj j jd�dS( NR�R�RtFORLRMR�tFoo(R,RR�RtValueR�RRTR�R6RLRRMR�(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestEnum_Value"s2             cCs |jdddgttjj���|jdddgttjj���|jdddgttjj���tj�}|jddd d gt|jj���|jd d d dgt|jj���|jddddgt|jj���dS(NR�R�RiiiRLRMR�tNEGiiii����(R�i(R�i(Ri(RLi(RMi(R�i(R i����( R,RCRRtkeysR.titemsR6R(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestEnum_KeysAndValues>s  ++cCs�tj�}|j|j �|jdt|j��|jjd�|jjd�|jjd�|j|j�|jdt|j��|jdddg|j�|jd|jd�|jd|jd�|jt|jj d�|jt|jj d�|jt |jj d �|jt |jj d�d |jd <|jdd dg|j�|jj d d �|jdd d dg|j�|jjd �|jd d dg|jd d!�|jdd d dd g|j�d�t d�D�|jd d+|jddd dd g|j�dddg|jd d+|jddddd g|j�g}x|jD]}|j|�q{W|jddddd g|�|jd=|jdddd g|j�|jd3|jddg|j�|jjddg�|jddddg|j�|jd�|j|j �|jdt|j��|jjd �|jd |jd�d|jd<|jd|jd�dd ddg|j(|jd=|jdd dg|j�|jd=|jddg|j�|jt|jjd�|jt|jjd�|jdd5|jdg|j�|jdd5|jdg|j�dS(Niii iii����i�i.���RSiiiiicss|] }|VqdS(N((R�R0((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pys rsii#i(i-i R<i����i����i,idi'(RR6RYR<R,R!R|RTR�t __getitem__RUR7tinsertR-R�RZt __delitem__(RR:RR0((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedScalarsMsl  ## ""        cCs�tj�}|j|j �|jdt|j��|jjd�|jjd�|jjd�|jjd�|jdt|j��|jjd�|jdt|j��|jd|jd�|jd|jd�|jd|jd�|jjd�|jdt|j��|jd|jd�|jd|jd�|jjd�|jdt|j��|jd|jd�|jt |jjd�dS( Niii iiiii{( RR6RYR<R,R!R|tremoveRTR�(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedScalarsRemove�s* c Cs$tj�}|j|j �|jdt|j��|jj�}|jj�}|j|j�|jdt|j��|j||g|j�|j|tjj �|j t |jj d�|j t |jj d�|j t |jj d�|j t |jj d�|jj�}|jj�}|jj�}|j|||g|jdd!�|j|||||g|j�|j||g|jd �|j|||g|jd�|j||jd�|j|g|jd �g}x|jD]}|j|�qW|j|||||g|�|jd=|j||||g|j�|jd3|j||g|j�tjj dd�} tjj dd�} |jj| | g�|jdt|j��|j| |jd�|j| |jd �|j t |jj| �|j t |jjdg�tj�} |j t |jj| g�|jd �|j|j �|jdt|j��|jjdd �|jdt|j��|jd |jdj�|j t |jjd �|j t��d |jdRR?RJRARKRLRMR�R�t ParseMessageR,(Rt desc_prototfdpRGRNRPtserialized_priust new_prius((RHROsL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestDescriptorProtoSupportQsN       .      cCs�tj�}tj}|j|j|� �|jd|j|�|j|j|� �d|j|<|jd|j|�|j|j|��|j|�|jd|j|�|j|j|� �dS(Nii(RR�R�RYt HasExtensionR,R�tClearExtension(Rtextendee_protot extension((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt'testTopLevelExtensionsForOptionalScalar�s    cCs�tj�}tj}|jdt|j|��|j|jd�|jdg|j|�|j|}|j|�|jdt|j|��|j||j|k �|j t t j |j|d�dS(NiRSRJ( RR�R�R,R!R�R|R`RYRTRUtoperatortsetitem(RRaRbt string_list((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt'testTopLevelExtensionsForRepeatedScalar�s    cCs=tj�}tj}|j|j|� �|jd|j|j�|j|j|� �d|j|_|jd|j|j�|j|j|��|j|}|j|�|j||j|k �d|_|jd|j�|j|j d��|j|j|� �|j t t j |j|d�dS(Niii*RHRJ(RR�t"optional_foreign_message_extensionRYR_R,R�RHR`R9RTRURdRe(RRaRbtforeign_message((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt(testTopLevelExtensionsForOptionalMessage�s"     cCstj�}tj}|jdt|j|��|j|j�}d|_|jd|j|dj�d|_|jd|j|dj�|j|}|j|�|jdt|j|��|j ||j|k �|j t t j |j|d�dS(Niii*RJ(RR�trepeatedgroup_extensionR,R!R�R~RJR`RYRTRURdRe(RRaRbtgroupt group_list((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt(testTopLevelExtensionsForRepeatedMessage�s      cCs�tj�}tjj}|j|j|� �|j|}|jd|j�|j|j|� �d|_|jd|j|j�|j|j|��|j |�|j||j|k �|j|j|� �dS(Nii( RR�t TestRequiredtsingleRYR_R�R,RJR`(RRaRbtrequired((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestNestedExtensions�s     cCsvtjj}|j|jtjjd��|j|jd�jtjj�|j dt |j tj j���dS(Nis*protobuf_unittest.optional_int32_extensioni( RR�tpoolRYtFindExtensionByNumberR�tassertIstFindExtensionByNameR&R,R!tFindAllExtensionsR6(RRs((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRegisteredExtensions�s    cCs�tj�}|j|jd� �|jd|jjtj�|j|jd� �d|jjtj<|jd|jjtj�|j|jd��tj�}|j|jd� �|jg|jjtj�|j|jd� �|jjtjj d�|jdg|jjtj�|j|jd��tj�}|j|jd� �|jd|jjtj j �|j|jd� �d|jjtj _ |jd|jjtj j �|j|jd��tj�}|j|jd� �|jdt |jjtj ��|j|jd� �|jjtj j�}|j||jjtj d�|j|jd��dS(Nt submessageii(R tTopLevelMessageRYR9R,RyR�toptional_int_extensiontrepeated_int_extensionR|toptional_message_extensiontforeign_message_intR!trepeated_message_extensionR~(Rttopleveltforeign((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt(testHasBitsForAncestorsOfExtendedMessage�sL          cCs_tj�}|j}tj}|j|}|j|�d|_|j||j|k �dS(Ni(R RzRyR}R�R`R~RY(RR�RaRbtextension_proto((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt*testDisconnectionAfterClearingEmptyMessage*s      cCstj�}|jt|jd�|jt|jd�|jt|jjd�|jt|jjdd�x�t j t j t j t j fD]g}|jt|j|�|jt|j|�|jt|jj|�|jt|jj|d�q�W|jt|jtj�dS(Ni�i(RR�RTtKeyErrorR_R`R�R R�R R{R}R|RR�(RRatunknown_handle((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestExtensionFailureModes4s&  cCsKtj�}tj|�|j�}tjj|�}|j||�dS(N(RR6R t SetAllFieldsR�t FromStringR,(RRststring1Rt((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestStaticParseFromSs    cCsatj�}d|_tj�}d|_|j|�|jd|j�|jd|j�dS(NiR�(RR6R2R4RrR,(RRsRt((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestMergeFromSingularField]s     cCs�tj�}|jjd�|jjd�tj�}|jjd�|j|�|jd|jd�|jd|jd�|jd|jd�dS(Niii(RR6R<R|RrR,(RRsRt((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestMergeFromRepeatedFieldjs   cCsKtj�}d|j_tj�}|j|�|jd|jj�dS(Ni (RR6ReRJRrR,(RRsRt((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestMergeFromOptionalGroupxs     cCs,tj�}|jj�}d|_|jj�}d|_tj�}|jj�}d|_|j|�|jd|jdj�|jd|jdj�|jd|jdj�tj�}|jj|j�|jd|jdj�|jd|jdj�|jd|jdj�dS(Ni{iAi�iii(RR6RER~RFRrR,(RRstmRttproto3((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt"testMergeFromRepeatedNestedMessage�s"       cCsntj�}tj|�tj�}|j|�|j||�|j�}|j�}|j||�dS(N(RR6R R�RrR,R�(RRsRtR�tstring2((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestMergeFromAllFields�s      cCsStj�}d|jtjd|�qNW|dd�|d d�|d d�dS( Ncs7�jj�|�j_�j|d�j��dS(Ni(R:R�R�R,R(R0texpected_varint_size(R(sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pytTest#s  iiii?i'i����i i����ll����(tzipR-(RRR0t num_bytes((RsL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt testVarints"s  1  cCs�d|j_|jd|j��d|j_|jdt|jj�|j��dd|j_|jdt|jj�|j��dS(NR�iR�R�i�i(R:R4R,RR!(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt testStrings1s   &cCs�d|j_|jd|j��tj�|_d|j_|jd|j��tj�|_d|j_|jd|j��tj�|_d|j_|jd|j��tj�|_d|j_ |jd|j��tj�|_dS(Ni�ii gX9��v��?i@i( R:R�R,RRR6R�R5R3R�(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestOtherNumerics>s     cCs)d|jj_|jd|j��dS( Niiiii@iii(R:RQRFR,R(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestCompositesXscCs-d|jj_|jdd|j��dS(Niiiii ii(R:ReRJR,R(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt testGroups`scCsD|jjjd�|jjjd�|jdd|j��dS(Ni i�iiii(R:R<R|R,R(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyRgscCs7|jjjddg�|jdd|j��dS(Ni i�iiii(R:R<R�R,R(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedScalarsExtendmscCsm|jjjd�|jjjd�|jdd|j��|jjjd�|jd|j��dS(Ni i�iiiii(R:R<R|R,RR(R((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyRrs cCsG|jjj�}|jjj�}d|_|jd|j��dS( Niiiiiiii(R:RER~RFR,R(Rtforeign_message_0tforeign_message_1((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyRzs cCss|jjj�}|jjj�}d|_|jd |j��tj|jj�}|jjd=|jd|j��|jjj�}d|_|jd|j��|jjd=|jd|j��|jjd=|jd|j��|jdt|��|dd5t j �dkr=|jdt|��n|d=t j �dkro|jdt|��ndS(Ni iiii Rvi����iiiiiiiiiiiiii i iii( R:RER~RFR,RR�R�R!RRx(RR'R(REtforeign_message_2((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedCompositesDelete�s,      cCsG|jjj�}|jjj�}d|_|jd|j��dS( Niiiiiii i (R:RIR~RJR,R(Rtgroup_0tgroup_1((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestRepeatedGroups�s cCs�tj�}|jd|j��tj}d|j|<|jd|j��tjjjd}|j t ��d|j|D s8      6 )  3 !       t OptionsTestcBseZd�Zd�ZRS(cCsTtj�}|jt|jj�j�tj�}|jt |jj�j�dS(N( R R�R,RAR�RYRZRR6RB(RR:((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestMessageOptionsw s     cCs�tj�}d|_d|_x3|j�D]%\}}|jt|j�j�q+Wtj �}|j j d�|j j d�xL|j�D]>\}}|jt |j�j�|jtjj|j�q�WdS(Nig@(RR6R2R3R�R,RBRYRyRR7R|R8RARR5RWR$(RR:tfield_descriptort_((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestPackedOptions s    (R#R$R�R�(((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyR�u s t ClassAPITestcBs�eZejej�dko-ej�dkd�d��Zd�Ze j d�d��Z e j d�d��Z e j d�d��Z RS( R�is6C++ implementation requires a call to MakeDescriptor()cCs$tjddddddgdgdgdg�}tjd d ddddgd|gdgdg�}tjd d ddddgdgdgdg�}tjd dddddgd||gdgdg�}tj|�}|jd |j�|jd |j�|jd|jj�dS(Ntleafspackage.parent.child.leafR�R&R1R/R0R2R2spackage.parent.childtsiblingspackage.parent.siblingtparentspackage.parent(RR:R7Rt MakeClassR�t__dict__R2(Rt leaf_desct child_desct sibling_desct parent_desct message_class((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt!testMakeClassWithNestedDescriptor� s(          cCs4d|d}tj�}tj||�|j�S(s Get a serialized representation of a test FileDescriptorProto. Args: name: All calls to this must use a unique message name, to avoid collisions in the cpp descriptor pool. Returns: A string containing the serialized form of a test FileDescriptorProto. smessage_type { name: "si" field { name: "flat" number: 1 label: LABEL_REPEATED type: TYPE_UINT32 } field { name: "bar" number: 2 label: LABEL_OPTIONAL type: TYPE_MESSAGE type_name: "Bar" } nested_type { name: "Bar" field { name: "baz" number: 3 label: LABEL_OPTIONAL type: TYPE_MESSAGE type_name: "Baz" } nested_type { name: "Baz" enum_type { name: "deep_enum" value { name: "VALUE_A" number: 0 } } field { name: "deep" number: 4 label: LABEL_OPTIONAL type: TYPE_UINT32 } } }}(RR�RtMergeR�(RRtfile_descriptor_strtfile_descriptor((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt_GetSerializedFileDescriptor� s ) s MakeDescriptor is not repeatablecs�tj�dkrdStj�}|j|jd��tj|jd��dt j t j t j�f�fd��Y}|�}d}tj||�|j|jddd g�dS( s7Test that the generated class can parse a flat message.RvNtAit MessageClasscseZ�ZRS((R#R$R�((tmsg_descriptor(sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyR�� ssflat: 0 flat: 1 flat: 2 ii(RRxRR�R�R�RRXR'R<R=RR>RR?RR�R,tflat(RR�R�R�tmsg_str((R�sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt0testParsingFlatClassWithExplicitClassDeclaration� s  . cCs�tj�}|j|jd��tj|jd�}tj|�}|�}d}t j ||�|j |j dddg�dS(s7Test that the generated class can parse a flat message.tBisflat: 0 flat: 1 flat: 2 iiN( RR�R�R�RRXR'RR�RR�R,R�(RR�R�t msg_classR�R�((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestParsingFlatClass� s  cCs�tj�}|j|jd��tj|jd�}tj|�}|�}d}t j ||�|j |j j jd�dS(s9Test that the generated class can parse a nested message.tCisbar { baz { deep: 4 }}iN(RR�R�R�RRXR'RR�RR�R,R�R�tdeep(RR�R�R�R�R�((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyttestParsingNestedClass s  (R#R$R�R�RRxR�R�R�RtSkipReferenceLeakCheckerR�R�R�(((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyR�� s! 8t__main__()R%R�RmRdR<Rt unittest2R�t ImportErrortgoogle.protobufRRRRRRRRR�RR R R R R RRt BaseTestCasetobjectRR+R�RRRRR>R�R�R#tmain(((sL/usr/lib/python2.7/site-packages/google/protobuf/internal/reflection_test.pyt#s`       -�������V! �9��3�