1 """
2 Changes to the content of one single LDAP entry.
3
4 (This means these do not belong here: adding or deleting of entries,
5 changing of location in tree)
6 """
7
8 from ldaptor import attributeset
9 from ldaptor.protocols import pureldap, pureber
10 from ldaptor.protocols.ldap import ldif, distinguishedname
11
14 raise NotImplementedError
15
16 _LDAP_OP = None
17
28
33
34 -class Add(Modification):
52
72
74 _LDAP_OP = 2
75
77 if self:
78 entry[self.key] = self
79 else:
80 try:
81 del entry[self.key]
82 except KeyError:
83 pass
84
86 r=[]
87 values = list(self)
88 values.sort()
89 r.append(ldif.attributeAsLDIF('replace', self.key))
90 for v in values:
91 r.append(ldif.attributeAsLDIF(self.key, v))
92 r.append('-\n')
93 return ''.join(r)
94
95
98 """
99 Find the correct entry in IConnectedLDAPEntry and patch it.
100
101 @param root: IConnectedLDAPEntry that is at the root of the
102 subtree the patch applies to.
103
104 @returns: Deferred with None or failure.
105 """
106 raise NotImplementedError
107
109 - def __init__(self, dn, modifications=[]):
114
123
128
134 _getClassFromOp = classmethod(_getClassFromOp)
135
137 if not isinstance(request, pureldap.LDAPModifyRequest):
138 raise RuntimeError("%s.fromLDAP needs an LDAPModifyRequest"
139 % class_.__name__)
140 dn = request.object
141 result = []
142 for op, mods in request.modification:
143 op = op.value
144 klass = class_._getClassFromOp(op)
145 if klass is None:
146 raise RuntimeError("Unknown LDAP op number %r in %s.fromLDAP"
147 % (op, class_.__name__))
148
149 key, vals = mods
150 key = key.value
151 vals = [x.value for x in vals]
152 m = klass(key, vals)
153 result.append(m)
154 return class_(dn, result)
155 fromLDAP = classmethod(fromLDAP)
156
158 d = root.lookup(self.dn)
159 def gotEntry(entry, modifications):
160 for mod in self.modifications:
161 mod.patch(entry)
162 return entry
163 d.addCallback(gotEntry, self.modifications)
164 return d
165
167 return (self.__class__.__name__
168 + '('
169 + 'dn=%r' % str(self.dn)
170 + ', '
171 + 'modifications=%r' % self.modifications
172 + ')')
173
175 if not isinstance(other, self.__class__):
176 return 0
177 if self.dn != other.dn:
178 return 0
179 if self.modifications != other.modifications:
180 return 0
181 return 1
182
184 return not self==other
185
189
191 l = str(self.entry).splitlines()
192 assert l[0].startswith('dn:')
193 l[1:1] = [ldif.attributeAsLDIF('changetype', 'add').rstrip('\n')]
194 return ''.join([x+'\n' for x in l])
195
200 d.addCallback(gotParent, self.entry)
201 return d
202
204 return (self.__class__.__name__
205 + '('
206 + '%r' % self.entry
207 + ')')
208
210 if not isinstance(other, self.__class__):
211 return False
212 if self.entry != other.entry:
213 return False
214 return True
215
217 return not self==other
218
222
229
234 d.addCallback(gotEntry)
235 return d
236
238 return (self.__class__.__name__
239 + '('
240 + '%r' % self.dn
241 + ')')
242
244 if not isinstance(other, self.__class__):
245 return False
246 if self.dn != other.dn:
247 return False
248 return True
249
251 return not self==other
252