def _check_boolean(parameter_name, value, parameter_config):
    """Checks if a boolean value is valid.

  This is called by the transform_parameter_value function and shouldn't be
  called directly.

  This checks that the string value passed in can be converted to a valid
  boolean value.

  Args:
    parameter_name: A string containing the name of the parameter, which is
      either just a variable name or the name with the index appended. For
      example 'var' or 'var[2]'.
    value: A string containing the value passed in for the parameter.
    parameter_config: The dictionary containing information specific to the
      parameter in question. This is retrieved from request.parameters in
      the method config.

  Raises:
    BasicTypeParameterError: If the given value is not a valid boolean
      value.
  """
    if parameter_config.get('type') != 'boolean':
        return

    if value.lower() not in ('1', 'true', '0', 'false'):
        raise errors.BasicTypeParameterError(parameter_name, value, 'boolean')
def transform_parameter_value(parameter_name, value, parameter_config):
    """Validates and transforms parameters to the type expected by the SPI.

  If the value is a list this will recursively call _transform_parameter_value
  on the values in the list. Otherwise, it checks all parameter rules for the
  the current value and converts its type from a string to whatever format
  the SPI expects.

  In the list case, '[index-of-value]' is appended to the parameter name for
  error reporting purposes.

  Args:
    parameter_name: A string containing the name of the parameter, which is
      either just a variable name or the name with the index appended, in the
      recursive case. For example 'var' or 'var[2]'.
    value: A string or list of strings containing the value(s) passed in for
      the parameter.  These are the values from the request, to be validated,
      transformed, and passed along to the SPI.
    parameter_config: The dictionary containing information specific to the
      parameter in question. This is retrieved from request.parameters in the
      method config.

  Returns:
    The converted parameter value(s).  Not all types are converted, so this
    may be the same string that's passed in.
  """
    if isinstance(value, list):
        # We're only expecting to handle path and query string parameters here.
        # The way path and query string parameters are passed in, they'll likely
        # only be single values or singly-nested lists (no lists nested within
        # lists).  But even if there are nested lists, we'd want to preserve that
        # structure.  These recursive calls should preserve it and convert all
        # parameter values.  See the docstring for information about the parameter
        # renaming done here.
        return [
            transform_parameter_value('%s[%d]' % (parameter_name, index),
                                      element, parameter_config)
            for index, element in enumerate(value)
        ]

    # Validate and convert the parameter value.
    entry = _get_parameter_conversion_entry(parameter_config)
    if entry:
        validation_func, conversion_func, type_name = entry
        if validation_func:
            validation_func(parameter_name, value, parameter_config)
        if conversion_func:
            try:
                return conversion_func(value)
            except ValueError:
                raise errors.BasicTypeParameterError(parameter_name, value,
                                                     type_name)

    return value