Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_values(item, lang="en_US"):
"""
Extract value from regex hit.
"""
def callback(pattern):
return " %s" % (reg.unicode_fractions()[pattern.group(0)])
fracs = r"|".join(reg.unicode_fractions())
value = item.group("value")
# Remove grouping operators
value = re.sub(
r"(?<=\d)[%s](?=\d{3})" % reg.grouping_operators_regex(lang), "", value
)
# Replace unusual exponents by e (including e)
value = re.sub(
r"(?<=\d)(%s)(e|E|10)\^?" % reg.multiplication_operators_regex(lang), "e", value
)
# calculate other exponents
value, factors = resolve_exponents(value)
_LOGGER.debug("After exponent resolution: {}".format(value))
value = re.sub(fracs, callback, value, re.IGNORECASE)
def callback(pattern):
return " %s" % (reg.unicode_fractions()[pattern.group(0)])