
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKrS	 rS
 r " S S\R                   5      r " S S\5      r " S S\5      r SS jrg)z=Utilities for interacting with message classes and instances.    )absolute_import)division)unicode_literals)messages)encoding)
exceptionsNc                 *    U(       a  [        X5      $ U $ )a`  Updates given message from diff object recursively.

The function recurses down through the properties of the diff object,
checking, for each key in the diff, if the equivalent property exists on the
message at the same depth. If the property exists, it is set to value from the
diff. If it does not exist, that diff key is silently ignored. All diff keys
are assumed to be strings.

Args:
  message: An apitools.base.protorpclite.messages.Message instance.
  diff: A dict of changes to apply to the message
    e.g. {'settings': {'availabilityType': 'REGIONAL'}}.

Returns:
  The modified message instance.
)_UpdateMessageHelper)messagediffs     +lib/googlecloudsdk/api_lib/util/messages.pyUpdateMessager      s    " 
..	.    c                     [         R                  " U5       HQ  u  p#[        X5      (       d  M  [        U[        5      (       a  [        [        X5      X   5        ME  [        XU5        MS     U $ )N)six	iteritemshasattr
isinstancedictr
   getattrsetattr)r   r   keyvals       r   r
   r
   2   sQ    --%hcw	C		WW2DI>c" & 
.r   c                       \ rS rSrSrSrg)Error<   z8Indicates an error with an encoded protorpclite message. N__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   <   s    @r   r   c                   8    \ rS rSrSr\S 5       r\S 5       rSrg)DecodeError@   z6Indicates an error in decoding a protorpclite message.c           	      @   U Vs/ s H  n[         R                  " U5      PM     nn[        U5      S:  a9  UR                  SR	                  SR                  [        U5      5      5      5        OU(       a  UR                  US   5        SR                  U5      $ s  snf )a  Returns a string representation of a path to a proto field.

The return value represents one or more fields in a python dictionary
representation of a message (json/yaml) that could not be decoded into the
message as a string. The format is a dot separated list of python like sub
field references (name, name[index], name[name]). The final element of the
returned dot separated path may be a comma separated list of names enclosed
in curly braces to represent multiple subfields (see examples)

Examples:
  o Reference to a single field that could not be decoded:
    'a.b[1].c[x].d'

  o Reference to two subfields
    'a.b[1].c[x].{d,e}'

Args:
  edges: List of objects representing python field references
         (__str__ suitably defined.)
  field_names: List of names for subfields of the message
     that could not be decoded.

Returns:
  A string representation of a python reference to a filed or
  fields in a message that could not be decoded as described
  above.
   z{{{}}},r   .)r   	text_typelenappendformatjoinsorted)clsedgesfield_namesedgepaths        r   _FormatProtoPathDecodeError._FormatProtoPathC   s{    < -22EDCMM$ED2
;! kk(//#((6++>"?@A	 kk+a.!88D> 3s    Bc                     [        U5      R                  nSR                  US9nU VVs/ s H#  u  pVSR                  X0R                  XV5      S9PM%     nnnU " SR	                  U/U-   5      5      $ s  snnf )zReturns a DecodeError from a list of locations of errors.

Args:
  message: The protorpc Message in which a parsing error occurred.
  errors: List[(edges, field_names)], A list of locations of errors
      encountered while decoding the message.
z/Failed to parse value(s) in protobuf [{type_}]:)type_z  {type_}.{path})r:   r6   
)typer   r/   r7   r0   )r2   r   errorsr:   base_msgr3   r4   error_pathss           r   FromErrorPathsDecodeError.FromErrorPathsn   s     M""E@GG H H .45-3)u &,,..uB - D-3  5 tyy(k12335s   *A2r   N)	r   r    r!   r"   r#   classmethodr7   r@   r$   r   r   r   r&   r&   @   s,    >( (T 4 4r   r&   c                       \ rS rSrSrSrg)ScalarTypeMismatchError   zGIncicates a scalar property was provided a value of an unexpected type.r   Nr   r   r   r   rD   rD      s    Or   rD   c           	      r    [         R                  " X5      n[        [         R                  " U5      5      nU(       a  U(       a  [        R                  X45      eU$ ! [        R                   a<  n[        SR                  UR                  [        R                  " U5      S95      eSnAf[         a    e f = f)a  Convert "dict_" to a message of type message_type and check for errors.

A common use case is to define the dictionary by deserializing yaml or json.

Args:
  dict_: The dict to parse into a protorpc Message.
  message_type: The protorpc Message type.
  throw_on_unexpected_fields: If this flag is set, an error will be raised if
  the dictionary contains unrecognized fields.

Returns:
  A message of type "message_type" parsed from "dict_".

Raises:
  DecodeError: One or more unparsable values were found in the parsed message.
zBFailed to parse value in protobuf [{type_}]:
  {type_}.??: "{msg}")r:   msgN)	_encodingDictToMessagelistUnrecognizedFieldIterr&   r@   	_messagesValidationErrorrD   r/   r   r   r,   AttributeError)dict_message_typethrow_on_unexpected_fieldsr   r=   es         r   DictToMessageWithErrorCheckrS      s    &%%e:G )11':;F,&&w77N# 
	"	" @ "	  &''S]]1-= !' !?@ @ 
 
 
	
s   A B607B''B6)T)r#   
__future__r   r   r   apitools.base.protorpcliter   rL   apitools.base.pyr   rH   googlecloudsdk.corer   r   r   r
   r   r&   rD   rS   r   r   r   <module>rX      sd    D &  ' < 2 * 
,AJ A=4% =4@Pk P <@&r   