Source

intensional / intensional.py

Diff from to

File intensional.py

     __metaclass__ = MementoMetaclass
     
     
-# need to complete more of the set functions like union, difference, etc
+# Any = Union, Every = Intersection
+# might want to complete more of the set functions like symmetric difference, discard, etc
+
 
 
 class ReMatch(orderedstuf):
                     return False
         return True
 
-   
+class ButNot(IntensionalSet):
+    """
+    An item is in a ButNot if it's in the primary set and not the exclusion.
+    """
+    
+    def __init__(self, items, exclusion):
+        self.items = items
+        self.exclusion = exclusion
+
+    def __contains__(self, item):
+        if item == self.items or item in self.items:
+            if item != self.exclusion and item not in self.exclusion:
+                return True
+        return False
+
 class Test(IntensionalSet):
     
     def __init__(self, expr, *args, **kwargs):
             raise ValueError('expr needs to be string or callable')
         
     def __contains__(self, item):
-        return self.func(item, *self.args, **self.kwargs)
+        try:
+            return self.func(item, *self.args, **self.kwargs)
+        except StandardError:
+            return False
+        
+        # NB failure to run test => fails test
+        # might silently hide syntax errors and such
+        # do we want a mode or mechanism to make such errors into Warnings?