Property link object. @ivar endpoints: A tuple of the (2) endpoints of the link. @type endpoints: tuple(2)
| 41 | |
| 42 | |
| 43 | class Link(object): |
| 44 | """ |
| 45 | Property link object. |
| 46 | @ivar endpoints: A tuple of the (2) endpoints of the link. |
| 47 | @type endpoints: tuple(2) |
| 48 | """ |
| 49 | def __init__(self, a, b): |
| 50 | """ |
| 51 | @param a: Property (A) to link. |
| 52 | @type a: L{Property} |
| 53 | @param b: Property (B) to link. |
| 54 | @type b: L{Property} |
| 55 | """ |
| 56 | pA = Endpoint(self, a) |
| 57 | pB = Endpoint(self, b) |
| 58 | self.endpoints = (pA, pB) |
| 59 | self.validate(a, b) |
| 60 | a.links.append(pB) |
| 61 | b.links.append(pA) |
| 62 | |
| 63 | def validate(self, pA, pB): |
| 64 | """ |
| 65 | Validate that the two properties may be linked. |
| 66 | @param pA: Endpoint (A) to link. |
| 67 | @type pA: L{Endpoint} |
| 68 | @param pB: Endpoint (B) to link. |
| 69 | @type pB: L{Endpoint} |
| 70 | @return: self |
| 71 | @rtype: L{Link} |
| 72 | """ |
| 73 | if pA in pB.links or \ |
| 74 | pB in pA.links: |
| 75 | raise Exception('Already linked') |
| 76 | dA = pA.domains() |
| 77 | dB = pB.domains() |
| 78 | for d in dA: |
| 79 | if d in dB: |
| 80 | raise Exception('Duplicate domain "%s" found' % d) |
| 81 | for d in dB: |
| 82 | if d in dA: |
| 83 | raise Exception('Duplicate domain "%s" found' % d) |
| 84 | kA = pA.keys() |
| 85 | kB = pB.keys() |
| 86 | for k in kA: |
| 87 | if k in kB: |
| 88 | raise Exception('Duplicate key %s found' % k) |
| 89 | for k in kB: |
| 90 | if k in kA: |
| 91 | raise Exception('Duplicate key %s found' % k) |
| 92 | return self |
| 93 | |
| 94 | def teardown(self): |
| 95 | """ |
| 96 | Teardown the link. |
| 97 | Removes endpoints from properties I{links} collection. |
| 98 | @return: self |
| 99 | @rtype: L{Link} |
| 100 | """ |