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 import codecs
14 raise NotImplementedError
15
16 _LDAP_OP = None
17
38
43
44 -class Add(Modification):
62
82
84 _LDAP_OP = 2
85
87 if self:
88 entry[self.key] = self
89 else:
90 try:
91 del entry[self.key]
92 except KeyError:
93 pass
94
96 r=[]
97 values = list(self)
98 values.sort()
99 r.append(ldif.attributeAsLDIF('replace', self.key))
100 for v in values:
101 r.append(ldif.attributeAsLDIF(self.key, v))
102 r.append('-\n')
103 return ''.join(r)
104
105
108 """
109 Find the correct entry in IConnectedLDAPEntry and patch it.
110
111 @param root: IConnectedLDAPEntry that is at the root of the
112 subtree the patch applies to.
113
114 @returns: Deferred with None or failure.
115 """
116 raise NotImplementedError
117
119 - def __init__(self, dn, modifications=[]):
124
133
138
144 _getClassFromOp = classmethod(_getClassFromOp)
145
147 if not isinstance(request, pureldap.LDAPModifyRequest):
148 raise RuntimeError("%s.fromLDAP needs an LDAPModifyRequest"
149 % class_.__name__)
150 dn = request.object
151 result = []
152 for op, mods in request.modification:
153 op = op.value
154 klass = class_._getClassFromOp(op)
155 if klass is None:
156 raise RuntimeError("Unknown LDAP op number %r in %s.fromLDAP"
157 % (op, class_.__name__))
158
159 key, vals = mods
160 key = key.value
161 vals = [x.value for x in vals]
162 m = klass(key, vals)
163 result.append(m)
164 return class_(dn, result)
165 fromLDAP = classmethod(fromLDAP)
166
168 d = root.lookup(self.dn)
169 def gotEntry(entry, modifications):
170 for mod in self.modifications:
171 mod.patch(entry)
172 return entry
173 d.addCallback(gotEntry, self.modifications)
174 return d
175
177 return (self.__class__.__name__
178 + '('
179 + 'dn=%r' % str(self.dn)
180 + ', '
181 + 'modifications=%r' % self.modifications
182 + ')')
183
185 if not isinstance(other, self.__class__):
186 return 0
187 if self.dn != other.dn:
188 return 0
189 if self.modifications != other.modifications:
190 return 0
191 return 1
192
194 return not self==other
195
199
201 l = str(self.entry).splitlines()
202 assert l[0].startswith('dn:')
203 l[1:1] = [ldif.attributeAsLDIF('changetype', 'add').rstrip('\n')]
204 return ''.join([x+'\n' for x in l])
205
210 d.addCallback(gotParent, self.entry)
211 return d
212
214 return (self.__class__.__name__
215 + '('
216 + '%r' % self.entry
217 + ')')
218
220 if not isinstance(other, self.__class__):
221 return False
222 if self.entry != other.entry:
223 return False
224 return True
225
227 return not self==other
228
232
239
244 d.addCallback(gotEntry)
245 return d
246
248 return (self.__class__.__name__
249 + '('
250 + '%r' % self.dn
251 + ')')
252
254 if not isinstance(other, self.__class__):
255 return False
256 if self.dn != other.dn:
257 return False
258 return True
259
261 return not self==other
262