Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._units = "M"
else:
if units.upper() not in distance.legal_units:
raise UnitsError("unrecognized distance unit: '" + units + "'")
self._units = units.upper()
try:
if value.startswith("M"):
value = value[1:]
gtlt = "<"
elif value.startswith("P"):
value = value[1:]
gtlt = ">"
except:
pass
if gtlt and gtlt not in distance.legal_gtlt:
raise ValueError(
"unrecognized greater-than/less-than symbol: '" + gtlt + "'"
)
self._gtlt = gtlt
try:
self._value = float(value)
self._num = None
self._den = None
except ValueError:
mf = FRACTION_RE.match(value)
if not mf:
raise ValueError("distance is not parseable: '" + str(value) + "'")
df = mf.groupdict()
self._num = int(df["num"])
self._den = int(df["den"])
self._value = float(self._num) / float(self._den)