mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ticket 1568 - DN objects should support the insert method
Add dn.insert() and update unittest
This commit is contained in:
committed by
Rob Crittenden
parent
2012f847f3
commit
fae07f8154
30
ipalib/dn.py
30
ipalib/dn.py
@@ -1004,9 +1004,19 @@ class DN(object):
|
||||
dn[:]
|
||||
|
||||
# Set the 2nd and 3rd RDN using slices (all are equivalent)
|
||||
dn[1:3] = ('cn', 'Bob), ('dc', 'redhat.com')
|
||||
dn[1:3] = [['cn', 'Bob], ['dc', 'redhat.com']]
|
||||
dn[1:3] = RDN('cn', 'Bob), RDN('dc', 'redhat.com')
|
||||
dn[1:3] = ('cn', 'Bob'), ('dc', 'redhat.com')
|
||||
dn[1:3] = [['cn', 'Bob'], ['dc', 'redhat.com']]
|
||||
dn[1:3] = RDN('cn', 'Bob'), RDN('dc', 'redhat.com')
|
||||
|
||||
DN objects support the insert operation.
|
||||
|
||||
dn.insert(i,x) is exactly equivalent to dn[i:i] = [x], thus the following
|
||||
are all equivalent:
|
||||
|
||||
dn.insert(i, ('cn','Bob'))
|
||||
dn.insert(i, ['cn','Bob'])
|
||||
dn.insert(i, RDN(('cn','Bob')))
|
||||
dn[i:i] = [('cn','Bob')]
|
||||
|
||||
DN objects support equality testing and comparision. See RDN for the
|
||||
definition of the comparision method.
|
||||
@@ -1214,6 +1224,20 @@ class DN(object):
|
||||
|
||||
return self
|
||||
|
||||
def insert(self, i, x):
|
||||
'''
|
||||
x must be a 2-value tuple or list promotable to an RDN object,
|
||||
or a RDN object.
|
||||
|
||||
dn.insert(i, x) is the same as s[i:i] = [x]
|
||||
|
||||
When a negative index is passed as the first parameter to the
|
||||
insert() method, the list length is added, as for slice
|
||||
indices. If it is still negative, it is truncated to zero, as
|
||||
for slice indices.
|
||||
'''
|
||||
self.rdns.insert(i, self._rdn_from_value(x))
|
||||
|
||||
# The implementation of startswith, endswith, tailmatch, adjust_indices
|
||||
# was based on the Python's stringobject.c implementation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user