Author: hwright
Date: Wed Aug 4 13:15:43 2010
New Revision: 982241
URL: http://svn.apache.org/viewvc?rev=982241&view=rev
Log:
Simplify the Mouse matcher by using a couple of lambda functions and removing
a level of indirection in the checker.
Modified:
labs/mouse/match.py
Modified: labs/mouse/match.py
URL:
http://svn.apache.org/viewvc/labs/mouse/match.py?rev=982241&r1=982240&r2=982241&view=diff
==============================================================================
--- labs/mouse/match.py (original)
+++ labs/mouse/match.py Wed Aug 4 13:15:43 2010
@@ -31,49 +31,33 @@ class UnknownResult(object):
self.type_name = 'standard'
self.include_sample = True
- @staticmethod
- def match(item):
- return True
-
class NoticeResult(object):
def __init__(self):
self.type_name = 'notice'
- @staticmethod
- def match(item):
- return False
-
class ArchiveResult(object):
def __init__(self):
self.type_name = 'archive'
- @staticmethod
- def match(item):
- return False
-
class BinaryResult(object):
def __init__(self):
self.type_name = 'binary'
- @staticmethod
- def match(item):
- return guesser.is_binary(item)
-
_match_order = [
- NoticeResult,
- ArchiveResult,
- BinaryResult,
+ ( lambda x: False, NoticeResult ),
+ ( lambda x: False, ArchiveResult ),
+ ( guesser.is_binary, BinaryResult ),
# we don't need UnknownResult in this list, since it will be returned
# from do_match() by default.
- # UnknownResult,
+ # ( lambda x: True, UnknownResult ),
]
@@ -81,8 +65,8 @@ def do_match(item):
'''Check each of the classes in _match_order, using it's match() method, and
if the content of item matches that class, instantiate and return the
result.'''
- for m in _match_order:
- if m.match(item):
- return m()
+ for (matcher, result) in _match_order:
+ if matcher(item):
+ return result()
return UnknownResult()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]