
    0Vh                     T    d Z ddlmZ  G d d      Z G d de      Z G d de      Zy	)
zDefines *private* classes used for flag validators.

Do NOT import this module. DO NOT use anything from this module. They are
private APIs.
    )_exceptionsc                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)		Validatorz|Base class for flags validators.

  Users should NOT overload these classes, and use flags.Register...
  methods instead.
  r   c                 |    || _         || _        t        xj                  dz  c_        t        j                  | _        y)a!  Constructor to create all validators.

    Args:
      checker: function to verify the constraint.
          Input of this method varies, see SingleFlagValidator and
          multi_flags_validator for a detailed description.
      message: str, error message to be shown to the user.
       N)checkermessager   validators_countinsertion_index)selfr   r	   s      N/home/dcms/DCMS/lib/python3.12/site-packages/absl/flags/_validators_classes.py__init__zValidator.__init__"   s1     DLDL!#$55D    c                     | j                  |      }| j                  |      st        j                  | j                        y)a  Verifies that constraint is satisfied.

    flags library calls this method to verify Validator's constraint.

    Args:
      flag_values: flags.FlagValues, the FlagValues instance to get flags from.
    Raises:
      Error: Raised if constraint is not satisfied.
    N)_get_input_to_checker_functionr   r   ValidationErrorr	   )r   flag_valuesparams      r   verifyzValidator.verify1   s:     //<E<<''55 r   c                     t        d      )zpReturns the names of the flags checked by this validator.

    Returns:
      [string], names of the flags.
     This method should be overloadedNotImplementedErrorr   s    r   get_flags_nameszValidator.get_flags_names?   s     @
AAr   c                     t        d      )Nr   r   r   r   s     r   print_flags_with_valuesz!Validator.print_flags_with_valuesG   s    
@
AAr   c                     t        d      )zGiven flag values, returns the input to be given to checker.

    Args:
      flag_values: flags.FlagValues, containing all flags.
    Returns:
      The input to be given to checker. The return type depends on the specific
      validator.
    r   r   r   s     r   r   z(Validator._get_input_to_checker_functionJ   s     @
AAr   N)
__name__
__module____qualname____doc__r
   r   r   r   r   r    r   r   r   r      s+     66BB	Br   r   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )SingleFlagValidatora  Validator behind register_validator() method.

  Validates that a single flag passes its checker function. The checker function
  takes the flag value and returns True (if value looks fine) or, if flag value
  is not valid, either returns False or raises an Exception.
  c                 4    t         |   ||       || _        y)a  Constructor.

    Args:
      flag_name: string, name of the flag.
      checker: function to verify the validator.
          input  - value of the corresponding flag (string, boolean, etc).
          output - bool, True if validator constraint is satisfied.
              If constraint is not satisfied, it should either return False or
              raise flags.ValidationError(desired_error_message).
      message: str, error message to be shown to the user if validator's
          condition is not satisfied.
    N)superr   	flag_name)r   r)   r   r	   	__class__s       r   r   zSingleFlagValidator.__init__^   s     
GWg&DNr   c                     | j                   gS N)r)   r   s    r   r   z#SingleFlagValidator.get_flags_namesn   s    NNr   c                 T    d| j                   d|| j                      j                  S )Nzflag --=r)   valuer   s     r   r   z+SingleFlagValidator.print_flags_with_valuesq   s     !^^[-H-N-NOOr   c                 4    || j                      j                  S )zGiven flag values, returns the input to be given to checker.

    Args:
      flag_values: flags.FlagValues, the FlagValues instance to get flags from.
    Returns:
      object, the input to be given to checker.
    r/   r   s     r   r   z2SingleFlagValidator._get_input_to_checker_functiont   s     t~~&,,,r   )	r    r!   r"   r#   r   r   r   r   __classcell__r*   s   @r   r&   r&   V   s     P-r   r&   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )MultiFlagsValidatora  Validator behind register_multi_flags_validator method.

  Validates that flag values pass their common checker function. The checker
  function takes flag values and returns True (if values look fine) or,
  if values are not valid, either returns False or raises an Exception.
  c                 4    t         |   ||       || _        y)a  Constructor.

    Args:
      flag_names: [str], containing names of the flags used by checker.
      checker: function to verify the validator.
          input  - dict, with keys() being flag_names, and value for each
              key being the value of the corresponding flag (string, boolean,
              etc).
          output - bool, True if validator constraint is satisfied.
              If constraint is not satisfied, it should either return False or
              raise flags.ValidationError(desired_error_message).
      message: str, error message to be shown to the user if validator's
          condition is not satisfied
    N)r(   r   
flag_names)r   r7   r   r	   r*   s       r   r   zMultiFlagsValidator.__init__   s     
GWg& DOr   c                 \    | j                   D ci c]  }|||   j                   c}S c c}w )a7  Given flag values, returns the input to be given to checker.

    Args:
      flag_values: flags.FlagValues, the FlagValues instance to get flags from.
    Returns:
      dict, with keys() being self.flag_names, and value for each key
      being the value of the corresponding flag (string, boolean, etc).
    )r7   r0   )r   r   keys      r   r   z2MultiFlagsValidator._get_input_to_checker_function   s,     48??CCCS!'''CCCs   )c                     d}g }| j                   D ]%  }|j                  |d||   j                         ' |dj                  |      z   S )Nzflags r.   z, )r7   appendr0   join)r   r   prefixflags_with_valuesr9   s        r   r   z+MultiFlagsValidator.print_flags_with_values   sU    F H#{3/?/E/EFGHDII/000r   c                     | j                   S r,   )r7   r   s    r   r   z#MultiFlagsValidator.get_flags_names   s    ??r   )	r    r!   r"   r#   r   r   r   r   r2   r3   s   @r   r5   r5      s    !$	D1r   r5   N)r#   
absl.flagsr   r   r&   r5   r$   r   r   <module>rA      s5    #;B ;B|&-) &-R-) -r   