Module ldapurl (was: ldap_url_search ?)

Michael Ströder michael at stroeder.com
Sat Jun 29 13:02:12 CEST 2002


Derrick 'dman' Hudson wrote:
> On Fri, Jun 28, 2002 at 09:36:26PM +0200, Michael Ströder wrote:
> | Derrick 'dman' Hudson wrote:
> | >On Fri, Jun 28, 2002 at 04:44:54PM +0200, Michael Ströder wrote:
> | >| Michael Ströder wrote:
> | >| 
> | >| Anyone having any objections against removing methods url_search*()?
> | >| 
> | >| Anyone really using it?
> | >
> | >The only objection I have is that it really helped me to learn how to
> | >work with an LDAP URL.
> | 
> | How about practicing with the module ldapurl?
> 
> How?  The documentation is pretty sparse.
> [..]
> If the ldapurl module does everything that the current url_search
> methods do, then there is no compelling reason to keep the latter
> around.

It parses and unparses LDAP URLs and is designed to be completely 
independent from module ldap.

Some sample code for parsing a LDAP URL:

 >>> import ldapurl
 >>> ldap_url = 
ldapurl.LDAPUrl('ldap://localhost:1389/dc=stroeder,dc=com?cn???bindname=cn=Michael%2cdc=stroeder%2cdc=com,X-BINDPW=secret')
 >>> # Using the parsed LDAP URL by reading the class attributes
 >>> ldap_url.dn
u'dc=stroeder,dc=com'
 >>> ldap_url.hostport
'localhost:1389'
 >>> ldap_url.attrs
['cn']
 >>> ldap_url.filterstr
u'(objectclass=*)'
 >>> ldap_url.who
'cn=Michael,dc=stroeder,dc=com'
 >>> ldap_url.cred
'secret'
 >>> ldap_url.scope
0

Some sample code for the other way round:

 >>> ldap_url = 
ldapurl.LDAPUrl(hostport='localhost:1389',dn=u'dc=stroeder,dc=com',attrs=['cn','mail'],who='cn=Michael,dc=stroeder,dc=com',cred='secret')
 >>> ldap_url.unparse()
u'ldap://localhost:1389/dc=stroeder,dc=com?cn,mail?base?(objectclass=*)?bindname=cn=Michael%2Cdc=stroeder%2Cdc=com,X-BINDPW=secret'

That's pretty much all it does. Note that you don't have to 
specify all the class attributes. There are reasonable defaults 
assumed. And who and cred maps to None if not specified. See the 
tests at the bottom of ldapurl.py for more examples.

Advice: For security reasons you shouldn't specify passwords in 
LDAP URLs unless you really know what you're doing.

Ciao, Michael.






More information about the python-ldap mailing list