ldap3.strategy package

Submodules

ldap3.strategy.asynchronous module

class ldap3.strategy.asynchronous.AsyncStrategy(ldap_connection)[source]

Bases: ldap3.strategy.base.BaseStrategy

This strategy is asynchronous. You send the request and get the messageId of the request sent Receiving data from socket is managed in a separated thread in a blocking mode Requests return an int value to indicate the messageId of the requested Operation You get the response with get_response, it has a timeout to wait for response to appear Connection.response will contain the whole LDAP response for the messageId requested in a dict form Connection.request will contain the result LDAP message in a dict form Response appear in strategy._responses dictionary

class ReceiverSocketThread(ldap_connection)[source]

Bases: threading.Thread

The thread that actually manage the receiver socket

run()[source]

Wait for data on socket, compute the length of the message and wait for enough bytes to decode the message Message are appended to strategy._responses

close()[source]

Close connection and stop socket thread

get_stream()[source]
open(reset_usage=True, read_server_info=True)[source]

Open connection and start listen on the socket in a different thread

Clears connection.response and returns messageId

post_send_single_response(message_id)[source]

Clears connection.response and returns messageId.

receiving()[source]
set_stream(value)[source]

ldap3.strategy.asyncStream module

class ldap3.strategy.asyncStream.AsyncStreamStrategy(ldap_connection)[source]

Bases: ldap3.strategy.asynchronous.AsyncStrategy

This strategy is asynchronous. It streams responses in a generator as they appear in the self._responses container

accumulate_stream(message_id, change)[source]
get_stream()[source]
set_stream(value)[source]

ldap3.strategy.base module

class ldap3.strategy.base.BaseStrategy(ldap_connection)[source]

Bases: object

Base class for connection strategy

close()[source]

Close connection

static compute_ldap_message_size(data)[source]

Compute LDAP Message size according to BER definite length rules Returns -1 if too few data to compute message length

static decode_control(control)[source]

decode control, return a 2-element tuple where the first element is the control oid and the second element is a dictionary with description (from Oids), criticality and decoded control value

static decode_control_fast(control)[source]

decode control, return a 2-element tuple where the first element is the control oid and the second element is a dictionary with description (from Oids), criticality and decoded control value

static decode_request(message_type, component, controls=None)[source]
decode_response(ldap_message)[source]

Convert received LDAPMessage to a dict

decode_response_fast(ldap_message)[source]

Convert received LDAPMessage from fast ber decoder to a dict

do_operation_on_referral(request, referrals)[source]
do_search_on_auto_range(request, response)[source]
get_response(message_id, timeout=None, get_request=False)[source]

Get response LDAP messages Responses are returned by the underlying connection strategy Check if message_id LDAP message is still outstanding and wait for timeout to see if it appears in _get_response Result is stored in connection.result Responses without result is stored in connection.response A tuple (responses, result) is returned

get_stream()[source]
open(reset_usage=True, read_server_info=True)[source]

Open a socket to a server. Choose a server from the server pool if available

post_send_single_response(message_id)[source]
receiving()[source]
send(message_type, request, controls=None)[source]

Send an LDAP message Returns the message_id

sending(ldap_message)[source]
set_stream(value)[source]
unbind_referral_cache()[source]
valid_referral_list(referrals)[source]

ldap3.strategy.ldifProducer module

class ldap3.strategy.ldifProducer.LdifProducerStrategy(ldap_connection)[source]

Bases: ldap3.strategy.base.BaseStrategy

This strategy is used to create the LDIF stream for the Add, Delete, Modify, ModifyDn operations. You send the request and get the request in the ldif-change representation of the operation. NO OPERATION IS SENT TO THE LDAP SERVER! Connection.request will contain the result LDAP message in a dict form Connection.response will contain the ldif-change format of the requested operation if available You don’t need a real server to connect to for this strategy

accumulate_stream(fragment)[source]
get_stream()[source]
post_send_single_response(message_id)[source]
receiving()[source]
send(message_type, request, controls=None)[source]

Build the LDAPMessage without sending to server

set_stream(value)[source]

ldap3.strategy.mockAsync module

class ldap3.strategy.mockAsync.MockAsyncStrategy(ldap_connection)[source]

Bases: ldap3.strategy.mockBase.MockBaseStrategy, ldap3.strategy.asynchronous.AsyncStrategy

This strategy create a mock LDAP server, with asynchronous access It can be useful to test LDAP without accessing a real Server

get_response(message_id, timeout=None, get_request=False)[source]
post_send_single_response(payload)[source]

ldap3.strategy.mockBase module

class ldap3.strategy.mockBase.MockBaseStrategy[source]

Bases: object

Base class for connection strategy

add_entry(dn, attributes, validate=True)[source]
entries_from_json(json_entry_file)[source]
equal(dn, attribute_type, value_to_check)[source]
evaluate_filter_node(node, candidates)[source]

After evaluation each 2 sets are added to each MATCH node, one for the matched object and one for unmatched object. The unmatched object set is needed if a superior node is a NOT that reverts the evaluation. The BOOLEAN nodes mix the sets returned by the MATCH nodes

mock_add(request_message, controls)[source]
mock_bind(request_message, controls)[source]
mock_compare(request_message, controls)[source]
mock_delete(request_message, controls)[source]
mock_extended(request_message, controls)[source]
mock_modify(request_message, controls)[source]
mock_modify_dn(request_message, controls)[source]
remove_entry(dn)[source]
send(message_type, request, controls=None)[source]
class ldap3.strategy.mockBase.PagedSearchSet(response, size, criticality)[source]

Bases: object

next(size=None)[source]

ldap3.strategy.mockSync module

class ldap3.strategy.mockSync.MockSyncStrategy(ldap_connection)[source]

Bases: ldap3.strategy.mockBase.MockBaseStrategy, ldap3.strategy.sync.SyncStrategy

This strategy create a mock LDAP server, with synchronous access It can be useful to test LDAP without accessing a real Server

post_send_single_response(payload)[source]

ldap3.strategy.restartable module

class ldap3.strategy.restartable.RestartableStrategy(ldap_connection)[source]

Bases: ldap3.strategy.sync.SyncStrategy

get_stream()[source]
open(reset_usage=False, read_server_info=True)[source]
post_send_single_response(message_id)[source]
send(message_type, request, controls=None)[source]
set_stream(value)[source]

ldap3.strategy.reusable module

class ldap3.strategy.reusable.ReusableStrategy(ldap_connection)[source]

Bases: ldap3.strategy.base.BaseStrategy

A pool of reusable SyncWaitRestartable connections with lazy behaviour and limited lifetime. The connection using this strategy presents itself as a normal connection, but internally the strategy has a pool of connections that can be used as needed. Each connection lives in its own thread and has a busy/available status. The strategy performs the requested operation on the first available connection. The pool of connections is instantiated at strategy initialization. Strategy has two customizable properties, the total number of connections in the pool and the lifetime of each connection. When lifetime is expired the connection is closed and will be open again when needed.

class ConnectionPool(connection)[source]

Bases: object

Container for the Connection Threads

create_pool()[source]
get_info_from_server()[source]
rebind_pool()[source]
start_pool()[source]
terminate_pool()[source]
class PooledConnectionThread(worker, master_connection)[source]

Bases: threading.Thread

The thread that holds the Reusable connection and receive operation request via the queue Result are sent back in the pool._incoming list when ready

run()[source]
class PooledConnectionWorker(connection, request_queue)[source]

Bases: object

Container for the restartable connection. it includes a thread and a lock to execute the connection in the pool

new_connection()[source]
get_response(counter, timeout=None, get_request=False)[source]
get_stream()[source]
open(reset_usage=True, read_server_info=True)[source]
pools = {}
post_send_single_response(counter)[source]
receiving()[source]
send(message_type, request, controls=None)[source]
set_stream(value)[source]
terminate()[source]
validate_bind(controls)[source]

ldap3.strategy.sync module

class ldap3.strategy.sync.SyncStrategy(ldap_connection)[source]

Bases: ldap3.strategy.base.BaseStrategy

This strategy is synchronous. You send the request and get the response Requests return a boolean value to indicate the result of the requested Operation Connection.response will contain the whole LDAP response for the messageId requested in a dict form Connection.request will contain the result LDAP message in a dict form

get_stream()[source]
open(reset_usage=True, read_server_info=True)[source]

Executed after a search request Returns the result message and store in connection.response the objects found

post_send_single_response(message_id)[source]

Executed after an Operation Request (except Search) Returns the result message or None

receiving()[source]

Receive data over the socket Checks if the socket is closed

set_stream(value)[source]

Module contents