From: David L. <dav...@cs...> - 2001-02-07 00:02:51
|
On Tue, 6 Feb 2001, Michael Str=F6der 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.t= xt > > 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: =09* do we really need a LDAPDN class? Isn't python's string enough? =09 (same with LDAPUrl - could be done in the urllib style) =09* AttributeSet is just a list =09* 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 =3D LDAP.Connection() try: =09ld.connect("localhost", 389) =09ld.bind("", "") =09MY_FILTER =3D "sn=3DJensen" =09MY_SEARCHBASE =3D "o=3DAce Industry, c=3DUS" =09cons =3D ld.getSearchConstraints() =09cons.setBatchSize(1) =09res =3D ld.search(MY_SEARCHBASE, ld.SCOPE_ONE, MY_FILTER, None, 0, cons) =09for findEntry in res: =09=09print findEntry.getDN() =09=09findAttrs =3D findEntry.getAttributeSet() =09=09enumAttrs =3D findAttrs.getAttributes() =09=09print "Attributes:" =09=09for anAttr in enumAttrs: =09=09=09print `anAttr.getName()` =09=09=09for aVal in anAttr.getStringValues() =09=09=09=09print `aVal` except LDAP.Exception: =09print "Error!" if ld.isConnected(): =09ld.disconnect() #-- example 9.2 import LDAP ld =3D LDAP.Connection() try: =09MY_HOST =3D "localhost" =09MY_PORT =3D 389 =09ld.connect(MY_HOST, MY_PORT) =09MY_NAME =3D "cn=3DBarbara Jensen,o=3DAce Industry,c=3DUS" =09MY_PASSWORD =3D "MysteryLady" =09ld.bind(MY_NAME, MY_PASSWORD) =09attrEmail =3D LDAP.Attribute("mail", "ba...@ac...") =09mod =3D LDAP.Modification(LDAP.REPLACE, attrEmail) =09ld.modify(MY_NAME, mod) =09print "Entry modified" except LDAP.Exception: =09print "Error!" if ld.isConnected(): =09ld.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 --=20 David Leonard Dav...@ds... 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 B73CD65FBEF4C089B79A8EBADF1A932F13E= A0FC8 |