1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
22  """a set of helper functions for filters...""" 
23   
24  import operator 
25   
27      """checks whether a string is all alphanumeric, allowing any unicode characters >= 0x80 to pass the test""" 
28      return s.isalnum() or reduce(operator.and_, [c.isalnum() or c >= "\x80" for c in s], True) 
 29   
31      """checks whether countstr occurs the same number of times in str1 and str2""" 
32      return str1.count(countstr) == str2.count(countstr) 
 33   
35      """returns whether the result of func is the same for str1 and str2""" 
36      return func(str1, *args) == func(str2, *args) 
 37   
39      """checks whether each element in countlist occurs the same number of times in str1 and str2""" 
40      return reduce(operator.and_, [countmatch(str1, str2, countstr) for countstr in countlist], True) 
 41   
43      """checks whether the results of each func in funclist match for str1 and str2""" 
44      return reduce(operator.and_, [funcmatch(str1, str2, funcstr) for funcstr in funclist], True) 
 45   
47      """returns the number of characters in str1 that pass func""" 
48      return len(filter(func, str1)) 
 49   
51      """returns a version of the testmethod that operates on filtered strings using strfilter""" 
52      def filteredmethod(str1, str2): 
53          return testmethod(strfilter(str1), strfilter(str2)) 
 54      filteredmethod.__doc__ = testmethod.__doc__ 
55      filteredmethod.name = getattr(testmethod, 'name', testmethod.__name__) 
56      return filteredmethod 
57   
59      """passes str1 through a list of filters""" 
60      for strfilter in strfilters: 
61          str1 = strfilter(str1) 
62      return str1 
 63   
65      """returns a version of the testmethod that operates on filtered strings using strfilter""" 
66      def filteredmethod(str1, str2): 
67          return testmethod(multifilter(str1, strfilters), multifilter(str2, strfilters)) 
 68      filteredmethod.__doc__ = testmethod.__doc__ 
69      filteredmethod.name = getattr(testmethod, 'name', testmethod.__name__) 
70      return filteredmethod 
71