Skip to content

Commit cefcefd

Browse files
authored
Merge pull request #181 (Fixes #178)
ldap3-2.0.7 API change (Fixes #178)
2 parents fea68a9 + f756454 commit cefcefd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

python/multicorn/ldapfdw.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(self, fdw_options, fdw_columns):
123123
ldap3.Server(self.ldapuri),
124124
user=fdw_options.get("binddn", None),
125125
password=fdw_options.get("bindpwd", None),
126-
client_strategy=ldap3.STRATEGY_SYNC_RESTARTABLE)
126+
client_strategy=ldap3.RESTARTABLE if ldap3.version.__version__ > '2.0.0' else ldap3.STRATEGY_SYNC_RESTARTABLE)
127127
self.path = fdw_options["path"]
128128
self.scope = self.parse_scope(fdw_options.get("scope", None))
129129
self.object_class = fdw_options["objectclass"]
@@ -159,19 +159,22 @@ def execute(self, quals, columns):
159159
for key, value in entry["attributes"].items():
160160
if key.lower() in self.field_definitions:
161161
pgcolname = self.field_definitions[key.lower()].column_name
162-
if pgcolname in self.array_columns:
162+
if ldap3.version.__version__ > '2.0.0':
163163
value = value
164164
else:
165-
value = value[0]
165+
if pgcolname in self.array_columns:
166+
value = value
167+
else:
168+
value = value[0]
166169
litem[pgcolname] = value
167170
yield litem
168171

169172
def parse_scope(self, scope=None):
170173
if scope in (None, "", "one"):
171-
return ldap3.SEARCH_SCOPE_SINGLE_LEVEL
174+
return ldap3.LEVEL if ldap3.version.__version__ > '2.0.0' else ldap3.SEARCH_SCOPE_SINGLE_LEVEL
172175
elif scope == "sub":
173-
return ldap3.SEARCH_SCOPE_WHOLE_SUBTREE
176+
return ldap3.SUBTREE if ldap3.version.__version__ > '2.0.0' else ldap3.SEARCH_SCOPE_WHOLE_SUBTREE
174177
elif scope == "base":
175-
return ldap3.SEARCH_SCOPE_BASE_OBJECT
178+
return ldap3.BASE if ldap3.version.__version__ > '2.0.0' else ldap3.SEARCH_SCOPE_BASE_OBJECT
176179
else:
177180
log_to_postgres("Invalid scope specified: %s" % scope, ERROR)

0 commit comments

Comments
 (0)