Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def regexp(str_regex):
try:
return re.compile(str_regex)
except re.error as err:
raise configargparse.ArgumentTypeError('Invalid regexp: %r (%s)' % (str_regex, err.msg))
def _init_weights(s):
""" Handle the None value in VALID_INIT_WEIGHTS """
if s not in RimeSolverConfig.VALID_INIT_WEIGHTS:
import configargparse
raise configargparse.ArgumentTypeError("\'{iw}\'' must be one of {viw}"
.format(iw=INIT_WEIGHTS, viw=RimeSolverConfig.VALID_INIT_WEIGHTS))
return s
def positive_int_type(x):
x = int(x)
if x < 0:
raise configargparse.ArgumentTypeError("A negative number was supplied")
return x
def __call__(self, parser, namespace, values, flag_name):
help = self.help if self.help is not None else ""
msg = "Flag '%s' is deprecated. %s" % (flag_name, help)
raise configargparse.ArgumentTypeError(msg)
def commitpoint_type(x):
x = int(x)
if x < const.MIN_COMMIT_POINT:
raise configargparse.ArgumentTypeError(
"Minimum allowed commitpoint is: {}"
.format(const.MIN_COMMIT_POINT))
return x
def _str2bool(v):
"""Convert an argument string to a boolean value."""
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
raise _argparse.ArgumentTypeError("Boolean value expected.")
def __call__(self, parser, namespace, values, flag_name):
help = self.help if self.help is not None else ""
msg = "Flag '%s' is deprecated. %s" % (flag_name, help)
raise configargparse.ArgumentTypeError(msg)
def time_interval(str_interval):
try:
quant, unit = re.match(r'\A([\d.]+) ?(h|m(?:in)?|s)?\Z', str_interval).groups()
translate = {'h': 'hours', 'm': 'minutes', 'min': 'minutes', 's': 'seconds'}
return timedelta(**{translate[unit or 's']: float(quant)})
except (AttributeError, ValueError):
raise configargparse.ArgumentTypeError('Invalid time interval (e.g. 12[s|min|h]): %s' % str_interval)