Fixed Python 2.6 compatibility issue
Select was using "raise 'No Match'" to break from non-matches, this is deprecated
This commit is contained in:
parent
a567e8630f
commit
9fb2b4ff58
1 changed files with 22 additions and 18 deletions
|
@ -1718,12 +1718,14 @@ class KirbyBase:
|
||||||
while line:
|
while line:
|
||||||
# Strip off newline character and any trailing spaces.
|
# Strip off newline character and any trailing spaces.
|
||||||
line = line[:-1].strip()
|
line = line[:-1].strip()
|
||||||
try:
|
# Keep track of matching
|
||||||
# If blank line, skip this record.
|
is_no_match = False
|
||||||
if line == "": raise 'No Match'
|
# If blank line, skip this record.
|
||||||
# Split the line up into fields.
|
if line == "": is_no_match = True
|
||||||
record = line.split("|", maxfield)
|
# Split the line up into fields.
|
||||||
|
record = line.split("|", maxfield)
|
||||||
|
|
||||||
|
if not is_no_match:
|
||||||
# Foreach correspond field and pattern, check to see
|
# Foreach correspond field and pattern, check to see
|
||||||
# if the table record's field matches successfully.
|
# if the table record's field matches successfully.
|
||||||
for fieldPos, pattern in fieldPos_new_patterns:
|
for fieldPos, pattern in fieldPos_new_patterns:
|
||||||
|
@ -1739,23 +1741,26 @@ class KirbyBase:
|
||||||
try:
|
try:
|
||||||
if useRegExp:
|
if useRegExp:
|
||||||
if not pattern.search(
|
if not pattern.search(
|
||||||
self._unencodeString(record[fieldPos])
|
self._unencodeString(record[fieldPos])
|
||||||
):
|
):
|
||||||
raise 'No Match'
|
is_no_match = True
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
if record[fieldPos] != pattern:
|
if record[fieldPos] != pattern:
|
||||||
raise 'No Match'
|
is_no_match = True
|
||||||
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
raise KBError(
|
raise KBError(
|
||||||
'Invalid match expression for %s'
|
'Invalid match expression for %s'
|
||||||
% self.field_names[fieldPos])
|
% self.field_names[fieldPos])
|
||||||
# If the field type is boolean, then I will simply
|
# If the field type is boolean, then I will simply
|
||||||
# do an equality comparison. See comments above
|
# do an equality comparison. See comments above
|
||||||
# about why I am actually doing a string compare
|
# about why I am actually doing a string compare
|
||||||
# here rather than a boolean compare.
|
# here rather than a boolean compare.
|
||||||
elif self.field_types[fieldPos] == bool:
|
elif self.field_types[fieldPos] == bool:
|
||||||
if record[fieldPos] != pattern:
|
if record[fieldPos] != pattern:
|
||||||
raise 'No Match'
|
is_no_match = True
|
||||||
|
break
|
||||||
# If it is not a string or a boolean, then it must
|
# If it is not a string or a boolean, then it must
|
||||||
# be a number or a date.
|
# be a number or a date.
|
||||||
else:
|
else:
|
||||||
|
@ -1776,14 +1781,14 @@ class KirbyBase:
|
||||||
# strings works out the same as comparing two
|
# strings works out the same as comparing two
|
||||||
# datetime values anyway.
|
# datetime values anyway.
|
||||||
elif self.field_types[fieldPos] in (
|
elif self.field_types[fieldPos] in (
|
||||||
datetime.date, datetime.datetime):
|
datetime.date, datetime.datetime):
|
||||||
tableValue = record[fieldPos]
|
tableValue = record[fieldPos]
|
||||||
else:
|
else:
|
||||||
# If it falls through to here, then,
|
# If it falls through to here, then,
|
||||||
# somehow, a bad field type got put into
|
# somehow, a bad field type got put into
|
||||||
# the table and we show an error.
|
# the table and we show an error.
|
||||||
raise KBError('Invalid field type for %s'
|
raise KBError('Invalid field type for %s'
|
||||||
% self.field_names[fieldPos])
|
% self.field_names[fieldPos])
|
||||||
# Now we do the actual comparison. I used to
|
# Now we do the actual comparison. I used to
|
||||||
# just do an eval against the pattern string
|
# just do an eval against the pattern string
|
||||||
# here, but I found that eval's are VERY slow.
|
# here, but I found that eval's are VERY slow.
|
||||||
|
@ -1791,12 +1796,11 @@ class KirbyBase:
|
||||||
# they are trying to do and I do it directly.
|
# they are trying to do and I do it directly.
|
||||||
# This sped up queries by 40%.
|
# This sped up queries by 40%.
|
||||||
if not pattern[0](tableValue, pattern[1]):
|
if not pattern[0](tableValue, pattern[1]):
|
||||||
raise 'No Match'
|
is_no_match = True
|
||||||
|
break
|
||||||
# If a 'No Match' exception was raised, then go to the
|
# If a 'No Match' exception was raised, then go to the
|
||||||
# next record, otherwise, add it to the list of matches.
|
# next record, otherwise, add it to the list of matches.
|
||||||
except 'No Match':
|
if not is_no_match:
|
||||||
pass
|
|
||||||
else:
|
|
||||||
match_list.append([line, fpos])
|
match_list.append([line, fpos])
|
||||||
# Save the file position BEFORE we read the next record,
|
# Save the file position BEFORE we read the next record,
|
||||||
# because after a read it is pointing at the END of the
|
# because after a read it is pointing at the END of the
|
||||||
|
|
Loading…
Reference in a new issue