Skip to content

Commit ebdee71

Browse files
committed
feat(ldap.dn): add ldap.dn.normalize()
1 parent cfa6a15 commit ebdee71

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Lib/ldap/dn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,8 @@ def is_dn(s,flags=0):
122122
return False
123123
else:
124124
return True
125+
126+
127+
def normalize(s, flags=0):
128+
"""Returns a normalized distinguished name (DN)"""
129+
return dn2str(str2dn(s, flags), flags)

Tests/t_ldap_dn.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,27 @@ def test_explode_rdn(self):
378378
['cn=äöüÄÖÜß']
379379
)
380380

381+
def test_normalize(self):
382+
"""
383+
test function normalize()
384+
"""
385+
self.assertEqual(
386+
ldap.dn.normalize('uid = test42 , ou = Testing , dc = example , dc = com', flags=ldap.DN_FORMAT_LDAPV3),
387+
'uid=test42,ou=Testing,dc=example,dc=com'
388+
)
389+
self.assertEqual(
390+
ldap.dn.normalize('cn=äöüÄÖÜß,dc=example,dc=com', flags=0),
391+
'cn=äöüÄÖÜß,dc=example,dc=com'
392+
)
393+
self.assertEqual(
394+
ldap.dn.normalize('cn=äöüÄÖÜß,dc=example,dc=com', flags=ldap.DN_FORMAT_LDAPV3),
395+
r'cn=\C3\A4\C3\B6\C3\BC\C3\84\C3\96\C3\9C\C3\9F,dc=example,dc=com'
396+
)
397+
self.assertEqual(
398+
ldap.dn.normalize('/ dc = com / dc = example / ou = Testing / uid = test42 , cn = test42', flags=ldap.DN_FORMAT_DCE),
399+
'/dc=com/dc=example/ou=Testing/uid=test42,cn=test42'
400+
)
401+
381402

382403
if __name__ == '__main__':
383404
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy