Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
unit = load.units(lang).names["dimensionless"]
else:
derived, slash = [], False
multiplication_operator = False
for index in range(0, 5):
unit = item.group(group_units[index])
operator_index = None if index < 1 else group_operators[index - 1]
operator = None if index < 1 else item.group(operator_index)
# disallow spaces as operators in units expressed in their symbols
# Enforce consistency among multiplication and division operators
# Single exceptions are colloquial number abbreviations (5k miles)
if operator in reg.multiplication_operators(lang) or (
operator is None
and unit
and not (index == 1 and unit in reg.suffixes(lang))
):
if multiplication_operator != operator and not (
index == 1 and str(operator).isspace()
):
if multiplication_operator is False:
multiplication_operator = operator
else:
# Cut if inconsistent multiplication operator
# treat the None operator differently - remove the
# whole word of it
if operator is None:
# For this, use the last consistent operator
# (before the current) with a space
# which should always be the preceding operator
derived.pop()
operator_index = group_operators[index - 2]
values = [value * reg.suffixes(lang)[suffix] for value in values]
unit.original_dimensions = [
unit.original_dimensions[0]
] + unit.original_dimensions[2:]
dimension_change = True
elif unit.original_dimensions[0]["surface"] in reg.suffixes(lang).keys():
# k/M etc is only applied if non-symbolic surfaces of other units
# (because colloquial) or currency units
symbolic = all(
dim["surface"] in load.units(lang).names[dim["base"]].symbols
for dim in unit.original_dimensions[1:]
)
if not symbolic:
suffix = unit.original_dimensions[0]["surface"]
values = [value * reg.suffixes(lang)[suffix] for value in values]
unit.original_dimensions = unit.original_dimensions[1:]
dimension_change = True
# Usually "1990s" stands for the decade, not the amount of seconds
elif re.match(r"[1-2]\d\d0s", surface):
unit.original_dimensions = []
dimension_change = True
surface = surface[:-1]
span = (span[0], span[1] - 1)
_LOGGER.debug('\tCorrect for "1990s" pattern')
# Usually "1am", "5.12 pm" stand for the time, not pico- or attometer
if (
len(unit.dimensions) == 1
and ("pm" == item.group("unit1") or "am" == item.group("unit1"))
and unit.entity.name == "length"
if unit.entity.dimensions:
if (
len(unit.entity.dimensions) > 1
and unit.entity.dimensions[0]["base"] == "currency"
and unit.original_dimensions[1]["surface"] in reg.suffixes(lang).keys()
):
suffix = unit.original_dimensions[1]["surface"]
# Only apply if at least last value is suffixed by k, M, etc
if re.search(r"\d{}\b".format(suffix), text):
values = [value * reg.suffixes(lang)[suffix] for value in values]
unit.original_dimensions = [
unit.original_dimensions[0]
] + unit.original_dimensions[2:]
dimension_change = True
elif unit.original_dimensions[0]["surface"] in reg.suffixes(lang).keys():
# k/M etc is only applied if non-symbolic surfaces of other units
# (because colloquial) or currency units
symbolic = all(
dim["surface"] in load.units(lang).names[dim["base"]].symbols
for dim in unit.original_dimensions[1:]
)
if not symbolic:
suffix = unit.original_dimensions[0]["surface"]
values = [value * reg.suffixes(lang)[suffix] for value in values]
unit.original_dimensions = unit.original_dimensions[1:]
dimension_change = True
# Usually "1990s" stands for the decade, not the amount of seconds
elif re.match(r"[1-2]\d\d0s", surface):
unit.original_dimensions = []
dimension_change = True