
    	                    (   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rSSKJ	r	  SS	K
Jr   \R                  r " S
 S\	R                  5      rSrSSS jjrSS jrSS jrSS jrSS jr " S S\R.                  5      rg! \ a    \r NRf = f)z-Wrapper for Cloud Run InstanceSplit messages.    )absolute_import)annotations)division)print_function)unicode_literalsN)
exceptions)run_v1_messagesc                      \ rS rSrSrSrg)&InvalidInstanceSplitSpecificationError"   z:Error to indicate an invalid instance split specification. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       0lib/googlecloudsdk/api_lib/run/instance_split.pyr   r   "   s    Br   r   LATESTc                \    U[         :X  a  U R                  SUS9nU$ U R                  XS9nU$ )a  Creates a new InstanceSplit.

Args:
  messages: The message module that defines InstanceSplit.
  key: The key for the instance split assignment in the InstanceSplits
    mapping.
  percent: Optional percent of instance split to assign.

Returns:
  The newly created InstanceSplit.
T)latestRevisionpercent)revisionNamer   )LATEST_REVISION_KEYInstanceSplit)messageskeyr   results       r   NewInstanceSplitr    -   sC     	##4#IF 
- ###FF	-r   c                H    U R                   (       a  [        $ U R                  $ )zReturns the key for a InstanceSplit.

Args:
  split: InstanceSplit, the InstanceSplit to check

Returns:
  LATEST_REVISION_KEY if split is for the latest revison or
  split.revisionName if not.
)r   r   r   )splits    r   GetKeyr#   @   s     !& 4 4	L%:L:LLr   c                .    U [         :X  a  SU 4nU$ SU 4nU$ )ag  Sorted key function to order InstanceSplit keys.

InstanceSplits keys are one of:
o revisionName
o LATEST_REVISION_KEY

Note LATEST_REVISION_KEY is not a str so its ordering with respect
to revisionName keys is hard to predict.

Args:
  key: Key for a InstanceSplits dictionary.

Returns:
  A value that sorts by revisionName with LATEST_REVISION_KEY
  last.
      )r   )r   r   s     r   SortKeyFromKeyr'   M   s-    " 	XF 
- XF	-r   c                .    [        U 5      n[        U5      $ )zSorted key function to order InstanceSplit objects by key.

Args:
  split: A InstanceSplit.

Returns:
  A value that sorts by revisionName with LATEST_REVISION_KEY
  last.
)r#   r'   )r"   r   s     r   SortKeyFromSplitr)   e   s     	u#		r   c                H    U R                   (       a  U R                   nU$ SnU$ )zBKey function for sorting InstanceSplit objects during __getitem__.r   )r   )r"   r   s     r   _GetItemSortKeyr+   s   s$     #]]EMM'	. 12'	.r   c                  d    \ rS rSrSrS rS rS rS rS r	\
S 5       rS	 rS
 rS rS rS rSrg)InstanceSplits}   ab  Wraps a repeated InstanceSplit message and provides dict-like access.

The dictionary key is one of
   LATEST_REVISION_KEY for the latest revision
   InstanceSplit.revisionName for InstanceSplits with a revision name.

The dictionary value is a list of all instance split assignments referencing
the same revision, either by name or the latest revision.
c                R    Xl         X l        U R                   R                  U l        g)a  Constructs a new InstanceSplits instance.

The InstanceSplits instance wraps the to_wrap argument, which is a repeated
proto message. Operations that mutate to_wrap will usually occur through
this class, but that is not a requirement. Callers can directly mutate
to_wrap by accessing the proto directly.

Args:
  messages_module: The message module that defines InstanceSplit.
  to_wrap: The instance split assignments to wrap.
N)	_messages_mr   _instance_split_cls)selfmessages_moduleto_wraps      r   __init__InstanceSplits.__init__   s      %NG#~~;;Dr   c                p   ^ [        U4S jU R                   5       [        S9nU(       d  [        T5      eU$ )a  Gets a sorted list of instance split assignments associated with the given key.

Allows accessing instance split assignments based on the revision they
reference
(either directly by name or the latest ready revision by specifying
"LATEST" as the key).

Returns a sorted list of instance split assignments to support comparison
operations on
InstanceSplits objects which should be independent of the order of the
instance split assignments for a given key.

Args:
  key: A revision name or "LATEST" to get the instance split assignments
    for.

Returns:
  A sorted list of instance split assignments associated with the given key.

Raises:
  KeyError: If this object does not contain the given key.
c              3  J   >#    U  H  n[        U5      T:X  d  M  Uv   M     g 7fNr#   ).0ir   s     r   	<genexpr>-InstanceSplits.__getitem__.<locals>.<genexpr>   s     0GqvayC/Gs   #	#)r   )sortedr1   r+   KeyError)r3   r   r   s    ` r   __getitem__InstanceSplits.__getitem__   s1    . 0DGG0oF SMMr   c                    [        5       ezNot implemented for now.NotImplementedError)r3   r   s     r   __delitem__InstanceSplits.__delitem__       

r   c                    [        5       erE   rF   )r3   r   
new_splitss      r   __setitem__InstanceSplits.__setitem__   rJ   r   c                L    U R                    H  nU[        U5      :X  d  M    g   g)z(Implements evaluation of `item in self`.TF)r1   r#   )r3   r   r"   s      r   __contains__InstanceSplits.__contains__   s$    	u	  r   c                :    [        S U R                   5       5      $ )z$A set containing the mapping's keys.c              3  8   #    U  H  n[        U5      v   M     g 7fr:   r;   )r<   r=   s     r   r>   *InstanceSplits._key_set.<locals>.<genexpr>   s     *'Qvayy's   )setr1   r3   s    r   _key_setInstanceSplits._key_set   s     *$''***r   c                ,    [        U R                  5      $ )z%Implements evaluation of `len(self)`.)lenrW   rV   s    r   __len__InstanceSplits.__len__   s    t}}r   c                ,    [        U R                  5      $ )z<Returns an iterator over the instance split assignment keys.)iterrW   rV   s    r   __iter__InstanceSplits.__iter__   s    r   c                    U R                   $ r:   )r1   rV   s    r   MakeSerializableInstanceSplits.MakeSerializable   s    77Nr   c                X    SR                  S U R                  5        5       5      nSU-  $ )Nz, c              3  H   #    U  H  u  pS R                  X5      v   M     g7f)z{}: {}N)format)r<   kvs      r   r>   *InstanceSplits.__repr__.<locals>.<genexpr>   s     G,$!--,s    "z[%s])joinitems)r3   contents     r   __repr__InstanceSplits.__repr__   s'    iiG$**,GGGGr   c                b    U R                   R                  [        U R                  X5      5        g)zAdd a new instance split assignments for the given key.

Mainly for testing.

Args:
  key: Name of the revision (or "LATEST") to set the percent for.
  percent: Percent of instance split to set.
N)r1   appendr    r0   )r3   r   r   s      r   AddSplitInstanceSplits.AddSplit   s      	GGNN#DNNCABr   )r2   r1   r0   N)r   r   r   r   r   r6   rB   rH   rM   rP   propertyrW   r[   r_   rb   rm   rq   r   r   r   r   r-   r-   }   sN    < <   + +	Cr   r-   r:   )r   str)r"   zrun_v1_messages.InstanceSplit)r   
__future__r   r   r   r   r   collectionsgooglecloudsdk.corer   ,googlecloudsdk.generated_clients.apis.run.v1r	   abccollections_abcAttributeErrorErrorr   r   r    r#   r'   r)   r+   MutableMappingr-   r   r   r   <module>r~      s    4 & "  % '  * H OO/
Z-=-=   &
M0eC_33 eC   / s   B BB