Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib/python3.5/site-packages/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/__pycache__/gflags_validators.cpython-35.opt-1.pyc



0�]*�@shdZdZGdd�de�ZGdd�de�ZGdd�de�ZGdd	�d	e�Zd
S)z�Module to enforce different constraints on flags.

A validator represents an invariant, enforced over a one or more flags.
See 'FLAGS VALIDATORS' in gflags.py's docstring for a usage manual.
z#olexiy@google.com (Olexiy Oryeshko)c@seZdZdZdS)�Errorz0Thrown If validator constraint is not satisfied.N)�__name__�
__module__�__qualname__�__doc__�rr�B/opt/alt/python35/lib/python3.5/site-packages/gflags_validators.pyr'src@sXeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�	Validatorz}Base class for flags validators.

  Users should NOT overload these classes, and use gflags.Register...
  methods instead.
  �cCs1||_||_tjd7_tj|_dS)aConstructor to create all validators.

    Args:
      checker: function to verify the constraint.
        Input of this method varies, see SimpleValidator and
          DictionaryValidator for a detailed description.
      message: string, error message to be shown to the user
    �N)�checker�messager�validators_countZinsertion_index)�selfrrrrr�__init__5s			zValidator.__init__cCs1|j|�}|j|�s-t|j��dS)z�Verify that constraint is satisfied.

    flags library calls this method to verify Validator's constraint.
    Args:
      flag_values: gflags.FlagValues, containing all flags
    Raises:
      Error: if constraint is not satisfied.
    N)�_GetInputToCheckerFunctionrrr)r�flag_valuesZparamrrr�VerifyDs	zValidator.VerifycCstd��dS)znReturn the names of the flags checked by this validator.

    Returns:
      [string], names of the flags
    z This method should be overloadedN)�NotImplementedError)rrrr�
GetFlagsNamesQszValidator.GetFlagsNamescCstd��dS)Nz This method should be overloaded)r)rrrrr�PrintFlagsWithValuesYszValidator.PrintFlagsWithValuescCstd��dS)z�Given flag values, construct the input to be given to checker.

    Args:
      flag_values: gflags.FlagValues, containing all flags.
    Returns:
      Return type depends on the specific validator.
    z This method should be overloadedN)r)rrrrrr\sz$Validator._GetInputToCheckerFunctionN)
rrrrr
rrrrrrrrrr+s
rcsLeZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�S)
�SimpleValidatoraValidator behind RegisterValidator() 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.cs&tt|�j||�||_dS)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 - Boolean. Must return True if validator constraint is satisfied.
          If constraint is not satisfied, it should either return False or
          raise Error.
      message: string, error message to be shown to the user if validator's
        condition is not satisfied
    N)�superrr�	flag_name)rrrr)�	__class__rrrms
zSimpleValidator.__init__cCs
|jgS)N)r)rrrrr}szSimpleValidator.GetFlagsNamescCsd|j||jjfS)Nzflag --%s=%s)r�value)rrrrrr�sz$SimpleValidator.PrintFlagsWithValuescCs||jjS)z�Given flag values, construct the input to be given to checker.

    Args:
      flag_values: gflags.FlagValues
    Returns:
      value of the corresponding flag.
    )rr)rrrrrr�sz*SimpleValidator._GetInputToCheckerFunction)rrrrrrrrrr)rrrgs
rcsLeZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�S)
�DictionaryValidatoraValidator behind RegisterDictionaryValidator 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.
  cs&tt|�j||�||_dS)aXConstructor.

    Args:
      flag_names: [string], containing names of the flags used by checker.
      checker: function to verify the validator.
        input  - dictionary, with keys() being flag_names, and value for each
          key being the value of the corresponding flag (string, boolean, etc).
        output - Boolean. Must return True if validator constraint is satisfied.
          If constraint is not satisfied, it should either return False or
          raise Error.
      message: string, error message to be shown to the user if validator's
        condition is not satisfied
    N)rrr�
flag_names)rrrr)rrrr�szDictionaryValidator.__init__cs t�fdd�|jD��S)aGiven flag values, construct the input to be given to checker.

    Args:
      flag_values: gflags.FlagValues
    Returns:
      dictionary, with keys() being self.lag_names, and value for each key
        being the value of the corresponding flag (string, boolean, etc).
    c3s"|]}|�|jgVqdS)N)r)�.0�key)rrr�	<genexpr>�szADictionaryValidator._GetInputToCheckerFunction.<locals>.<genexpr>)�dictr)rrr)rrr�s	z.DictionaryValidator._GetInputToCheckerFunctioncCsOd}g}x/|jD]$}|jd|||jf�qW|dj|�S)Nzflags z%s=%sz, )r�appendr�join)rr�prefixZflags_with_valuesrrrrr�s
"z(DictionaryValidator.PrintFlagsWithValuescCs|jS)N)r)rrrrr�sz!DictionaryValidator.GetFlagsNames)rrrrrrrrrr)rrr�s
rN)r�
__author__�	Exceptionr�objectrrrrrrr�<module>"s
<'