Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _bind(self, conn, bind, passwd):
# let's bind
if self.use_tls:
try:
conn.start_tls_s()
except Exception:
raise BackendError('Could not activate TLS on established '
'connection with %s' % self.uri,
backend=conn)
if bind is not None:
conn.simple_bind_s(bind, passwd)
conn.active = True
# We successfully connected to one of the servers, so
# we can just return the connection and stop processing
# any additional URIs.
if connected:
return conn
# We failed to connect to any of the servers,
# so raise an appropriate exception.
if not connected:
if isinstance(exc, (ldap.NO_SUCH_OBJECT,
ldap.SERVER_DOWN,
ldap.TIMEOUT)):
raise exc
# that's something else
raise BackendError(str(exc), backend=conn)