From 84c4043f6e775a95d2a458bda13898fdde795f0a Mon Sep 17 00:00:00 2001 From: stroeder Date: Sun, 26 Mar 2006 12:23:07 +0000 Subject: [PATCH] Examples for using ldap.async. --- Demo/Lib/ldap/async/ldifwriter.py | 42 +++++++++++++++++++++++++++++++ Demo/Lib/ldap/async/sizelimit.py | 42 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 Demo/Lib/ldap/async/ldifwriter.py create mode 100644 Demo/Lib/ldap/async/sizelimit.py diff --git a/Demo/Lib/ldap/async/ldifwriter.py b/Demo/Lib/ldap/async/ldifwriter.py new file mode 100644 index 0000000..f919cd9 --- /dev/null +++ b/Demo/Lib/ldap/async/ldifwriter.py @@ -0,0 +1,42 @@ +""" +ldifwriter - using ldap.async module for output of LDIF stream + of LDAP search results + +Written by Michael Stroeder + +$Id: ldifwriter.py,v 1.4 2006/03/26 12:23:07 stroeder Exp $ + +This example translates the naming context of data read from +input, sanitizes some attributes, maps/removes object classes, +maps/removes attributes., etc. It's far from being complete though. + +Python compability note: +Tested on Python 2.0+, should run on Python 1.5.x. +""" + +import sys,ldap,ldap.async + +s = ldap.async.LDIFWriter( + ldap.initialize('ldap://localhost:1390'), + sys.stdout +) + +s.startSearch( + 'dc=stroeder,dc=de', + ldap.SCOPE_SUBTREE, + '(objectClass=*)', +) + +try: + partial = s.processResults() +except ldap.SIZELIMIT_EXCEEDED: + sys.stderr.write('Warning: Server-side size limit exceeded.\n') +else: + if partial: + sys.stderr.write('Warning: Only partial results received.\n') + +sys.stderr.write( + '%d results received.\n' % ( + s.endResultBreak-s.beginResultsDropped + ) +) diff --git a/Demo/Lib/ldap/async/sizelimit.py b/Demo/Lib/ldap/async/sizelimit.py new file mode 100644 index 0000000..9915909 --- /dev/null +++ b/Demo/Lib/ldap/async/sizelimit.py @@ -0,0 +1,42 @@ +""" +ldifwriter - using ldap.async module for retrieving partial results + in a list even though the exception ldap.SIZELIMIT_EXCEEDED + was raised.output of LDIF stream + +Written by Michael Stroeder + +$Id: sizelimit.py,v 1.4 2006/03/26 12:23:07 stroeder Exp $ + +This example translates the naming context of data read from +input, sanitizes some attributes, maps/removes object classes, +maps/removes attributes., etc. It's far from being complete though. + +Python compability note: +Tested on Python 2.0+, should run on Python 1.5.x. +""" + +import sys,ldap,ldap.async + +s = ldap.async.List( + ldap.initialize('ldap://localhost:1390'), +) + +s.startSearch( + 'dc=stroeder,dc=de', + ldap.SCOPE_SUBTREE, + '(objectClass=*)', +) + +try: + partial = s.processResults() +except ldap.SIZELIMIT_EXCEEDED: + sys.stderr.write('Warning: Server-side size limit exceeded.\n') +else: + if partial: + sys.stderr.write('Warning: Only partial results received.\n') + +sys.stderr.write( + '%d results received.\n' % ( + len(s.allResults) + ) +)