From: Ames A. <And...@co...> - 2005-05-30 11:09:02
|
Hi all, the attached patch tries to implement what subject says. It is barely tested (only against Active Directory) and it is diffed against stock 2.0.7 release (because I need it this way and because I have no CVS access by courtesy of a corp. firewall). It is actually a small add-on to Deepak Giridharagopal's control patch. Here is a minimalistic usage example. You might want to edit the four constants at the very beginning of the sample code, to make it behave meaningful in your environment: ------------ <demo> ---------------- url =3D "ldap://your.ldap.server/" base =3D "ou=3Dyour,dc=3Dbase,dc=3Ddn" search_flt =3D r'(sn=3Da*)' page_size =3D 100 import ldap from ldap.controls import LDAPControl ldap.set_option(ldap.OPT_REFERRALS, 0) l =3D ldap.initialize(url) l.bind_s(r"tnbk1\ts62fr", "webti", ldap.AUTH_SIMPLE) pctrl_val =3D ldap.encode_page_control(page_size, '') msgid =3D l.search_ext(base, ldap.SCOPE_SUBTREE, search_flt, = serverctrls=3D[LDAPControl(ldap.LDAP_CONTROL_PAGE_OID, True, = pctrl_val)]) pages =3D 0 while True: pages +=3D 1 print "Getting page %d" % (pages,) rtype, rdata, rmsgid, serverctrls =3D l.result3(msgid) pctrls =3D [c for c in serverctrls if c[0] =3D=3D = ldap.LDAP_CONTROL_PAGE_OID] if pctrls: # l.result3 returns raw tuples, no LDAPControl instances # this is just a matter of taste and can be easily changed est, cookie =3D ldap.decode_page_control(pctrls[0][2]) if cookie: pctrl_val =3D ldap.encode_page_control(page_size, cookie) msgid =3D l.search_ext(base, ldap.SCOPE_SUBTREE, search_flt, = serverctrls=3D[LDAPControl(ldap.LDAP_CONTROL_PAGE_OID, True, = pctrl_val)]) else: break else: print "Warning: Server ignores RFC 2696 control." break ------------ </demo> ---------------- HTH, aa --=20 Andreas Ames | Programmer | Comergo GmbH |=20 Voice: +49 69 7505 3213 | andreas . ames AT comergo . com |