Author: jmorliaguet
Date: Mon May  1 19:19:55 2006
New Revision: 3009

Modified:
   cpsskins/branches/paris-sprint-2006/relations/interfaces.py
   cpsskins/branches/paris-sprint-2006/relations/relations.py
Log:

- made it possible to update relations before they are added to the storage.



Modified: cpsskins/branches/paris-sprint-2006/relations/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/relations/interfaces.py (original)
+++ cpsskins/branches/paris-sprint-2006/relations/interfaces.py Mon May  1 
19:19:55 2006
@@ -48,8 +48,19 @@
         """Return the relation's arity"""
 
     def __call__():
-        """Return the relation's predicate"""
+        """Return the relation's predicate."""
 
+    def getPredicate():
+        """Get the predicate of the relation."""
+
+    def setPredicate(predicate):
+        """Set the predicate od the relation."""
+
+    def getRelates():
+        """Get the relates."""
+
+    def setRelates(relates):
+        """Set the relates."""
 
 class IMonadicRelation(IRelation):
     """A monadic relation connects a relate with itself."""

Modified: cpsskins/branches/paris-sprint-2006/relations/relations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/relations/relations.py  (original)
+++ cpsskins/branches/paris-sprint-2006/relations/relations.py  Mon May  1 
19:19:55 2006
@@ -19,11 +19,11 @@
 
 from persistent import Persistent
 
-from zope.component import adapts
-from zope.component.factory import Factory
+from zope.app.container.interfaces import IContained
 from zope.interface import implements
 from zope.security.proxy import removeSecurityProxy as trusted
 
+from cpsskins.relations.predicates import Predicate
 from cpsskins.relations.interfaces import IRelation
 from cpsskins.relations.interfaces import IMonadicRelation, IDyadicRelation
 from cpsskins.relations.interfaces import ITriadicRelation, IRelatable
@@ -55,6 +55,34 @@
     def __len__(self):
         return len(self._tuple)
 
+    def getPredicate(self):
+        return self._predicate
+
+    def setPredicate(self, predicate):
+        if IContained.providedBy(self):
+            raise IOError("Cannot set the predicate of a stored relation.")
+        if not isinstance(predicate, basestring):
+            raise TypeError("The predicate must be a string.")
+        self._predicate = Predicate(unicode(predicate))
+
+    def getRelates(self):
+        return self._relates
+
+    def setRelates(self, relates):
+        if IContained.providedBy(self):
+            raise IOError("Cannot set the relates of a stored relation.")
+        if not isinstance(relates, (list, tuple)):
+            raise TypeError("Relates must be passed as a list or as a tuple.")
+        if 1 <= len(relates) <= 3:
+            self._relates = tuple([trusted(r) for r in relates])
+        else:
+            raise ValueError("Incorrect number of relates (%s)" % len(relates))
+
+    predicate = property(getPredicate, setPredicate)
+
+    relates = property(getRelates, setRelates)
+
+
 class MonadicRelation(Relation):
     """A monadic relation
 
@@ -218,12 +246,3 @@
     def __repr__(self):
         return self.name
 
-MonadicRelationFactory = Factory(MonadicRelation, "Monadic Relation Factory",
-    "A Factory that creates monadic relations")
-
-DyadicRelationFactory = Factory(DyadicRelation, "Dyadic Relation Factory",
-    "A Factory that creates dyadic relations")
-
-TriadicRelationFactory = Factory(TriadicRelation, "Triadic Relation Factory",
-    "A Factory that creates triadic relations")
-
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to