[Python-checkins] python/dist/src/Lib difflib.py,1.6.10.1,1.6.10.2
nnorwitz@users.sourceforge.net
nnorwitz@users.sourceforge.net
Tue, 01 Jul 2003 08:12:35 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv31467/Lib
Modified Files:
Tag: release22-maint
difflib.py
Log Message:
Fix SF bug #763023, difflib.py: ratio() zero division not caught
Index: difflib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/difflib.py,v
retrieving revision 1.6.10.1
retrieving revision 1.6.10.2
diff -C2 -d -r1.6.10.1 -r1.6.10.2
*** difflib.py 30 Oct 2002 06:33:33 -0000 1.6.10.1
--- difflib.py 1 Jul 2003 15:12:33 -0000 1.6.10.2
***************
*** 25,28 ****
--- 25,33 ----
'Differ', 'IS_CHARACTER_JUNK', 'IS_LINE_JUNK']
+ def _calculate_ratio(matches, length):
+ if length:
+ return 2.0 * matches / length
+ return 1.0
+
class SequenceMatcher:
***************
*** 526,530 ****
matches = reduce(lambda sum, triple: sum + triple[-1],
self.get_matching_blocks(), 0)
! return 2.0 * matches / (len(self.a) + len(self.b))
def quick_ratio(self):
--- 531,535 ----
matches = reduce(lambda sum, triple: sum + triple[-1],
self.get_matching_blocks(), 0)
! return _calculate_ratio(matches, len(self.a) + len(self.b))
def quick_ratio(self):
***************
*** 555,559 ****
if numb > 0:
matches = matches + 1
! return 2.0 * matches / (len(self.a) + len(self.b))
def real_quick_ratio(self):
--- 560,564 ----
if numb > 0:
matches = matches + 1
! return _calculate_ratio(matches, len(self.a) + len(self.b))
def real_quick_ratio(self):
***************
*** 567,571 ****
# can't have more matches than the number of elements in the
# shorter sequence
! return 2.0 * min(la, lb) / (la + lb)
def get_close_matches(word, possibilities, n=3, cutoff=0.6):
--- 572,576 ----
# can't have more matches than the number of elements in the
# shorter sequence
! return _calculate_ratio(min(la, lb), la + lb)
def get_close_matches(word, possibilities, n=3, cutoff=0.6):