예제 #1
0
class LDIFTreeEntry(
        entry.EditableLDAPEntry,
        entryhelpers.DiffTreeMixin,
        entryhelpers.SubtreeFromChildrenMixin,
        entryhelpers.MatchMixin,
        entryhelpers.SearchByTreeWalkingMixin,
):
    implements(interfaces.IConnectedLDAPEntry)

    def __init__(self, path, dn=None, *a, **kw):
        if dn is None:
            dn = ''
        entry.BaseLDAPEntry.__init__(self, dn, *a, **kw)
        self.path = path
        if dn != '':  #TODO DistinguishedName.__nonzero__
            self._load()

    def _load(self):
        assert self.path.endswith('.dir')
        entryPath = '%s.ldif' % self.path[:-len('.dir')]

        parser = StoreParsedLDIF()

        try:
            f = file(entryPath)
        except IOError, e:
            if e.errno == errno.ENOENT:
                return
            else:
                raise
        while 1:
            data = f.read(8192)
            if not data:
                break
            parser.dataReceived(data)
        parser.connectionLost(failure.Failure(error.ConnectionDone))
        assert parser.done

        entries = parser.seen
        if len(entries) == 0:
            raise LDIFTreeEntryContainsNoEntries
        elif len(entries) > 1:
            raise LDIFTreeEntryContainsMultipleEntries, entries
        else:
            # TODO ugliness and all of its friends
            for k, v in entries[0].items():
                self._attributes[k] = attributeset.LDAPAttributeSet(k, v)
예제 #2
0
    def testCopy(self):
        class Magic:
            pass
        m1 = Magic()
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd', m1])
        b = a.__copy__()
        self.assertEquals(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEquals(magicFromA, magicFromB)
        self.assertIdentical(magicFromA, magicFromB)

        a.update('x')
        self.assertEquals(a, sets.Set(['b', 'c', 'd', m1, 'x']))
        self.assertEquals(b, sets.Set(['b', 'c', 'd', m1]))
예제 #3
0
    def testDeepCopy(self):
        class Magic:
            def __eq__(self, other):
                return isinstance(other, self.__class__)
            def __hash__(self):
                return 42
        m1 = Magic()
        a = attributeset.LDAPAttributeSet('k', ['a', m1])
        b = a.__deepcopy__({})
        self.assertEquals(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEquals(magicFromA, magicFromB)
        self.assertNotIdentical(magicFromA, magicFromB)

        a.update('x')
        self.assertEquals(a, sets.Set(['a', m1, 'x']))
        self.assertEquals(b, sets.Set(['a', m1]))
예제 #4
0
 def testEquality_AttributeSet_False(self):
     a = delta.Add('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     self.assertNotEquals(a, b)
예제 #5
0
 def buildAttributeSet(self, key, values):
     return attributeset.LDAPAttributeSet(key, values)
예제 #6
0
 def testEquality_True_Set(self):
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     self.assertEquals(a, b)
예제 #7
0
 def testSymmetricDifference(self):
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e'])
     self.assertEquals(a ^ b, sets.Set(['d', 'e']))
예제 #8
0
 def testIntersection(self):
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e'])
     self.assertEquals(a & b, sets.Set(['b', 'c']))
예제 #9
0
 def testUnion(self):
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e'])
     self.assertEquals(a | b, sets.Set(['b', 'c', 'd', 'e']))
예제 #10
0
 def testEquality_False_Key(self):
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('l', ['b', 'c', 'd'])
     self.assertNotEqual(a, b)
예제 #11
0
 def testEquality_True_List_Ordering(self):
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = ['b', 'd', 'c']
     self.assertEquals(a, b)