Return a boolean value translating from other types if necessary.
168439
def _convert_to_boolean(self, value):
        
        if value.lower() not in self.BOOLEAN_STATES:
            raise ValueError('Not a boolean: %s' % value)
        return self.BOOLEAN_STATES[value.lower()]
544246
def _ConvertBool(value, require_str):
  
  if require_str:
    if value == 'true':
      return True
    elif value == 'false':
      return False
    else:
      raise ParseError('Expected "true" or "false", not {0}.'.format(value))

  if not isinstance(value, bool):
    raise ParseError('Expected true or false without quotes.')
  return value
135449
def as_bool(s):
    
    if s in (False, True): return s
    # Assume string
    s = s.lower()
    if s in ("yes", "true"):
        return True
    elif s in ("no", "false"):
        return False
    else:
        raise ValueError("Don't know how to convert type %s: %s into a boolean" % (type(s), s))
1161979
def parse_value(self, value):
        """"""
        parsed = super(BoolField, self).parse_value(value)
        return bool(parsed) if parsed is not None else None
655743
def to_boolean(value, ctx):
    
    if isinstance(value, bool):
        return value
    elif isinstance(value, int):
        return value != 0
    elif isinstance(value, Decimal):
        return value != Decimal(0)
    elif isinstance(value, str):
        value = value.lower()
        if value == 'true':
            return True
        elif value == 'false':
            return False
    elif isinstance(value, datetime.date) or isinstance(value, datetime.time):
        return True

    raise EvaluationError("Can't convert '%s' to a boolean" % str(value))
371124
def validate_boolean_or_string(option, value):
    """"""
    if isinstance(value, string_type):
        if value not in ('true', 'false'):
            raise ValueError("The value of %s must be "
                             "'true' or 'false'" % (option,))
        return value == 'true'
    return validate_boolean(option, value)
43089
def optional(self):
        """"""
        value = self._schema.get("optional", False)
        if value is not False and value is not True:
            raise SchemaError(
                "optional value {0!r} is not a boolean".format(value))
        return value
1343963
def from_representation(self, data):
        """"""
        if data in self._TRUE_VALUES:
            return True
        elif data in self._FALSE_VALUES:
            return False
        else:
            raise ValueError(
                "{type} type value must be one of {values}".format(
                    type=self.type,
                    values=self._TRUE_VALUES.union(self._FALSE_VALUES)
                )
            )
1320236
def _cast_boolean(value):
    
    _BOOLEANS = {'1': True, 'yes': True, 'true': True, 'on': True,
                 '0': False, 'no': False, 'false': False, 'off': False, '': False}
    value = str(value)
    if value.lower() not in _BOOLEANS:
        raise ValueError('Not a boolean: %s' % value)

    return _BOOLEANS[value.lower()]
717971
public BooleanType castToBoolean(Base b) throws FHIRException {
		if (b instanceof BooleanType)
			return (BooleanType) b;
		else
			throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Boolean");
	}
1084263
def normalizeBoolean(value):
    
    if isinstance(value, int) and value in (0, 1):
        value = bool(value)
    if not isinstance(value, bool):
        raise ValueError("Boolean values must be True or False, not '%s'."
                         % value)
    return value
408967
def p_ConstValue_boolean(p):
  """"""
  p[0] = model.Value(type=model.Value.BOOLEAN, value=p[1])
64465
def to_bool_alt(value):
    '''
    
    '''
    value = from_bool_alt(value)
    if isinstance(value, bool):
        value = 'yes' if value else 'no'
    elif value is None:
        value = 'none'

    return value
1198952
def to_bool(val):
    '''
    
    '''
    if val is None:
        return False
    if isinstance(val, bool):
        return val
    if isinstance(val, (six.text_type, six.string_types)):
        return val.lower() in ('yes', '1', 'true')
    if isinstance(val, six.integer_types):
        return val > 0
    if not isinstance(val, collections.Hashable):
        return bool(val)
    return False
1323121
def convert_boolean(value, parameter, default=False):
    '''
    
    '''
    value = _check_default(value, parameter, ( '', '-', None ))
    if isinstance(value, bool):
        return value
    if isinstance(value, str) and len(value) > 0:
        value = value[0]
    return value not in ( 'f', 'F', '0', False, None )
463204
def __convert_booleans(self, eitem):
        

        for field in eitem.keys():
            if isinstance(eitem[field], bool):
                if eitem[field]:
                    eitem[field] = 1
                else:
                    eitem[field] = 0
        return eitem
251196
protected Boolean checkBoolean(Object val, Boolean def) {
        return (val == null) ? def : (Boolean) val;
    }