o
    ßý°jâ  ã                   @   s    d Z zddlmZ W n ey   ddlmZ Y nw ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZ G dd„ deƒZdS )Ú
é    )ÚQueue)ÚStringIO)Úlinesepé   )Ú decode_persistent_search_control)ÚAsyncStrategy)ÚLDAPLDIFError)Úprepare_for_stream)Ú"persistent_search_response_to_ldifÚadd_ldif_headerc                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚAsyncStreamStrategyz|
    This strategy is asynchronous. It streams responses in a generator as they appear in the self._responses container
    c                 C   sn   t  | |¡ d| _t| _d| _d | _tƒ | _d| _	d | _
d| _d | _|jr/t|jƒ| _| `d S tƒ | _| `d S )NTF)r   Ú__init__Ú
can_streamr   Úline_separatorÚ
all_base64ÚstreamÚdictÚorderÚ_header_addedÚpersistent_search_message_idÚ	streamingÚcallbackÚ	pool_sizer   ÚeventsÚ	_requests)ÚselfÚldap_connection© r   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/strategy/asyncStream.pyr   /   s   þzAsyncStreamStrategy.__init__c                 C   sF   t  | ¡ | jr| jrt| jtƒr| jjr!|  tƒ ¡ d S d S d S d S ©N)r   Ú_start_listenr   r   Ú
isinstancer   ÚclosedÚ
set_stream©r   r   r   r   r!   A   s   
þz!AsyncStreamStrategy._start_listenc                 C   s"   t  | ¡ | jr| j ¡  d S d S r    )r   Ú_stop_listenr   r   Úcloser%   r   r   r   r&   G   s   
ÿz AsyncStreamStrategy._stop_listenc                 C   s\  || j kr¬| j� g | j|< W d   ƒ n1 sw   Y  | jrŠ| js?| j ¡ dkr?tdgƒd }| j t	|| j
 | j
 ƒ¡ t|ƒ}| jr„|r†| jjsˆ| j
 |¡}| jst| j ¡ dkrtd| _tdgƒd }| j t	|| j
 | j
 ƒ¡ | j t	|| j
 | j
 ƒ¡ d S d S d S d S t|ƒ}|rš| |¡ |d d= | js¥| j |¡ d S |  |¡ d S d S )Nr   ú-TÚcontrolsz2.16.840.1.113730.3.4.7)r   Ú
async_lockÚ
_responsesr   r   r   Útellr   Úwriter
   r   r   Ú
connectionr#   Újoinr   Úupdater   r   Úput)r   Ú
message_idÚchangeÚheaderÚ
ldif_linesÚfragmentÚnotificationr   r   r   Úaccumulate_streamL   s2   
ÿ ú

éz%AsyncStreamStrategy.accumulate_streamc                 C   s   | j r| jS d S r    )r   r   r%   r   r   r   Ú
get_streamf   s   zAsyncStreamStrategy.get_streamc              	   C   sL   d}z|  ¡ s	d}W n ttfy   d}Y nw |rtdƒ‚|| _d| _d S )NFTzstream must be writable)ÚwritableÚ
ValueErrorÚAttributeErrorr	   r   r   )r   ÚvalueÚerrorr   r   r   r$   k   s   €ÿ
zAsyncStreamStrategy.set_streamN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r&   r8   r9   r$   r   r   r   r   r   +   s    r   N)rB   Úqueuer   ÚImportErrorÚior   Úosr   Úprotocol.rfc2849r   Ústrategy.asynchronousr   Úcore.exceptionsr	   Ú
utils.convr
   r   r   r   r   r   r   r   Ú<module>   s    þ