A helper-wrapper for the safe_value_2() family.
433416
def safe_either(method, dictionary, key1, key2, default_value=None):
        """"""
        value = method(dictionary, key1)
        return value if value is not None else method(dictionary, key2, default_value)
173109
def nextpow2(value):
    """"""
    if value >= 1:
        return 2**np.ceil(np.log2(value)).astype(int)
    elif value > 0:
        return 1
    elif value == 0:
        return 0
    else:
        raise ValueError('Value must be positive')
51237
def safe(self,x):
        """"""
        x[np.isinf(x)] = 1
        x[np.isnan(x)] = 1
        return x
1261970
def safeEncodeAttribute(self, encValue):
		""""""
		encValue = encValue.replace(u'&', u'&amp;')
		encValue = encValue.replace(u'<', u'&lt;')
		encValue = encValue.replace(u'>', u'&gt;')
		encValue = encValue.replace(u'"', u'&quot;')
		encValue = encValue.replace(u'{', u'&#123;')
		encValue = encValue.replace(u'[', u'&#91;')
		encValue = encValue.replace(u"''", u'&#39;&#39;')
		encValue = encValue.replace(u'ISBN', u'&#73;SBN')
		encValue = encValue.replace(u'RFC', u'&#82;FC')
		encValue = encValue.replace(u'PMID', u'&#80;MID')
		encValue = encValue.replace(u'|', u'&#124;')
		encValue = encValue.replace(u'__', u'&#95;_')
		encValue = encValue.replace(u'\n', u'&#10;')
		encValue = encValue.replace(u'\r', u'&#13;')
		encValue = encValue.replace(u'\t', u'&#9;')
		return encValue
728007
def __within2(value, within=None, errmsg=None, dtype=None):
    ''''''
    valid, _value = False, value
    if dtype:
        try:
            _value = dtype(value)  # TODO: this is a bit loose when dtype is a class
            valid = _value in within
        except ValueError:
            pass
    else:
        valid = _value in within
    if errmsg is None:
        if dtype:
            typename = getattr(dtype, '__name__',
                               hasattr(dtype, '__class__')
                               and getattr(dtype.__class__, 'name', dtype))
            errmsg = '{0} within \'{1}\''.format(typename, within)
        else:
            errmsg = 'within \'{0}\''.format(within)
    return (valid, _value, errmsg)
294106
def valuePasses(self, value):
    ''''''
    return self._conditional_cmp[self.op](value, self.value)
1218364
def safe_int(val, allow_zero=True):
    
    try:
        ret = int(val)
    except ValueError:
        print("Sorry, '%s' is not a valid integer." % val)
        return False
    if not allow_zero and ret == 0:
        print("Please enter a non-zero integer.")
        return False
    return ret
367605
def _sanitize_value(key, value)
      case value
      when String
        value.dup.freeze
      when Symbol, Integer, Float, NilClass, TrueClass, FalseClass
        value
      when Array
        _sanitize_array(key, value)
      when Hash
        _sanitize_params(value)
      else
        raise Errors::UnsafeValueError.new(key, value)
      end
    end
1296745
def _float_generator(descriptor, bitwidth):
    ''
    return gen.IterValueGenerator(descriptor.name, values.get_floats(bitwidth))
259944
def P2(self, value):
        """"""
        if value > self.P1:
            self._P2 = value
        else:
            raise InvalidSecondDisparityChangePenaltyError("P2 must be greater "
                                                          "than P1.")
        self._replace_bm()
254003
def clean(self, value):
        """"""
        if not isinstance(value, self.t):
            value = self.t(value)

        if not self.allow_negative and value < 0:
            raise ValueError('value was negative')

        if not self.allow_positive and value > 0:
            raise ValueError('values was positive')

        return value
360864
def get_safe_variables(self,query,var_dict):
        '''  '''

        variables_bounded_to_constants = []

        for constraint in query.constraints:
            if (constraint.get_left_side().is_variable() and
                constraint.get_right_side().is_constant() and
                constraint.is_equality_constraint()):
                    variables_bounded_to_constants.append(constraint.get_left_side())

        safe_variables = list(var_dict) + variables_bounded_to_constants

        return safe_variables
1228498
function sanitizeValue(_ref) {
  var value = _ref.value,
      operator_keyword = _ref.operator_keyword,
      post_keyword = _ref.post_keyword;
  return parseInt(value, 10) * getMultiplier({
    operator_keyword: operator_keyword,
    post_keyword: post_keyword
  });
}
1176518
def _safe_db(num, den):
    
    if den == 0:
        return np.inf
    return 10 * np.log10(num / den)
98445
def safestr(value):
    ''''''
    if not value or isinstance(value, (int, float, bool, long)):
        return value
    elif isinstance(value, (date, datetime)):
        return value.isoformat()
    else:
        return unicode(value)
743672
def str(self, value, tolerant=False, limit=1000, seen=frozenset()):
        """"""
        if value is None:
            if tolerant:
                return ""

            raise ValueError("value is None")

        if isinstance(value, (bool, numbers.Number, basestring)):
            return str(value)

        if not isinstance(value, collections.Iterable):
            if not tolerant:
                raise ValueError("unknown value type")

            try:
                name = value.name
            except AttributeError:
                try:
                    name = value.__name__
                except AttributeError:
                    try:
                        name = value.__class__.__name__
                    except AttributeError:
                        return "<?>"

            return "<%s>" % (name,)

        is_mapping = isinstance(value, collections.Mapping)

        if not seen:
            wrap = "%s"
        elif is_mapping:
            wrap = "{%s}"
        else:
            wrap = "[%s]"

        id_ = id(value)
        if id_ in seen:
            if tolerant:
                return wrap % ("...",)
            raise ValueError("recursive representation")
        seen = seen.union((id_,))

        if is_mapping:
            items = [(self.str(n, tolerant=tolerant, limit=limit, seen=seen),
                      self.str(v, tolerant=tolerant, limit=limit, seen=seen))
                     for n, v in value.items()]
            items.sort()
            items = ("%s=%s" for n, v in items)
        else:
            it = iter(value)
            items = [self.str(item, tolerant=tolerant, limit=limit, seen=seen)
                     for item in itertools.islice(
                         it,
                         len(value)
                         if isinstance(value, collections.Sized)
                         else limit)]
            items.sort()
            try:
                next(it)
            except StopIteration:
                pass
            else:
                if not tolerant:
                    raise ValueError("iterable too long")
                items.append("...")

        return wrap % (", ".join(items),)
1244641
def safe_int(string, default=None):
    
    value = safe_float(string, default)
    if value is not None:
        value = int(value)
    return value