I-D: The Java LDAP Application Program Interface

David Leonard david.leonard at csee.uq.edu.au
Wed Feb 7 01:03:04 CET 2001

On Tue, 6 Feb 2001, Michael Ströder typed thusly:

> For those of you who are interested in designing/implementing a new
> class API for python-ldap 2.0 the new Internet Draft
>   "The Java LDAP Application Program Interface"
> http://www.ietf.org/internet-drafts/draft-ietf-ldapext-ldap-java-api-13.txt
> might be interesting. It looks more suitable for Python than going
> with the C-oriented LDAPEXT-API. Anyone interested in implementing
> that?

well it looks nice. has anyone got any favourite bits?
i like the decent methods on LDAPConnection.

I think that if we take the java api, and convert all the Javaisms
to Pythonisms we could even submit "our own" RFC draft. :)

A lot in that java api is 'over the top' in terms of object-orientedness.
Here are some:
	* do we really need a LDAPDN class? Isn't python's string enough?
	  (same with LDAPUrl - could be done in the urllib style)
	* AttributeSet is just a list
	* can we ignore/hide LDAPExtendedOperation/Response/Listener?

the java api looks overly complex. after whittling it back a bit, i think
a nice pythonesqe api could be developed.

Here's some of the examples converted from Java to API

    #-- Example 9.1
    import LDAP
    ld = LDAP.Connection()
	ld.connect("localhost", 389)
	ld.bind("", "")
	MY_FILTER = "sn=Jensen"
	MY_SEARCHBASE = "o=Ace Industry, c=US"
	cons = ld.getSearchConstraints()
	res = ld.search(MY_SEARCHBASE, ld.SCOPE_ONE, MY_FILTER, None, 0, cons)
	for findEntry in res:
		print findEntry.getDN()
		findAttrs = findEntry.getAttributeSet()
		enumAttrs = findAttrs.getAttributes()
		print "Attributes:"
		for anAttr in enumAttrs:
			print `anAttr.getName()`
			for aVal in anAttr.getStringValues()
				print `aVal`
    except LDAP.Exception:
	print "Error!"
    if ld.isConnected():

    #-- example 9.2
    import LDAP

    ld = LDAP.Connection()
	MY_HOST = "localhost"
	MY_PORT = 389
	ld.connect(MY_HOST, MY_PORT)

	MY_NAME = "cn=Barbara Jensen,o=Ace Industry,c=US"
	MY_PASSWORD = "MysteryLady"

	attrEmail = LDAP.Attribute("mail", "babs at ace.com")
	mod = LDAP.Modification(LDAP.REPLACE, attrEmail)
	ld.modify(MY_NAME, mod)
	print "Entry modified"
    except LDAP.Exception:
	print "Error!"
    if ld.isConnected():

Feel free to convert some more to see if you like the feel of it, or
if it reminds you of a way that its done in another python builtin/library.

David Leonard                           David.Leonard at dstc.edu.au
CRC For Distributed Systems Technology  Room:78-632  Ph:+61 7 336 58358
The University of Queensland            http://www.dstc.edu.au/
QLD 4072  AUSTRALIA                     B73CD65FBEF4C089B79A8EBADF1A932F13EA0FC8

More information about the python-ldap mailing list