
    
                         d Z ddlmZ  G d dej                        Z G d de      Zd Z G d d	ej                        Z G d
 de      Z	d Z
y)zFCode that's shared between multiple router route policies subcommands.    )
exceptionsc                       e Zd ZdZy)RoutePolicyErrorzFError superclass for all router route policies surface-related errors.N__name__
__module____qualname____doc__     Dlib/googlecloudsdk/command_lib/compute/routers/route_policy_utils.pyr   r      s    Nr   r   c                   "     e Zd ZdZ fdZ xZS )PolicyTermNotFoundErrorz-Error raised when a policy term is not found.c                 P    dj                  |      }t        t        |   |       y )Nz(Policy term [{term_priority}] not found.)term_priority)formatsuperr   __init__)selfr   msg	__class__s      r   r   z PolicyTermNotFoundError.__init__   s-    
4
;
;# < C 

!41#6r   r   r   r	   r
   r   __classcell__r   s   @r   r   r      s    57 7r   r   c                 `    | j                   D ]  }|j                  |k(  s|c S  t        |      )aI  Searches for and returns a term in the route policy resource.

  Args:
    resource: The route policy resource to find term for.
    term_priority: The priority of the term to find.

  Returns:
    The term with the given priority, if found.

  Raises:
    PolicyTermNotFoundError: If no term with the given priority is found.
  )termspriorityr   )resourcer   terms      r   FindPolicyTermOrRaiser    "   s0     nnd}}%k  	 ..r   c                       e Zd ZdZy)NamedSetErrorzAError superclass for all router named set surface-related errors.Nr   r   r   r   r"   r"   5   s    Ir   r"   c                   "     e Zd ZdZ fdZ xZS )NamedSetElementNotFoundErrorz3Error raised when a named set element is not found.c                 P    dj                  |      }t        t        |   |       y )Nz&Named set element {element} not found.)element)r   r   r$   r   )r   r&   r   r   s      r   r   z%NamedSetElementNotFoundError.__init__<   s&    
2
9
9'
9
JC	
&6s;r   r   r   s   @r   r$   r$   9   s    ;< <r   r$   c                 `    | j                   D ]  }|j                  |k(  s|c S  t        |      )al  Searches for and returns an element in the named set resource.

  Args:
    resource: The named set resource to find element for.
    element_cel: The CEL expression of the element to find.

  Returns:
    The element with the given CEL expression, if found.

  Raises:
    NamedSetElementNotFoundError: If no element with the given CEL expression is
    found.
  )elements
expressionr$   )r   element_celr&   s      r   FindNamedSetElementOrRiser+   A   s4     ""g[(n # 	%[11r   N)r
   googlecloudsdk.corer   core_exceptionsErrorr   r   r    r"   r$   r+   r   r   r   <module>r/      sY    M =O,, O7. 7/&JO)) J<= <2r   