Skip to content

Merge pyldap + python-ldap #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 123 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
e9aeb11
started 2.4.46
Nov 7, 2017
0829d52
slapdtest.SlapdObject.restart() just restarts slapd without cleaning …
Nov 7, 2017
d534a46
added explicit reconnect tests for ReconnectLDAPObject
Nov 7, 2017
cd3d83b
started 2.5.0 (instead of 2.4.46)
Nov 11, 2017
dab08df
Compability changes for pyasn1 0.3.x or newer
Nov 11, 2017
5bb74db
announce pyasn1* modules as Installation prerequisites, do not index …
Nov 11, 2017
2ffd389
bumped Doc/ version to 2.5
Nov 12, 2017
c0485fb
added requirements.txt, pyasn1>=0.3.7 and pyasn1_modules>=0.1.5 now m…
Nov 12, 2017
5913883
removed stand-alone module dsml
Nov 12, 2017
9de7162
module dsml was removed => docs obsolete
Nov 12, 2017
b8d12d6
remove stand-alone module dsml
Nov 12, 2017
a90c037
there will never be DSMLv2 support
Nov 12, 2017
c4a612a
class ldap.async.DSMLWriter removed too
Nov 12, 2017
7f76d8c
removed stand-alone module dsml
Nov 12, 2017
26c4443
removed unused code schema.c
Nov 12, 2017
af29cba
removed unused code schema.c
Nov 12, 2017
47bbbcf
removed schema.h and LDAPinit_schema
Nov 12, 2017
03e5e7a
removed schema.h and LDAPinit_schema
Nov 12, 2017
c0a269f
added distclean.sh
Nov 12, 2017
e01cd16
ldap.__version__, ldap.__author__ and ldap.__license__ now imported f…
Nov 12, 2017
c9390f8
removed schema.c and schema.h
Nov 12, 2017
79cc697
For 2.5.x mandatory prerequisites are: Python 2.7.x, pyasn1 0.3.7+ an…
Nov 12, 2017
0f8e8ba
corrected Test02_ReconnectLDAPObject.__doc__
Nov 12, 2017
072f5cf
Added safety assertion when importing _ldap: ldap.pkginfo.__version__…
Nov 12, 2017
65e9271
* The methods SSSResponseControl.decodeControlValue() and
Nov 12, 2017
58e1f26
added missing ldap.pkginfo in setup.py
Nov 12, 2017
6b1063e
prepare release 2.5.1
Nov 12, 2017
26c2564
started 2.5.2
Nov 16, 2017
6c65d12
Tests/ scripts do not directly call SlapdTestCase.setUpClass() anymore
Nov 16, 2017
20ca4e8
only use _ldap when setting LIBLDAP_API_INFO
Nov 18, 2017
9eff367
moved code from version.c to ldapmodule.c and removed version.[ch]
Nov 18, 2017
1721df1
removed obsolete back-ward compability constants from common.h
Nov 18, 2017
aedfdd1
Add _ldap.__version__
encukou Nov 22, 2017
98181de
build checks whether LDAP_API_VERSION is OpenLDAP 2.4.x
Nov 18, 2017
b1485d6
setup.py: added ldap.controls.vlv to py_modules
Nov 18, 2017
f9a910d
removed setting class attribute result_code in SSSResponseControl.dec…
Nov 18, 2017
25f8e6c
announce minor changes for 2.5.2 in Modules/ and Lib/
Nov 18, 2017
c25fe47
white-space cleaning
Nov 18, 2017
707744c
always use bytes() for UUID() constructor in ldap.syncrepl
Nov 18, 2017
5b35eef
C module _ldap now also gets __author__ and __license__ set from ldap…
Nov 18, 2017
082490a
stick to naming convention with LDAPinit_pkginfo()
Nov 18, 2017
8622217
removed almost all assert statements in ldap.schema.models, removed i…
Nov 18, 2017
db60bf1
removed all dependencies on modules string and types
Nov 18, 2017
839a5ec
fixed var usage when failing in test_bad_change_records()
Nov 18, 2017
45efe4f
use new-style classes in ldapurl
Nov 18, 2017
e61079a
added LDIF test with line-folded, base64-encoded attribute
Nov 18, 2017
270519e
module ldif now uses functions b64encode() and b64decode()
Nov 18, 2017
4904fbf
docstring cosmetics
Nov 18, 2017
00c2b9b
ldapurl: eliminated use of .has_key()
Nov 18, 2017
1e54be2
ldap.modlist: removed use of .has_key() and use set for attribute val…
Nov 18, 2017
92d40af
ldap.schema.tokenizer: removed use of .has_key()
Nov 18, 2017
b22750f
minor code-cleaning in ldif
Nov 18, 2017
591ec60
removed unneeded import for UserDict from ldap.schema.subentry
Nov 18, 2017
08ff14e
use IterableUserDict in ldap.cidict
Nov 18, 2017
0cd22c7
avoid use of .has_key()
Nov 18, 2017
f6586aa
ldap.cidict: more nits around .has_key()
Nov 18, 2017
efee495
ldap.cidict.__version__ imported from package
Nov 18, 2017
7791f95
ldap.schema: avoid .has_key(), NOT_HUMAN_READABLE_LDAP_SYNTAXES is no…
Nov 18, 2017
1514852
ldap.async: avoid using .has_key() and check result types against set…
Nov 18, 2017
3e0ef81
ldap.ldapobject: avoid using .has_key()
Nov 18, 2017
63fd67e
fixed ldap.schema.models.Entry.__contains__()
Nov 18, 2017
99912ea
ldap.modlist does not need ldap.cidict anymore
Nov 18, 2017
6b15de5
removed obsolete Python compability note from modules docstrings and …
Nov 18, 2017
eeb4daa
added Test02_ReconnectLDAPObject.test_reconnect_get_state
Nov 18, 2017
da2d43d
added Test02_ReconnectLDAPObject.test_reconnect_get_state
Nov 18, 2017
657ea2b
(re)numbered test classes and methods
Nov 18, 2017
be191b1
added Test01_ReconnectLDAPObject.test104_reconnect_restore()
Nov 18, 2017
cdd3a41
fixed pickling and restoring of ReconnectLDAPObject, avoid .has_key()…
Nov 18, 2017
8bded9c
ldap.cidict: avoid using .has_key()
Nov 18, 2017
6615bb1
modifyModlist(): avoid map(None, ...)
Nov 18, 2017
3597f2a
a bit of PEP-8 for ldap.logger
Nov 18, 2017
4944d99
more obsolete docstring content removed
Nov 19, 2017
e8eb3ee
a bit of PEP-8 for ldap.sasl
Nov 19, 2017
1c23992
docstring line-wrapping
Nov 19, 2017
9935cb8
added more tests for sub-module ldap.dn
Nov 19, 2017
3897251
ldap.dn: use Boolean for notypes
Nov 19, 2017
5bdd161
use example.com in examples and tests
Nov 19, 2017
4a9591c
removed class ldap.ldapobject.NonblockingLDAPObject
Nov 19, 2017
0a1e520
added ldap.dn tests with ldap.DN_FORMAT_LDAPV2
Nov 19, 2017
101d2e2
bumped Doc version to 2.5.2.0
Nov 19, 2017
a0e459f
ldap.resiter: PEP-8 and a small fix
Nov 19, 2017
5bf5f3c
some code cosmetics in ldap.syncrepl and also a small fix
Nov 19, 2017
2e88535
some cosmetics in syncrepl demo script, use logging
Nov 19, 2017
1c26ef1
raise ldap.PROTOCOL_ERROR if compare operation returned a wrong result
Nov 20, 2017
d40f13c
added tests for ldap.syncrepl
Nov 20, 2017
773d7fb
another LDAPObject test
Nov 20, 2017
d448fb9
assume C extension API for Python 2.7+
Nov 20, 2017
608cda5
prepare release 2.5.2
Nov 20, 2017
a603396
use single quotes
Nov 20, 2017
798cb61
use ..assertEqual() instead of .assertEquals() in t_ldap_syncrepl.py
Nov 20, 2017
3141ce0
removed CVS-Id in t_ldap_syncrepl.py
Nov 20, 2017
fc020d0
Merge Michael's work from the CVS repository on SourceForge
encukou Nov 22, 2017
aeeac96
Infra: Condense CHANGELOG from 2.5
Nov 23, 2017
83c7235
Infra: Add a .gitignore file
Nov 23, 2017
e73f8d8
py3: Use print as a function rather than statement
Nov 23, 2017
17365cc
py3: Use new syntax for exceptions
Nov 23, 2017
17b4000
py3: Use modern idioms with built-in types
Nov 23, 2017
587460a
py3: Add and use the ldap.compat module
Nov 23, 2017
03e8e7e
py3: Use "int" instead of "long" (in Python code)
Nov 23, 2017
b62c589
py3: Use absolute imports
Nov 23, 2017
8a54ae3
py3: Import StringIO from io
Nov 23, 2017
301939e
Tests: Expand cidict membership tests
Nov 23, 2017
f605dbf
Infra: Re-format README to Restructured Text, add REMADE.rst symlink
Nov 23, 2017
b2c2b5c
slapdtest: Open slapd config file in text mode when writing it
Nov 23, 2017
42f3e84
slapdtest: Automatically try some common locations for SCHEMADIR
Nov 23, 2017
d54539f
slapdtest: Ensure server is stopped when the process exits
Nov 23, 2017
e90c7d1
Tests: Replace deprecated "failIf" name by "assertFalse"
Nov 23, 2017
ffd3580
Infra: Remove PKG-INFO
Nov 23, 2017
39ad22e
Doc: Write about bytes/text management
Nov 23, 2017
b0c9081
Modules: Use alternate sasl.h location on macOS
Nov 23, 2017
2a30680
Modules: Eliminate getter & setter that reimplement the default
Nov 23, 2017
83763d9
Tests: Add a test for whoami after unbind
Nov 23, 2017
750fe8c
Modules: Use Python 3- compatible module initialization
Nov 24, 2017
fa35757
py3: Make the bytes/text distinction
Nov 24, 2017
388eafb
Modules: Python 3, alias PyInt to PyLong
Nov 24, 2017
4549352
Tests: Add a test suite for binds
Nov 24, 2017
2949e78
Tests: Add a test suite for edits
Nov 24, 2017
ebcdaae
Tests: Add a smoke-check for listall() and attribute_types()
Nov 24, 2017
eb06c59
Infra: Advertise and test Python 3 compatibility
Nov 24, 2017
9608ead
Infra: Set authorship to the python-ldap project
Nov 24, 2017
92283a2
Infra: Thank all pyldap contributors
Nov 24, 2017
3138957
Infra: Update CHANGELOG
encukou Nov 24, 2017
4c9c526
Merge Python 3 porting (and infrastructure improvements) from pyldap
encukou Nov 24, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Auto-generated
.*.swp
*.pyc
__pycache__/
.tox

# shared libs installed by 'setup.py test'
/Lib/*.so*
/Lib/*.dylib
/Lib/*.pyd

# Build related
*.egg-info
build/
dist/
PKG-INFO
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: python

python:
- '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6'
# Note: when updating Python versions, also change setup.py and tox.ini

sudo: false

cache: pip

addons:
apt:
packages:
- ldap-utils
- slapd

install:
- pip install "pip>=7.1.0"
- pip install tox-travis tox

script: tox
73 changes: 73 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
----------------------------------------------------------------
Released 3.0.0 xxxx-xx-xx

Changes since 2.4.45:

Mandatory prerequisites:
- Python 2.7.x or 3.3+
- pyasn1 0.3.7+ and pyasn1_modules 0.1.5+

Python 3 support is merged from the pyldap fork (https://github.com/pyldap)

Infrastructure:
- Add .gitignore
- Re-format README to ReStructured Text
- Setup for automatic testing using Travis CI

Modules/
(thanks to Michael Ströder)
* removed unused code schema.c
* moved code from version.c to ldapmodule.c
* removed obsolete back-ward compability constants from common.h
* build checks whether LDAP_API_VERSION is OpenLDAP 2.4.x
* _ldap.__author__ and _ldap.__license__ also set from ldap.pkginfo
* assume C extension API for Python 2.7+

Lib/
(thanks to Michael Ströder)
* ldap.__version__, ldap.__author__ and ldap.__license__ now
imported from new sub-module ldap.pkginfo also to setup.py
* Added safety assertion when importing _ldap:
ldap.pkginfo.__version__ must match _ldap.__version__
* removed stand-alone module dsml
* slapdtest.SlapdObject.restart() just restarts slapd
without cleaning any data
* Compability changes for pyasn1 0.3.x or newer
(thanks to Ilya Etingof and Christian Heimes)
* The methods SSSResponseControl.decodeControlValue() and
VLVResponseControl.decodeControlValue() now follow the coding
convention to use camel-cased ASN.1 name as class attribute name.
The old class names are still set for back-ward compability
but should not be used in new code because they might be removed
in a later release.
* removed SSSRequestControl from ldap.controls.KNOWN_RESPONSE_CONTROLS
* removed all dependencies on modules string and types
* removed use of .has_key()
* removed class ldap.ldapobject.NonblockingLDAPObject
* new global constant ldap.LIBLDAP_API_INFO
* right after importing _ldap there is a call into libldap to initialize it
* method .decodeControlValue() of SSSResponseControl and VLVResponseControl
does not set class attribute result_code anymore
* always use bytes() for UUID() constructor in ldap.syncrepl
* module ldif now uses functions b64encode() and b64decode()
* fixed pickling and restoring of ReconnectLDAPObject

Lib/slapdtest.py
* Automatically try some common locations for SCHEMADIR
* Ensure server is stopped when the process exits

Tests/
(thanks to Michael Ströder)
* added explicit reconnect tests for ReconnectLDAPObject
* scripts do not directly call SlapdTestCase.setUpClass() anymore
* added LDIF test with folded, base64-encoded attribute
* added more tests for sub-module ldap.dn
* added tests for ldap.syncrepl (thanks to Karl Kornel)

Tests/
(thanks to pyldap contributors):
* Expand cidict membership test
* Add test suite for binds
* Add test suite for edits
* Add a smoke-check for listall() and attribute_types()

----------------------------------------------------------------
Released 2.4.45 2017-10-09

Expand Down
10 changes: 6 additions & 4 deletions Demo/Lib/ldap/async/deltree.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import ldap,ldap.async

class DeleteLeafs(ldap.async.AsyncSearchHandler):
Expand All @@ -15,7 +17,7 @@ def __init__(self,l):

def startSearch(self,searchRoot,searchScope):
if not searchScope in [ldap.SCOPE_ONELEVEL,ldap.SCOPE_SUBTREE]:
raise ValueError, "Parameter searchScope must be either ldap.SCOPE_ONELEVEL or ldap.SCOPE_SUBTREE."
raise ValueError("Parameter searchScope must be either ldap.SCOPE_ONELEVEL or ldap.SCOPE_SUBTREE.")
self.nonLeafEntries = []
self.deletedEntries = 0
ldap.async.AsyncSearchHandler.startSearch(
Expand All @@ -28,7 +30,7 @@ def startSearch(self,searchRoot,searchScope):
)

def _processSingleResult(self,resultType,resultItem):
if self._entryResultTypes.has_key(resultType):
if resultType in self._entryResultTypes:
# Don't process search references
dn,entry = resultItem
hasSubordinates = entry.get(
Expand All @@ -45,7 +47,7 @@ def _processSingleResult(self,resultType,resultItem):
else:
try:
self._l.delete_s(dn)
except ldap.NOT_ALLOWED_ON_NONLEAF,e:
except ldap.NOT_ALLOWED_ON_NONLEAF as e:
self.nonLeafEntries.append(dn)
else:
self.deletedEntries = self.deletedEntries+1
Expand All @@ -62,7 +64,7 @@ def DelTree(l,dn,scope=ldap.SCOPE_ONELEVEL):
non_leaf_entries = leafs_deleter.nonLeafEntries[:]
while non_leaf_entries:
dn = non_leaf_entries.pop()
print deleted_entries,len(non_leaf_entries),dn
print(deleted_entries,len(non_leaf_entries),dn)
leafs_deleter.startSearch(dn,ldap.SCOPE_SUBTREE)
leafs_deleter.processResults()
deleted_entries = deleted_entries+leafs_deleter.deletedEntries
Expand Down
3 changes: 0 additions & 3 deletions Demo/Lib/ldap/async/ldifwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
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
Expand Down
3 changes: 0 additions & 3 deletions Demo/Lib/ldap/async/sizelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
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
Expand Down
10 changes: 5 additions & 5 deletions Demo/Lib/ldapurl/urlsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@

No output of LDAP data is produced except trace output.
"""

from __future__ import print_function
import sys,getpass,ldap,ldapurl

try:
ldapUrl = ldapurl.LDAPUrl(ldapUrl=sys.argv[1])
except IndexError:
print 'Usage: %s [LDAP URL]' % (sys.argv[0])
print('Usage: %s [LDAP URL]' % (sys.argv[0]))
sys.exit(1)

for a in [
'urlscheme','hostport','dn','attrs','scope',
'filterstr','extensions','who','cred'
]:
print a,repr(getattr(ldapUrl,a))
print(a,repr(getattr(ldapUrl,a)))

l = ldap.initialize(ldapUrl.initializeUrl(),trace_level=1)
if ldapUrl.who!=None:
if ldapUrl.cred!=None:
cred=ldapUrl.cred
else:
print 'Enter password for simple bind with',repr(ldapUrl.who)
print('Enter password for simple bind with',repr(ldapUrl.who))
cred=getpass.getpass()
l.simple_bind_s(ldapUrl.who,cred)

res = l.search_s(ldapUrl.dn,ldapUrl.scope,ldapUrl.filterstr,ldapUrl.attrs)

print len(res),'search results'
print(len(res),'search results')
3 changes: 0 additions & 3 deletions Demo/Lib/ldif/ldifcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
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,ldif
Expand Down
21 changes: 11 additions & 10 deletions Demo/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ldaps://localhost:1391 (LDAP over SSL)
ldapi://%2ftmp%2fopenldap2 (domain socket /tmp/openldap2)
"""
from __future__ import print_function

import sys,os,ldap

Expand All @@ -23,10 +24,10 @@
# Complete path name of the file containing all trusted CA certs
CACERTFILE='/etc/ssl/ca-bundle.pem'

print """##################################################################
print("""##################################################################
# LDAPv3 connection with StartTLS ext. op.
##################################################################
"""
""")

# Create LDAPObject instance
l = ldap.initialize('ldap://localhost:1390',trace_level=ldapmodule_trace_level,trace_file=ldapmodule_trace_file)
Expand All @@ -44,19 +45,19 @@
# Now try StartTLS extended operation
l.start_tls_s()

print '***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION)
print '***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER)
print('***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION))
print('***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER))

# Try an explicit anon bind to provoke failure
l.simple_bind_s('','')

# Close connection
l.unbind_s()

print """##################################################################
print("""##################################################################
# LDAPv3 connection over SSL
##################################################################
"""
""")

# Create LDAPObject instance
l = ldap.initialize('ldaps://localhost:1391',trace_level=ldapmodule_trace_level,trace_file=ldapmodule_trace_file)
Expand All @@ -74,16 +75,16 @@
# Try an explicit anon bind to provoke failure
l.simple_bind_s('','')

print '***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION)
print '***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER)
print('***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION))
print('***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER))

# Close connection
l.unbind_s()

print """##################################################################
print("""##################################################################
# LDAPv3 connection over Unix domain socket
##################################################################
"""
""")

# Create LDAPObject instance
l = ldap.initialize('ldapi://%2ftmp%2fopenldap-socket',trace_level=ldapmodule_trace_level,trace_file=ldapmodule_trace_file)
Expand Down
9 changes: 5 additions & 4 deletions Demo/ldapcontrols.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import print_function
import ldap,ldapurl,pprint

from ldap.controls import LDAPControl,BooleanControl

l = ldap.initialize('ldap://localhost:1390',trace_level=2)

print 60*'#'
print(60*'#')

pprint.pprint(l.get_option(ldap.OPT_SERVER_CONTROLS))
l.manage_dsa_it(1,1)
pprint.pprint(l.get_option(ldap.OPT_SERVER_CONTROLS))
print 60*'#'
print(60*'#')

# Search with ManageDsaIT control (which has no value)
pprint.pprint(l.search_ext_s(
Expand All @@ -19,7 +20,7 @@
['*','+'],
serverctrls = [ LDAPControl('2.16.840.1.113730.3.4.2',1,None) ],
))
print 60*'#'
print(60*'#')

# Search with Subentries control (which has boolean value)
pprint.pprint(l.search_ext_s(
Expand All @@ -30,4 +31,4 @@
serverctrls = [ BooleanControl('1.3.6.1.4.1.4203.1.10.1',1,1) ],
))

print 60*'#'
print(60*'#')
6 changes: 4 additions & 2 deletions Demo/ldapurl_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import sys,pprint,ldap

from ldap.ldapobject import LDAPObject
Expand All @@ -15,7 +17,7 @@ class MyLDAPUrl(LDAPUrl):
ldap_url = MyLDAPUrl(sys.argv[1])
trace_level = int(ldap_url.trace_level or '0')

print '***trace_level',trace_level
print('***trace_level',trace_level)

ldap.trace_level = trace_level

Expand All @@ -37,6 +39,6 @@ class MyLDAPUrl(LDAPUrl):

pprint.pprint(result)

print '***DIAGNOSTIC_MESSAGE',repr(l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE))
print('***DIAGNOSTIC_MESSAGE',repr(l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)))

l.unbind_s()
13 changes: 7 additions & 6 deletions Demo/matchedvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
# Matched values control: (mail=*@example.org)
# dn: uid=jsmith,ou=People,dc=example,dc=com
# mail: jsmith@example.org
from __future__ import print_function

import ldap
from ldap.controls import MatchedValuesControl

def print_result(search_result):
for n in range(len(search_result)):
print "dn: %s" % search_result[n][0]
print("dn: %s" % search_result[n][0])
for attr in search_result[n][1].keys():
for i in range(len(search_result[n][1][attr])):
print "%s: %s" % (attr, search_result[n][1][attr][i])
print("%s: %s" % (attr, search_result[n][1][attr][i]))
print


Expand All @@ -51,13 +52,13 @@ def print_result(search_result):
mv = MatchedValuesControl(criticality=True, controlValue=control_filter)

res = ld.search_ext_s(base, scope, filter, attrlist = ['mail'])
print "LDAP filter used: %s" % filter
print "Requesting 'mail' attribute back"
print("LDAP filter used: %s" % filter)
print("Requesting 'mail' attribute back")
print
print "No matched values control:"
print("No matched values control:")
print_result(res)

res = ld.search_ext_s(base, scope, filter, attrlist = ['mail'], serverctrls = [mv])
print "Matched values control: %s" % control_filter
print("Matched values control: %s" % control_filter)
print_result(res)

Loading