
    nhs                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddlm
Z
mZmZmZmZ ddlmZmZmZmZ ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddl m!Z!m"Z"m#Z# ddl$m%Z% 	 ddl&m'Z'm(Z( dZ)	 ddl+m,Z,m-Z-m.Z.m/Z/ dZ0erddl2m3Z3 ddl4m5Z5  ejl                  d      jn                  Z8 ejl                  d      jn                  Z9dZ:e;e,gejx                  Z<d/dZ=ej|                  dk7  r	 	 	 	 	 	 	 	 d0dZ?	 d1	 	 	 	 	 	 	 	 	 d2dZ@n	 	 	 	 	 	 	 	 d3dZ?	 d1	 	 	 	 	 	 	 	 	 d4dZ@d/dZAd5dZB	 	 	 	 	 	 d6dZC	 	 	 	 	 	 	 	 d7d ZDd!ej                  v ZFd8d"ZGd9d#ZH G d$ d%      ZI G d& d'eI      ZJ G d( d)eI      ZK G d* d+e      ZLd:d,ZMef	 	 	 	 	 	 	 d;d-ZNef	 	 	 	 	 	 	 d<d.ZOy# e*$ r dZ)Y :w xY w# e*$ r dZ0e(Z/ddl1m,Z,m-Z-m.Z. Y Ew xY w)=z&Internal network layer helper methods.    )annotationsN)AbstractEventLoopBaseTransportBufferedProtocolFuture	Transport)TYPE_CHECKINGAnyOptionalUnion)_csotssl_support)create_task)MAX_MESSAGE_SIZE)
decompress)ProtocolError_OperationCancelled)_UNPACK_REPLY_OpMsg_OpReply)_errno_from_exception)SSLError	SSLSocketTF)BLOCKING_IO_LOOKUP_ERRORBLOCKING_IO_READ_ERRORBLOCKING_IO_WRITE_ERROR_sslConn)r   r   r   )AsyncConnection)
Connectionz<iiiiz<iiBg      ?c                  K   | j                         }| j                  d       t        j                         }	 t        rAt        | t        t        f      r+t        j                  t        | ||      |       d {    n/t        j                  |j                  | |      |       d {    | j                  |       y 7 F7 # t        j                  $ r}t        j                  d      |d }~ww xY w# | j                  |       w xY ww)N        timeout	timed out)
gettimeout
settimeoutasyncioget_running_loop	_HAVE_SSL
isinstancer   r   wait_for_async_socket_sendall_sslsock_sendallTimeoutErrorsocketr#   )sockbufr#   loopexcs        {/var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/pymongo/network_layer.pyasync_socket_sendallr5   O   s     ooGOOC##%D	!D9h*?@""#<T3#MW^___""4#4#4T3#?QQQ
 	  `Q 3nn[)s23 	 sY   6DAC :C;/C *C+C /DC C C3C..C33C6 6D		Dwin32c                  K   t        |      }d}dd}|t        |      k  r(	 || j                  ||d        z  }|t        |      k  r'y y # t        $ r}| j	                         }|dk(  rt        d      d t        |t              rW|j                         }|j                  |||       	 | d {  7   |j                  |       n# |j                  |       w xY wt        |t              rW|j                         }|j                  |||       	 | d {  7   |j                  |       n# |j                  |       w xY wt        rt        |t              r|j                         }|j                  |||       	 |j                  |||       | d {  7   |j                  |       |j                  |       n'# |j                  |       |j                  |       w xY wY d }~d }~ww xY ww)Nr   c                H    | j                         ry | j                  d        y Ndone
set_resultfuts    r4   	_is_readyz,_async_socket_sendall_ssl.<locals>._is_readyg       xxzNN4     !Underlying socket has been closedr>   r   returnNone)
memoryviewlensendBLOCKING_IO_ERRORSfilenor   r*   r   create_future
add_readerremove_readerr   
add_writerremove_writer_HAVE_PYOPENSSLr   )	r0   r1   r2   viewsentr?   r3   fdr>   s	            r4   r,   r,   a   s     #	!
 SXo/		$tu+.. SXo & /[[]8"#FGTQc#9:,,.COOB	37/!		**2.**2.c#:;,,.COOB	37/!		**2.**2."z#7O'P,,.COOB	37/Is;!		**2.**2. **2.**2.7/s    G4A G4	G4
G1AG,*C/B20C5G,C6G,D.DD.G,.E<G,>F?FF?#G,?$G##G,&G4,G11G4c                  K   t        t        |            }d}dd}||k  r7	 | j                  ||d        }|dk(  rt        d      |r|d | S ||z  }||k  r7|S # t        $ r}| j                         }	|	dk(  rt        d      d t        |t              rW|j                         }
|j                  |	||
       	 |
 d {  7   |j                  |	       n# |j                  |	       w xY wt        |t              rW|j                         }
|j                  |	||
       	 |
 d {  7   |j                  |	       n# |j                  |	       w xY wt        rt        |t               r|j                         }
|j                  |	||
       	 |j                  |	||
       |
 d {  7   |j                  |	       |j                  |	       n'# |j                  |	       |j                  |	       w xY wY d }~d }~ww xY ww)Nr   c                H    | j                         ry | j                  d        y r9   r:   r=   s    r4   r?   z,_async_socket_receive_ssl.<locals>._is_ready   r@   rA   connection closedrB   rC   rD   )rG   	bytearray	recv_intoOSErrorrJ   rK   r   r*   r   rL   rM   rN   r   rO   rP   rQ   r   )connlengthr2   oncemv
total_readr?   readr3   rT   r>   s              r4   _async_socket_receive_sslra      s     	&)*
	!
 6!#/~~bo619!"566et9$d"
 6!J 	9 & /[[]8"#FGTQc#9:,,.COOB	37/!		**2.**2.c#:;,,.COOB	37/!		**2.**2."z#7O'P,,.COOB	37/Is;!		**2.**2. **2.**2.7/s    H*A HA HH
H%AG<:C?C CG<C**6G<!D>&D)'D>,G<>E<G<G&F)'G,#G<$G33G<6H<HHc                2  K   t        |      }t        |      }d}d}||k  rE	 | j                  ||d        }|dkD  rt        |dz  d      }nt        |dz  d      }||z  }||k  rDy y # t        $ r# t	        j
                  |       d {  7   d}Y \w xY ww)Nr   MbP?   Mb?)rG   rH   rI   rJ   r'   sleepmaxmin)r0   r1   dummyrR   total_length
total_sentbackoffrS   s           r4   r,   r,      s      #3x
 <'yyjk!23 axgk51gk51$J <' & mmG,,,s9    BA( .B&B(!B	B
BBBBc                ^  K   t        t        |            }d}d}||k  r\	 | j                  ||d        }|dk(  rt        d      |r|d | S 	 |dkD  rt        |dz  d      }nt        |dz  d      }||z  }||k  r\|S # t        $ r# t        j                  |       d {  7   d}Y \w xY ww)Nr   rc   rW   rd   re   )	rG   rX   rY   rZ   rJ   r'   rf   rg   rh   )r[   r\   ri   r]   r^   r_   rl   r`   s           r4   ra   ra      s      	&)*
 6!	~~bo619!"566et9$ 
 axgk51gk51$J 6!  	 & mmG,,,s:   B-*A> 0B-<B->!B*B" B*'B-)B**B-c                &    | j                  |       y r9   )sendall)r0   r1   s     r4   ro   ro      s    LLrA   c                   K   	 | j                   j                  ry t        j                  t               d {    97 wr9   )cancel_context	cancelledr'   rf   _POLL_TIMEOUTr[   s    r4   _poll_cancellationru      s7     
((mmM***	  	+s   5?=?c                8  K   | j                         }|}| j                  d       t        j                         }	 t        rSt        | t        t        f      r=t        j                  t        | ||d      |       d {   | j                  |       S t        j                  t        | ||      |       d {   | j                  |       S 7 P7 # t        j                  $ r}t        j                  d      |d }~ww xY w# | j                  |       w xY ww)Nr!   T)r]   r"   r$   )r%   r&   r'   r(   r)   r*   r   r   r+   ra   _async_socket_receiver.   r/   r#   )r0   r\   sock_timeoutr#   r2   errs         r4   async_receive_data_socketrz      s      ??$LGOOC##%D&D9h*?@ )))$4H  	% !))%dFD9  	%
  3nn[)s23 	%se   8DAC >C?C D%C 9C:C =DC C D&C<<DD DDc                   K   t        t        |            }d}||k  r8|j                  | ||d         d {   }|dk(  rt        d      ||z  }||k  r8|S 7 !w)Nr   rW   )rG   rX   sock_recv_intorZ   )r[   r\   r2   r^   
bytes_readchunk_lengths         r4   rw   rw     st      
If%	&BJ
v
!00r*+GG1-..l"
	 v

 I	 Hs   4AAAAPyPyc                   | j                   j                  }d}|j                         dk(  ry	 t        |d      r|j	                         dkD  rd}n_|r9|t        j                         z
  }|dk  rd}t        t        |t              d      }nt        }| j                  j                  |d|      }| j                  j                  rt        d      |ry|rt        j                   d	      )
zABlock until at least one byte is read, or a timeout, or a cancel.FrB   NTpendingr   )r`   r#   operation cancelledr$   )r[   r0   rK   hasattrr   time	monotonicrg   rh   rs   socket_checkerselectrq   rr   r   r/   r#   )r[   deadliner0   	timed_outreadable	remainingr#   s          r4   wait_for_readr   '  s    99>>DI{{}
4#(:H $t~~'77	 > $Ic)];Q?'**11$T71SH((%&;<<..--/ rA   c                $   t        |      }t        |      }d}| j                  j                         }	 ||k  r	 t        rSt        | |       t        j                         r||z| j                  t        |t        j                         z
  d             nI|0t        t        |t        j                         z
  d      t              }nt        }| j                  |       | j                  j                  ||d        }|dk(  rt+        d      ||z  }||k  r| j                  |       |S # t        $ r9 | j                   j"                  rt%        d      d t'        j(                  d      d t&        j(                  $ r- | j                   j"                  rt%        d      d t        r Y st*        $ rJ}	| j                   j"                  rt%        d      d t-        |	      t.        j0                  k(  rY d }	~	 d }	~	ww xY w# | j                  |       w xY w)Nr   r   r$   rW   )rX   rG   r[   r%   _PYPYr   r   get_timeoutset_conn_timeoutrg   r   r   rh   rs   rY   rJ   rq   rr   r   r/   r#   rZ   r   errnoEINTR)
r[   r\   r   r1   r^   r}   orig_timeoutshort_timeoutr~   r3   s
             r4   receive_datar   H  s   
F
C	CBJ 99'')L',6!!$1((*x/C--c(T^^=M2Mq.QR+(+C4>>;K0KQ,OQ^(_(5))-8#yy222jk?C& q 122,&JI 6!L 	l+I3 & <&&00-.CD$Nnn[1t;>> &&00-.CD$N &&00-.CD$N(-< 	l+sH   G< C D( :G< (A<G9$G< 'G9/>G4-G< 3G44G99G< <Hc                  b    e Zd Zd	dZed
d       ZddZd
dZddZed
d       Z	ed
d       Z
y)NetworkingInterfaceBasec                    || _         y r9   rt   )selfr[   s     r4   __init__z NetworkingInterfaceBase.__init__  s	    	rA   c                    t         r9   NotImplementedErrorr   s    r4   r%   z"NetworkingInterfaceBase.gettimeout      !!rA   c                    t         r9   r   r   r#   s     r4   r&   z"NetworkingInterfaceBase.settimeout      !!rA   c                    t         r9   r   r   s    r4   closezNetworkingInterfaceBase.close  r   rA   c                    t         r9   r   r   s    r4   
is_closingz"NetworkingInterfaceBase.is_closing  r   rA   c                    t         r9   r   r   s    r4   get_connz NetworkingInterfaceBase.get_conn  r   rA   c                    t         r9   r   r   s    r4   r0   zNetworkingInterfaceBase.sock  r   rA   N)r[   r
   )rE   r
   r#   float | NonerE   rF   rE   bool)__name__
__module____qualname__r   propertyr%   r&   r   r   r   r0    rA   r4   r   r     sR     " """" " " " "rA   r   c                  n     e Zd Zd fdZed	d       Zd
dZddZddZedd       Z	edd       Z
 xZS )AsyncNetworkingInterfacec                $    t         |   |       y r9   superr   r   r[   	__class__s     r4   r   z!AsyncNetworkingInterface.__init__      rA   c                4    | j                   d   j                  S N   r[   r%   r   s    r4   r%   z#AsyncNetworkingInterface.gettimeout  s    yy|&&&rA   c                @    | j                   d   j                  |       y r   r[   r&   r   s     r4   r&   z#AsyncNetworkingInterface.settimeout  s    		!(rA   c                   K   | j                   d   j                          | j                   d   j                          d {    y 7 wr   )r[   r   wait_closedr   s    r4   r   zAsyncNetworkingInterface.close  s4     		!iil&&(((s   >A AAc                <    | j                   d   j                         S )Nr   r[   r   r   s    r4   r   z#AsyncNetworkingInterface.is_closing  s    yy|&&((rA   c                     | j                   d   S r   rt   r   s    r4   r   z!AsyncNetworkingInterface.get_conn  s    yy|rA   c                >    | j                   d   j                  d      S )Nr   r/   )r[   get_extra_infor   s    r4   r0   zAsyncNetworkingInterface.sock  s    yy|**844rA   )r[   z!tuple[Transport, PyMongoProtocol]rE   r   r   rE   rF   r   )rE   PyMongoProtocol)rE   socket.socket)r   r   r   r   r   r%   r&   r   r   r   r0   __classcell__r   s   @r4   r   r     sS     ' ')))   5 5rA   r   c                  t     e Zd Zd
 fdZddZddZddZddZedd       Z	edd       Z
ddZdd	Z xZS )NetworkingInterfacec                $    t         |   |       y r9   r   r   s     r4   r   zNetworkingInterface.__init__  r   rA   c                6    | j                   j                         S r9   r   r   s    r4   r%   zNetworkingInterface.gettimeout      yy##%%rA   c                :    | j                   j                  |       y r9   r   r   s     r4   r&   zNetworkingInterface.settimeout  s    		W%rA   c                8    | j                   j                          y r9   )r[   r   r   s    r4   r   zNetworkingInterface.close  s    		rA   c                6    | j                   j                         S r9   r   r   s    r4   r   zNetworkingInterface.is_closing  r   rA   c                    | j                   S r9   rt   r   s    r4   r   zNetworkingInterface.get_conn      yyrA   c                    | j                   S r9   rt   r   s    r4   r0   zNetworkingInterface.sock  r   rA   c                6    | j                   j                         S r9   )r[   rK   r   s    r4   rK   zNetworkingInterface.fileno  s    yy!!rA   c                8    | j                   j                  |      S r9   )r[   rY   )r   buffers     r4   rY   zNetworkingInterface.recv_into  s    yy""6**rA   )r[   Union[socket.socket, _sslConn]r   r   r   r   )rE   r   )rE   int)r   bytesrE   r   )r   r   r   r   r%   r&   r   r   r   r   r0   rK   rY   r   r   s   @r4   r   r     sN    &&&    "+rA   r   c                      e Zd ZdddZddZedd       ZddZddZddZ	ddZ
dd	Zdd
ZddZdddZdddZdddZddZy)r   Nc                   d | _         t        t        d            | _        d| _        t        t        d            | _        d| _        d | _        d| _        d| _	        d| _
        d| _        d| _        d| _        d | _        || _        d| _        d | _        t$        | _        d | _        t+        j,                         j/                         | _        t3        j4                         | _        t3        j4                         | _        y )N   r   	   TF)	transportrG   rX   _header_header_index_compression_header_compression_index_message_message_index_expecting_header_expecting_compression_message_size_op_code_connection_lost_read_waiter_timeout_is_compressed_compressor_idr   _max_message_size_response_tor'   r(   rL   _closedcollectionsdeque_pending_messages_done_messagesr   s     r4   r   zPyMongoProtocol.__init__  s    $( ")B-0#-il#; "#.2!%&+# %.2#-1!1+///1??A<G<M<M<O9D9J9J9LrA   c                    || _         y r9   r   r   s     r4   r&   zPyMongoProtocol.settimeout  s	    rA   c                    | j                   S )zGThe configured timeout for the socket that underlies our protocol pair.r   r   s    r4   r%   zPyMongoProtocol.gettimeout  s     }}rA   c                Z    || _         | j                   j                  t        t               y)zCalled exactly once when a connection is made.
        The transport argument is the transport representing the write side of the connection.
        N)r   set_write_buffer_limitsr   )r   r   s     r4   connection_madezPyMongoProtocol.connection_made  s!     #../?AQRrA   c                   K   | j                   j                         rt        d      | j                   j                  |       | j                   j	                          yw)z/Write a message to this connection's transport.zConnection is closedN)r   r   rZ   writeresume_reading)r   messages     r4   r  zPyMongoProtocol.write  sD     >>$$&011W%%%'s   AAc                  K   | j                   r	 | j                   j                          || _        | j
                  r#| j
                  j                          d{   }n| j                   r%| j                   j                         rt        d      t        j                         j                         }| j                  j                  |       	 | d{   }|| j
                  v r| j
                  j                  |       	 |r1|\  }}}}|||k7  rt        d|d|      |t        ||      }||fS t        d      # t        $ r t        d      dw xY w7 7 # || j
                  v r| j
                  j                  |       w w xY ww)zARead a single MongoDB Wire Protocol message from this connection.zconnection is already closedNGot response id  but expected rW   )r   r  AttributeErrorrZ   r   r   popleftr   r'   r(   rL   r   appendremover   r   )	r   
request_idmax_message_sizer  read_waiterop_codecompressor_idresponse_todatas	            r4   r`   zPyMongoProtocol.read  s    >>H--/ "2 //7799G~~$..";";"=<==!224BBDK""))+6< ++$"5"55''..{;8?5G]K%,'*;/
~V  (!$6= )**5 " H<=4GH : ,$"5"55''..{; 6sS   FE 0FEA3FE EE A(FEFE ,F

Fc                B   | j                   r1| j                  st        t        d            | _        | j                  S | j                  r| j
                  | j                  d S | j                  r| j                  | j                  d S | j                  | j                  d S )a8  Called to allocate a new receive buffer.
        The asyncio loop calls this method expecting to receive a non-empty buffer to fill with data.
        If any data does not fit into the returned buffer, this method will be called again until
        either no data remains or an empty buffer is returned.
        i @  N)r   r   rG   rX   r   r   r   r   r   r   r   )r   sizehints     r4   
get_bufferzPyMongoProtocol.get_buffer'  s       == *9U+; <==  !!<< 2 2 455&&++D,C,C,EFF}}T00233rA   c                   |dk(  r| j                  t        d             y| j                  ry| j                  ry| xj                  |z  c_        | j                  dk\  rTd| _        	 | j                         \  | _        | _        | _        | _	        t        t        | j                              | _        y| j                  rI| xj                  |z  c_        | j                  dk\  r$d| _	        | j                         \  | _        | _        y| xj"                  |z  c_        | j"                  | j                  k\  rd| _        | j$                  j'                          | j(                  r| j(                  j+                         }n"t-        j.                         j1                         }|j3                         r| j                  d       y|j5                  | j                  | j                   | j                  | j                  f       | j6                  j9                  |       d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        yy# t        $ r}| j                  |       Y d}~yd}~ww xY w)z9Called when the buffer was updated with the received datar   rW   Nr   Fr   T)r   rZ   r   r   r   process_headerr   r   r   r   r   rG   rX   r   r   process_compression_headerr   r   r   pause_readingr   r  r'   r(   rL   r;   r<   r   r	  )r   nbytesr3   results       r4   buffer_updatedzPyMongoProtocol.buffer_updated<  s"    Q;JJw234  !!&(!!R').&	 ++-*)3
 !+9T5G5G+H I&&##v-#&&!+.3+595T5T5V2t2v%$"4"44%)D"NN((*%%//779 113AAC{{}

4  3 3T5F5FV &&v.!"D&'D#"#D!"D DMDM"&D $D3 5 % JJsOs   &)I 	I9I44I9c                
   t        | j                        \  }}}}d}|dk(  r|dk  rt        d|d      d}|dz  }|dk  rt        d|d	      || j                  kD  rt        d|d
| j                  d      |dz
  |||fS )z&Unpack a MongoDB Wire Protocol header.F     Message length (zA) not longer than standard OP_COMPRESSED message header size (25)Tr   r   3) not longer than standard message header size (16)*) is larger than server max message size ())_UNPACK_HEADERr   r   r   )r   r\   _r  r  expecting_compressions         r4   r  zPyMongoProtocol.process_headerw  s    *8*F'; %d?|#&vj0qr  %)!aKFR<"6*,_`  D***"6* -!!%!7!7 :!= 
 {G[2GGGrA   c                <    t        | j                        \  }}}||fS )z2Unpack a MongoDB Wire Protocol compression header.)_UNPACK_COMPRESSION_HEADERr   )r   r  r$  r  s       r4   r  z*PyMongoProtocol.process_compression_header  s$    $>t?W?W$X!M%%rA   c                    t        | j                        }|D ]R  }|j                         s%||j                  d        n|j	                  |       | j
                  j                  |       T y r9   )listr   r;   r<   set_exceptionr   r	  )r   r3   r   msgs       r4   _resolve_pending_messagesz)PyMongoProtocol._resolve_pending_messages  s]    t--. 	,C88:;NN4(%%c*&&s+	,rA   c                h    | j                   j                          | j                  |       d| _        y )NT)r   abortr,  r   r   r3   s     r4   r   zPyMongoProtocol.close  s(    &&s+ $rA   c                    | j                  |       | j                  j                         s| j                  j                  d        y y r9   )r,  r   r;   r<   r/  s     r4   connection_lostzPyMongoProtocol.connection_lost  s7    &&s+||  "LL##D) #rA   c                8   K   | j                    d {    y 7 wr9   )r   r   s    r4   r   zPyMongoProtocol.wait_closed  s     lls   r9   )r#   Optional[float]r   r   )r   r   rE   rF   )r  r   rE   rF   )r  Optional[int]r  r   rE   ztuple[bytes, int])r  r   rE   rG   )r  r   rE   rF   )rE   ztuple[int, int, int, bool])rE   ztuple[int, int])r3   zOptional[Exception]rE   rF   r   )r   r   r   r   r&   r   r%   r   r  r`   r  r  r  r  r,  r   r1  r   r   rA   r4   r   r     s\    M4   S( +D4*9%vH.&
,%
*
rA   r   c                   K   	 t        j                  | j                  |      | j                         d {    y 7 # t         j                  $ r}t        j                  d      |d }~ww xY ww)Nr"   r$   )r'   r+   r  r%   r.   r/   r#   )r[   r1   r3   s      r4   async_sendallr6    sS     3tzz#HHH 3nn[)s23s1   A03? =? A0? A-A((A--A0c                  K   | j                   j                  }t        j                         rt        j                         }n|rt        j                         |z   }nd}|r!t        |t        j                         z
  d      }t        t        |             }t        | j                   j                  j                  ||            }||g}	 t        j                  ||t        j                         d{   \  }}	|	D ]  }
|
j                           |	rt        j                  |	       d{    t!        |      dk(  rt#        j$                  d      ||v r%|j'                         \  }}	 t(        |   } ||      S t1        d      7 7 ]# t*        $ r% t-        d|dt)        j.                               dw xY w# t        j2                  $ r7 |D ]  }
|
j                           t        j                  |       d{  7    w xY ww)1Receive a raw BSON message or raise socket.error.Nr   )r#   return_whenr$   Got opcode r  r   )r[   r%   r   r   get_deadliner   r   rg   r   ru   r   r`   r'   waitFIRST_COMPLETEDcancelrH   r/   r#   r  r   KeyErrorr   keysr   CancelledError)r[   r  r  r#   r   cancellation_task	read_tasktasksr;   r   taskr  r  unpack_replys                 r4   async_receive_messagerG    s     ii""G%%'~~''1HH h!1115#$6t$<=DII..33J@PQRI)*E%ll70G0G
 
g  	DKKM	,,w'''t9>..--%,,.MD',W5
  %%!"788%
 (  #!'N=;M;M;O:RS !!  	DKKM	ll5!!!	sg   CH		)F< 2F38F< +F	,>F< +	F 4F< ;H	<F< 	F< .F99F< <AH>H?HH	c                   t        j                         rt        j                         }n6| j                  j	                         }|rt        j                         |z   }nd}t        t        | d|            \  }}}}|||k7  rt        d|d|      |dk  rt        d|d      ||kD  rt        d|d|d      |d	k(  r5t        t        | d
|            \  }}}	t        t        | |dz
  |      |	      }
nt        | |dz
  |      }
	 t        |   } ||
      S # t        $ r% t        d|dt        j                               dw xY w)r8  Nr   r  r  r  r   r!  r"  r  r   r  r:  )r   r   r;  r[   r%   r   r   r#  r   r   r'  r   r   r?  r@  )r[   r  r  r   r#   r\   r$  r  r  r  r  rF  s               r4   receive_messagerI    s    %%'))&&(~~''1HH&4\$H5U&V#FA{G$"2;/PZ~ ^__|vj([\
 	
   vj )-03
 	
 $$>|DRSU]?^$_!M,tVb[(C]SD&2+x8$W-
 	  'N=3E3E3G2JK
	s   		D .E)r0   r   r1   r   rE   rF   )r0   r   r1   r   r2   r   rE   rF   )F)
r[   r   r\   r   r2   r   r]   Optional[bool]rE   rG   )r0   r   r1   r   ri   r   rE   rF   )
r[   r   r\   r   ri   r   r]   rJ  rE   rG   )r[   r   rE   rF   )r0   r   r\   r   rE   rG   )r[   r   r\   r   r2   r   rE   rG   )r[   r   r   r3  rE   rF   )r[   r   r\   r   r   r3  rE   rG   )r[   r   r1   r   rE   rF   )r[   r   r  r4  r  r   rE   Union[_OpReply, _OpMsg])r[   r   r  r4  r  r   rE   rK  )P__doc__
__future__r   r'   r   r   r/   structsysr   r   r   r   r   r   typingr	   r
   r   r   pymongor   r   pymongo._asyncio_taskr   pymongo.commonr   pymongo.compression_supportr   pymongo.errorsr   r   pymongo.messager   r   r   pymongo.socket_checkerr   sslr   r   r)   ImportErrorpymongo.pyopenssl_contextr   r   r   r   rQ   pymongo.ssl_supportpymongo.asynchronous.poolr   pymongo.synchronous.poolr   Structunpackr#  r'  rs   BlockingIOErrorrJ   r5   platformr,   ra   ro   ru   rz   rw   versionr   r   r   r   r   r   r   r6  rG  rI  r   rA   r4   <module>rc     s   - "      
  Y Y  ' - + 2 = ; ; 8'I  O 93w'..*V]]6299 %'?a+B`B`a 
!  <<7)/,)/38)/@Q)/	)/X V[00 #0+<0DR0	0l,38AR	, W\ #,=ES	6+&
(&25&&2


!$
,=

 	#++.B5p" "456 56+1 +>T& Tn3 -0
00 0 	0h JZ'
'"/'CF''s  I  OH s$   2
F, =F: ,F76F7:GG