I-D: The Java LDAP Application Program Interface

David Leonard david.leonard at csee.uq.edu.au
Thu Feb 8 00:35:44 CET 2001


more on the mapping of the java api to python (which it seems is a good thing)

what I forgot to say in my previous message was that I wanted to encourage
you (readers of this list) to attempt to convert some of the I-D examples into
python as an exercise that might reveal what Java idioms have been used that
make it incompatible (or uncomfortable to use) with Python.

Java's Iterator and Python's 'for' construct are good examples where they are
interchangable in many situations - but not all. only by attempting some
expressions do you find out how clumsy/elegant/robust/error-prone they are.

remember, by adding a library we are effectively extending a language.
With a little work, future expressions in this language extension will
be natural and effortless to its users.

d

On Wed, 7 Feb 2001, David Leonard typed thusly:
> Here's some of the examples converted from Java to API
>
>     #-- Example 9.1
>     import LDAP
>     ld = LDAP.Connection()
>     try:
> 	ld.connect("localhost", 389)
> 	ld.bind("", "")
> 	MY_FILTER = "sn=Jensen"
> 	MY_SEARCHBASE = "o=Ace Industry, c=US"
> 	cons = ld.getSearchConstraints()
> 	cons.setBatchSize(1)
> 	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():
> 	ld.disconnect()
>
>
>     #-- example 9.2
>     import LDAP
>
>     ld = LDAP.Connection()
>     try:
> 	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"
> 	ld.bind(MY_NAME, MY_PASSWORD)
>
> 	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():
> 	ld.disconnect()
>
> 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.
>
> d
>

-- 
David Leonard                           David.Leonard at csee.uq.edu.au
Dept of Comp. Sci. and Elec. Engg   _   Room:78-640  Ph:+61 7 336 51187
The University of Queensland       |+|  http://www.csee.uq.edu.au/~leonard/
QLD 4072  AUSTRALIA               ~` '~ B73CD65FBEF4C089B79A8EBADF1A932F13EA0FC8





More information about the python-ldap mailing list