Fixed compatibility of ck2cti with Python 2.6

re.sub doesn't accept the flags keyword argument until 2.7, but the same
effect can be achieved using re.compile.
This commit is contained in:
Ray Speth 2013-03-13 20:20:31 +00:00
parent 9a1d6532ba
commit b82df1b1ea

View file

@ -981,20 +981,20 @@ class Parser(object):
quantity_units = self.quantity_units quantity_units = self.quantity_units
if 'units' in entry.lower(): if 'units' in entry.lower():
for units in sorted(QUANTITY_UNITS, key=lambda k: -len(k)): for units in sorted(QUANTITY_UNITS, key=lambda k: -len(k)):
m = re.search(r'units *\/ *%s *\/' % re.escape(units), pattern = re.compile(r'units *\/ *%s *\/' % re.escape(units),
entry, re.IGNORECASE) flags=re.IGNORECASE)
m = pattern.search(entry)
if m: if m:
entry = re.sub(r'units *\/ *%s *\/' % re.escape(units), '', entry = pattern.sub('', entry)
entry, flags=re.IGNORECASE)
quantity_units = QUANTITY_UNITS[units] quantity_units = QUANTITY_UNITS[units]
break break
for units in sorted(ENERGY_UNITS, key=lambda k: -len(k)): for units in sorted(ENERGY_UNITS, key=lambda k: -len(k)):
m = re.search(r'units *\/ *%s *\/' % re.escape(units), pattern = re.compile(r'units *\/ *%s *\/' % re.escape(units),
entry, re.IGNORECASE) re.IGNORECASE)
m = pattern.search(entry)
if m: if m:
entry = re.sub(r'units *\/ *%s *\/' % re.escape(units), '', entry = pattern.sub('', entry)
entry, flags=re.IGNORECASE)
energy_units = ENERGY_UNITS[units] energy_units = ENERGY_UNITS[units]
break break