From 9fb2b4ff58681dde805f9ac2c8be3b59ad8e9a50 Mon Sep 17 00:00:00 2001 From: ryuslash Date: Thu, 8 Apr 2010 15:12:26 +0200 Subject: Fixed Python 2.6 compatibility issue Select was using "raise 'No Match'" to break from non-matches, this is deprecated --- modules/kirbybase.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/kirbybase.py b/modules/kirbybase.py index be4fd6d..c18f111 100644 --- a/modules/kirbybase.py +++ b/modules/kirbybase.py @@ -1718,12 +1718,14 @@ class KirbyBase: while line: # Strip off newline character and any trailing spaces. line = line[:-1].strip() - try: - # If blank line, skip this record. - if line == "": raise 'No Match' - # Split the line up into fields. - record = line.split("|", maxfield) - + # Keep track of matching + is_no_match = False + # If blank line, skip this record. + if line == "": is_no_match = True + # Split the line up into fields. + record = line.split("|", maxfield) + + if not is_no_match: # Foreach correspond field and pattern, check to see # if the table record's field matches successfully. for fieldPos, pattern in fieldPos_new_patterns: @@ -1739,23 +1741,26 @@ class KirbyBase: try: if useRegExp: if not pattern.search( - self._unencodeString(record[fieldPos]) - ): - raise 'No Match' + self._unencodeString(record[fieldPos]) + ): + is_no_match = True + break else: if record[fieldPos] != pattern: - raise 'No Match' + is_no_match = True + break except Exception: raise KBError( - 'Invalid match expression for %s' - % self.field_names[fieldPos]) + 'Invalid match expression for %s' + % self.field_names[fieldPos]) # If the field type is boolean, then I will simply # do an equality comparison. See comments above # about why I am actually doing a string compare # here rather than a boolean compare. elif self.field_types[fieldPos] == bool: if record[fieldPos] != pattern: - raise 'No Match' + is_no_match = True + break # If it is not a string or a boolean, then it must # be a number or a date. else: @@ -1776,14 +1781,14 @@ class KirbyBase: # strings works out the same as comparing two # datetime values anyway. elif self.field_types[fieldPos] in ( - datetime.date, datetime.datetime): + datetime.date, datetime.datetime): tableValue = record[fieldPos] else: # If it falls through to here, then, # somehow, a bad field type got put into # the table and we show an error. raise KBError('Invalid field type for %s' - % self.field_names[fieldPos]) + % self.field_names[fieldPos]) # Now we do the actual comparison. I used to # just do an eval against the pattern string # 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. # This sped up queries by 40%. 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 # next record, otherwise, add it to the list of matches. - except 'No Match': - pass - else: + if not is_no_match: match_list.append([line, fpos]) # Save the file position BEFORE we read the next record, # because after a read it is pointing at the END of the -- cgit v1.2.3-54-g00ecf