We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e75c24d commit 4b9b845Copy full SHA for 4b9b845
Lib/ldap/filter.py
@@ -87,3 +87,21 @@ def time_span_filter(
87
until_timestr=strf_secs(until_timestamp),
88
)
89
# end of time_span_filter()
90
+
91
92
+def is_filter(ldap_filter):
93
+ """
94
+ Returns True if `ldap_filter' can be parsed as a valid LDAP filter, otherwise False is returned.
95
96
+ import ldap
97
+ lo = ldap.initialize('')
98
+ try:
99
+ lo.search_ext_s('', ldap.SCOPE_BASE, ldap_filter)
100
+ except (ldap.FILTER_ERROR, TypeError, ValueError):
101
+ return False
102
+ except ldap.SERVER_DOWN:
103
+ # the filter syntax is valid, as the connection is not bound we expect SERVER_DOWN here
104
+ return True
105
+ finally:
106
+ lo.unbind()
107
+ raise RuntimeError('Could not check filter syntax.') # can not happen
0 commit comments