Skip to content

feat(ldap.dn): Add support for different formats in ldap.dn2str() via flags #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

spaceone
Copy link
Contributor

@spaceone spaceone commented Apr 1, 2022

In C dn2str() supports flags which works by providing LDAP_DN_FORMAT_UFN, LDAP_DN_FORMAT_AD_CANONICAL, ….
These symbols do exist in Python, but could not be used ultimately because the Python counterpart was pure Python and did not pass to dn2str(3).

Fix #257

@spaceone spaceone force-pushed the dn2str-flags branch 2 times, most recently from 6948a13 to f25fa60 Compare April 1, 2022 14:01
@droideck
Copy link
Contributor

@spaceone hi!
The PR says 'WIP', - is it still true?

@spaceone
Copy link
Contributor Author

@spaceone hi! The PR says 'WIP', - is it still true?

@droideck Well, I would say it needs code clenaup but the functionality is done. But before I try to cleanup I would like to get feedback.

@droideck
Copy link
Contributor

Overall, I think it'll be nice to have the feature.
@mistotebe what do you think?

@mistotebe
Copy link
Contributor

I agree, getting better DN handling would be nice.

Lib/ldap/dn.py Outdated
Comment on lines 60 to 61
#if not dn:
# return ''
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@mistotebe mistotebe Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we want to make the distinction for None and make dn2str(None) is None, might be too much hassle though.

@spaceone spaceone changed the title WIP: Add support for flags in ldap.dn2str() feat(ldap.dn): Add support for different formats in ldap.dn2str() via flags Jun 3, 2025
@spaceone spaceone requested a review from mistotebe June 3, 2025 21:51
spaceone added 2 commits June 4, 2025 08:25
…` via flags

In C `dn2str()` supports `flags` which works by providing one of `LDAP_DN_FORMAT_UFN`, `LDAP_DN_FORMAT_AD_CANONICAL`, `LDAP_DN_FORMAT_DCE`, `LDAP_DN_FORMAT_LDAPV3`.
These symbols do exist in Python, but could not be used ultimately because the Python counterpart was pure Python and did not pass to `dn2str(3)`.

Fix python-ldap#257
@spaceone
Copy link
Contributor Author

spaceone commented Jun 4, 2025

Performance comparison:

C:

python3 -m timeit -s 'import ldap.dn' "ldap.dn.dn2str([[('uid', 'test, 42', 1)],[('ou', 'Testing', 1)],[('dc', 'example', 1)],[('dc', 'com', 1)]], ldap.DN_FORMAT_LDAPV3)"
200000 loops, best of 5: 1.41 usec per loop

Python:

python3 -m timeit -s 'import ldap.dn' "ldap.dn.dn2str([[('uid', 'test, 42', 1)],[('ou', 'Testing', 1)],[('dc', 'example', 1)],[('dc', 'com', 1)]], 0)"
50000 loops, best of 5: 4.1 usec per loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ldap.dn.dn2str() does not support flags
3 participants