vregistry.py
branchtls-sprint
changeset 697 06807984e610
parent 695 356da23c57f1
child 698 7dfd03e9e810
--- a/vregistry.py	Tue Feb 17 21:42:33 2009 +0100
+++ b/vregistry.py	Tue Feb 17 21:46:46 2009 +0100
@@ -638,6 +638,19 @@
         return NotImplementedError("selector %s must implement its logic "
                                    "in its __call__ method" % self.__class__)
 
+    
+def objectify_selector(selector_func):
+    """convenience decorator for simple selectors where a class definition
+    would be overkill::
+
+        @objectify_selector
+        def yes(cls, *args, **kwargs):
+            return 1
+        
+    """
+    return type(selector_func.__name__, (Selector,),
+                {'__call__': lambda self, *args: selector_func(*args)})
+
 
 class AndSelector(Selector):
     """and-chained selectors (formerly known as chainall)"""