
    G                         S r SSKJr  SSKJr   SSKJr  SrSrSr	S	r
 " S
 S5      r " S S\R                  5      rS/rg! \ a    Sr N5f = f)zThis module contains the MessageSet class, which is a special kind of
protocol message which can contain other protocol messages without knowing
their types.  See the class's doc string for more information.    )ProtocolBuffer)log)_net_proto___parse__pythonN            c                   x    \ rS rSrSrSS jrS rS rS rS r	S	 r
SS
 jrS rS rS rS rS r\" \5      rSrg)Item,   aG  This class is used internally by MessageSet.

This class represents a particular message in the set.  The message may be
either parsed or unparsed.  The point of this class is to provide a nice
wrapper for all of the standard protocol buffer operations so that the
caller does not have to check if the message is parsed or not.Nc                     Xl         X l        g Nmessagemessage_class)selfr   r   s      1lib/googlecloudsdk/appengine/proto/message_set.py__init__Item.__init__4   s    L&    c                 (    U" 5       U l         Xl        g r   r   r   r   s     r   SetToDefaultInstanceItem.SetToDefaultInstance8   s     ?DL&r   c                     U R                   b  g U" 5       nUR                  U R                  5        X l        Xl         g! [        R                   a%    [
        R                  SUR                  -   5         gf = f)z@Upgrades the Item to a parsed one, returning true if successful.   z>Parse error in message inside MessageSet.  Tried to parse as: r   )r   MergePartialFromStringr   r   ProtocolBufferDecodeErrorloggingwarn__name__)r   r   message_objs      r   Parse
Item.Parse<   sv     %	!Ok((6 l(33 ll #%2%;%;< =s   .? 6A87A8c                    U R                   bG  UR                  U R                   5      (       a&  U R                  R                  UR                  5        ggUR                   bl  U R                  UR                   5      (       d&  UR                  5       U l        UR                   U l         U R                  R                  UR                  5        gU =R                  UR                  -  sl        g)zkMerges two items.

If one item is parsed and one is not, an attempt will be made to parse
the unparsed one.N)r   r#   r   	MergeFromr   others     r   r&   Item.MergeFromM   s     %	T''	(	(u}}- 
)
 
			(ZZ++,,**,"00
llU]]+ llemm#lr   c                     U R                   c  [        U R                  5      $ U R                  5       nUR                  U R                  5        [        XR                   5      $ )zMake a deep copy of the Item.)r   r   r   CopyFrom)r   new_messages     r   Copy	Item.Copyc   sP     !$,,&&(k4<<(+1122r   c                    U R                   bF  UR                  U R                   5      (       d  gU R                  R                  UR                  5      $ UR                   bF  U R                  UR                   5      (       d  gU R                  R                  UR                  5      $ U R                  UR                  :H  $ )zCheck if two items are equal.

If one message is parsed and the other is not, an attempt will be made
to parse the unparsed one.r   )r   r#   r   Equalsr'   s     r   r0   Item.Equalsm   s     %[[++,,Q\\  //				(ZZ++,,Q\\  // \\U]]**r   c                 T    U R                   c  gU R                  R                  U5      $ )z]Calls IsInitialized on the contained message if it is parsed, or just
returns true otherwise.r   )r   r   IsInitialized)r   
debug_strss     r   r3   Item.IsInitialized~   s(     !\\''
33r   c                     SnU R                   c  [        U R                  5      nOU R                  R                  5       nUR	                  U5      UR                  U5      -   S-   $ )z&Returns the encoded size of this item.r      )r   lenr   ByteSizelengthStringlengthVarInt64r   pbtype_idmessage_lengths       r   r9   Item.ByteSize   s[     N!4<<(n||,,.n ??>*R->->w-GG!KKr   c                     SnU R                   c  [        U R                  5      nOU R                  R                  5       nUR	                  U5      UR                  U5      -   S-   $ )zEReturns the encoded size of this item, not counting missing optional.r   r7   )r   r8   r   ByteSizePartialr:   r;   r<   s       r   rB   Item.ByteSizePartial   s[     N!4<<(n||335n ??>*R->->w-GG!KKr   c                 T   UR                  [        5        UR                  U5        UR                  [        5        U R                  c  UR                  U R                  5        gUR                  U R                  R                  5       5        U R                  R                  U5        g)z8Writes the item to the decoder "out", given its type ID.N)	putVarInt32TAG_TYPE_IDputVarUint64TAG_MESSAGEr   putPrefixedStringr   r9   OutputUncheckedr   outr>   s      r   rJ   Item.OutputUnchecked   su     OOK 
 WOOK !	DLL)	oodll++-.
ll""3'r   c                 T   UR                  [        5        UR                  U5        UR                  [        5        U R                  c  UR                  U R                  5        gUR                  U R                  R                  5       5        U R                  R                  U5        g)zaWrites the item to the decoder "out", given its type ID.
Does not assume required fields are set.N)	rE   rF   rG   rH   r   rI   r   rB   OutputPartialrK   s      r   rO   Item.OutputPartial   su     OOK 
 WOOK !	DLL)	oodll2245
ll  %r   c                 <   SnSn U R                  5       nU[        :X  a  OaU[        :X  a  U R                  5       nM8  U[        :X  a  U R                  5       nMT  US:X  a  [        R                  eU R                  U5        M|  US:X  d  Uc  [        R                  eX4$ )zeDecodes a type_id and message buffer from the decoder.  (static)

Returns a (type_id, message) tuple.r   N)	getVarInt32TAG_END_ITEM_GROUPrF   getVarUint64rH   getPrefixedStringr   r   skipData)decoderr>   r   tags       r   DecodeItem.Decode   s    
 GG
!c	"	"		
 &&(		++- 
AAAs# & !|w444r   r   r   )r!   
__module____qualname____firstlineno____doc__r   r   r#   r&   r-   r0   r3   r9   rB   rJ   rO   rY   staticmethod__static_attributes__ r   r   r   r   ,   sR    D''"$,3+"4
L
L( &": &r   r   c                       \ rS rSrSrS!S jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS!S jrS rS rS rS rS rS rS rS rS rS"S jr S r!S r"g)#
MessageSet   a  A protocol message which contains other protocol messages.

This class is a specially-crafted ProtocolMessage which represents a
container storing other protocol messages.  The contained messages can be
of any protocol message type which has been assigned a unique type
identifier.  No two messages in the MessageSet may have the same type,
but otherwise there are no restrictions on what you can put in it.  Accessing
the stored messages involves passing the class objects representing the
types you are looking for:
  assert myMessageSet.has(MyMessageType)
  message = myMessageSet.get(MyMessageType)
  message = myMessageSet.mutable(MyMessageType)
  myMessageSet.remove(MyMessageType)

Message types designed to be stored in MessageSets must have unique
32-bit type identifiers.  Give your message type an identifier like so:
  parsed message MyMessageType {
    enum TypeId {MESSAGE_TYPE_ID = 12345678};
To insure that your type ID is unique, use one of your perforce change
numbers.  Just make sure you only use your own numbers and that you don't
use the same one twice.

The wire format of a MessageSet looks like this:
   parsed message MessageSet {
     repeated group Item = 1 {
       required fixed32 type_id = 2;
       required message<RawMessage> message = 3;
     };
   };
The MessageSet class provides a special interface around this format for
the sake of ease-of-use and type safety.

See message_set_unittest.proto and message_set_py_unittest.py for examples.
Nc                 L    [        5       U l        Ub  U R                  U5        gg)z]Construct a new MessageSet, with optional starting contents
in binary protocol buffer format.N)dictitemsMergeFromString)r   contentss     r   r   MessageSet.__init__  s#     DJT11(;r   c                     UR                   U R                  ;  a  U" 5       $ U R                  UR                      nUR                  U5      (       a  UR                  $ U" 5       $ )a  Gets a message of the given type from the set.

If the MessageSet contains no message of that type, a default instance
of the class is returned.  This is done to match the behavior of the
accessors normally generated for an optional field of a protocol message.
This makes it easier to transition from a long list of optional fields
to a MessageSet.

The returned message should not be modified.
)MESSAGE_TYPE_IDrg   r#   r   r   r   items      r   getMessageSet.get  sS     $$DJJ6_::m334Dzz-  \\_r   c                 $   UR                   U R                  ;  a+  U" 5       n[        X!5      U R                  UR                   '   U$ U R                  UR                      nUR                  U5      (       d  UR	                  U5        UR
                  $ )zGets a mutable reference to a message of the given type in the set.

If the MessageSet contains no message of that type, one is created and
added to the set.
)rl   rg   r   r#   r   r   )r   r   r   rn   s       r   mutableMessageSet.mutable!  sv     $$DJJ6g26w2Ndjj../n::m334D::m$$
.<<r   c                     UR                   U R                  ;  a  gU R                  UR                      nUR                  U5      $ )z7Checks if the set contains a message of the given type.r   )rl   rg   r#   rm   s      r   hasMessageSet.has1  s<     $$DJJ6::m334D::m$$r   c                 4    UR                   U R                  ;   $ )a  Checks if the set contains an unparsed message of the given type.

This differs from has() when the set contains a message of the given type
with a parse error.  has() will return false when this is the case, but
has_unparsed() will return true.  This is only useful for error checking.
rl   rg   r   s     r   has_unparsedMessageSet.has_unparsed9  s     ((DJJ66r   c                 6    U R                   R                  5       $ )zReturn a list of all type ids in the set.

Returns:
  [ cls1.MESSAGE_TYPE_ID, ... ] for each cls in the set.  The returned
  list does not contain duplicates.
)rg   keysr   s    r   
GetTypeIdsMessageSet.GetTypeIdsB  s     ::??r   c                 ,    [        U R                  5      $ )zReturn the number of messages in the set.  For any set the following
invariant holds:
  set.NumMessages() == len(set.GetTypeIds())

Returns:
  number of messages in the set
r8   rg   r}   s    r   NumMessagesMessageSet.NumMessagesK  s     tzz?r   c                 h    UR                   U R                  ;   a  U R                  UR                   	 gg)z3Removes any message of the given type from the set.Nrx   r   s     r   removeMessageSet.removeU  s+    $$

2
**]22
3 3r   c                     UR                   U R                  ;  a  [        U5      eU R                  UR                      nUR                  U5      (       a  UR                  $ [        U5      er   )rl   rg   KeyErrorr#   r   rm   s      r   __getitem__MessageSet.__getitem__]  sW    $$DJJ6]##::m334Dzz-  \\]##r   c                 H    [        X!5      U R                  UR                  '   g r   )r   rg   rl   )r   r   r   s      r   __setitem__MessageSet.__setitem__f  s    04W0LDJJ},,-r   c                 $    U R                  U5      $ r   )ru   r   s     r   __contains__MessageSet.__contains__i  s    88M""r   c                 &    U R                  U5        g r   )r   r   s     r   __delitem__MessageSet.__delitem__l  s    KKr   c                 ,    [        U R                  5      $ r   r   r}   s    r   __len__MessageSet.__len__o  s    tzz?r   c                     XLd   eUR                   R                  5        HQ  u  p#X R                   ;   a   U R                   U   R                  U5        M4  UR                  5       U R                   U'   MS     g)zMerges the messages from MessageSet 'other' into this set.

If both sets contain messages of matching types, those messages will be
individually merged by type.
N)rg   r&   r-   r   r(   r>   rn   s       r   r&   MessageSet.MergeFromu  s^      ;;,,.	JJ	

7%%d+"iik

7	 /r   c                    XL a  g[        U R                  5      [        UR                  5      :w  a  gUR                  R                  5        H;  u  p#X R                  ;  a    gU R                  U   R                  U5      (       a  M;    g   g)z$Checks if two MessageSets are equal.r   r   )r8   rg   r0   r   s       r   r0   MessageSet.Equals  sj    }Q
4::#ekk**1 ;;,,.	

	"1ZZ ''--a / r   c                 z    US L=(       a1    UR                   U R                   :H  =(       a    U R                  U5      $ r   )	__class__r0   r'   s     r   __eq__MessageSet.__eq__  s5    $ __.KK r   c                     X:X  + $ r   ra   r'   s     r   __ne__MessageSet.__ne__  s    r   c                     SnU R                   R                  5        H  nUR                  U5      (       a  M  SnM     U$ )zMChecks if all messages in this set have had all of their required fields
set.r   r   )rg   valuesr3   )r   r4   initializedrn   s       r   r3   MessageSet.IsInitialized  s>     K

!!#
++ $ r   c                     S[        U R                  5      -  nU R                  R                  5        H  u  p#XR                  X5      -  nM     U$ )zEGets the byte size of a protocol buffer representing this MessageSet.r7   )r8   rg   r9   r   nr>   rn   s       r   r9   MessageSet.ByteSize  sC    	C

OA::++-==''a .Hr   c                     S[        U R                  5      -  nU R                  R                  5        H  u  p#XR                  X5      -  nM     U$ )zmGets the byte size of a protocol buffer representing this MessageSet.
Does not count missing required fields.r7   )r8   rg   rB   r   s       r   rB   MessageSet.ByteSizePartial  sG     	
C

OA::++-..a .Hr   c                 "    [        5       U l        g)z"Removes all messages from the set.N)rf   rg   r}   s    r   ClearMessageSet.Clear  s    DJr   c                     U R                   R                  5        H@  u  p#UR                  [        5        UR                  X5        UR                  [        5        MB     g)z+Writes the MessageSet to the encoder 'out'.N)rg   rE   TAG_BEGIN_ITEM_GROUPrJ   rS   r   rL   r>   rn   s       r   rJ   MessageSet.OutputUnchecked  sC    ::++-	oo*+
3(	oo() .r   c                     U R                   R                  5        H@  u  p#UR                  [        5        UR                  X5        UR                  [        5        MB     g)zTWrites the MessageSet to the encoder 'out'.
Does not assume required fields are set.N)rg   rE   r   rO   rS   r   s       r   rO   MessageSet.OutputPartial  sE      ::++-	oo*+
&	oo() .r   c                    UR                  5       S:  a  UR                  5       nU[        :X  ah  [        R	                  U5      u  p4X0R
                  ;   a(  U R
                  U   R                  [        U5      5        O[        U5      U R
                  U'   M  US:X  a  [        R                  eUR                  U5        UR                  5       S:  a  M  gg)zPAttempts to decode a MessageSet from the decoder 'd' and merge it
with this one.r   N)
availrR   r   r   rY   rg   r&   r   r   rV   )r   rW   rX   r>   r   s        r   TryMergeMessageSet.TryMerge  s     --/A
!c	$	$![[1jj 
**W

'
'W
6 $W$**W
 (>CCCs --/A
r   c                 ~    [         c  [        R                  R                  X5      $ [         R                  " U SU5      $ NMessageSetInternal)r   r   ProtocolMessage	_CToASCIIToASCII)r   output_formats     r   r   MessageSet._CToASCII  s:    !)++55dJJ'//
$m5 5r   c                     [         c   [        R                  R                  X5        g [         R                  " U SU5        g r   )r   r   r   
ParseASCIIr   ss     r   r   MessageSet.ParseASCII  s/    !)$$//8 ++D2FJr   c                     [         c   [        R                  R                  X5        g [         R                  " U SU5        g r   )r   r   r   ParseASCIIIgnoreUnknownr   s     r   r   "MessageSet.ParseASCIIIgnoreUnknown  s2    !)$$<<TE 88
$a)r   c                 \   SnU R                   R                  5        H  u  pEUR                  c0  USX4-  -  nUSU[        UR                  5      4-  -  nUSU-  -  nMB  X1< SUR                  R                  < S3-  nX5R                  R                  US-   U5      -  nUSU-  -  nM     U$ )N z	%s[%d] <
z%s  (%d bytes)
z%s>
[z] <
z  )rg   r   r8   r   r!   __str__)r   prefixprintElemNumbertextr>   rn   s         r   r   MessageSet.__str__  s    D::++-				#000"fc$,,.?%@@@&  (:(:(C(CDD$$Vd]ODD&   . Kr   )rg   r   )r   r   )#r!   r[   r\   r]   r^   r   ro   rr   ru   ry   r~   r   r   r   r   r   r   r   r&   r0   r   r   r3   r9   rB   r   rJ   rO   r   r   r   r   r   _PROTO_DESCRIPTOR_NAMEr`   ra   r   r   rc   rc      s    !F<( %74$M#*	 
**$5K) (r   rc   )r^   googlecloudsdk.appengine.protor   googlecloudsdk.corer   r   ImportErrorr   rS   rF   rH   r   r   rc   __all__ra   r   r   <module>r      sv   "B : #$G
   q  q h](// ](~ .y  $#$s   A AA