ó
    Ð]jö&  ã                  óÈ  • S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	J
r
  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJr  SSKJrJrJrJr  SSKJrJ r   \	(       a  SSKJ!r!  SSK"J#r#  SSK$J%r%  \RL                  RN                  r'\RL                  RP                  r(\RR                  RT                  r* " S S\S   5      r+ " S S\5      r, " S S\,5      r- " S S\-5      r.g)z7
Objects to support the COPY protocol (async version).
é    )Úannotations)ÚABCÚabstractmethod)ÚTracebackType)ÚTYPE_CHECKINGÚAny)ÚAsyncIteratorÚSequenceé   )Úerrors)Úpq)ÚSelf)ÚAQueueÚAWorkerÚagatherÚaspawn)ÚMAX_BUFFER_SIZEÚPREFER_FLUSHÚ
QUEUE_SIZEÚBaseCopy)Úcopy_endÚcopy_to)ÚBuffer)ÚAsyncCursor)ÚAsyncConnectionc                  ó¾   ^ • \ rS rSr% SrSrS\S'   SSS.     SU 4S jjjrSS	 jr        SS
 jrSS jr	SS jr
SS jrSS jrSS jrSS jrSS jrSrU =r$ )Ú	AsyncCopyé    aB  Manage an asynchronous :sql:`COPY` operation.

:param cursor: the cursor where the operation is performed.
:param binary: if `!True`, write binary format.
:param writer: the object to write to destination. If not specified, write
    to the `!cursor` connection.

Choosing `!binary` is not necessary if the cursor has executed a
:sql:`COPY` operation, because the operation result describes the format
too. The parameter is useful when a `!Copy` object is created manually and
no operation is performed on the cursor, such as when using ``writer=``\
`~psycopg.copy.FileWriter`.
ÚpsycopgÚAsyncWriterÚwriterN)Úbinaryr!   c               ór   >• [         TU ]  XS9  U(       d  [        U5      nX0l        UR                  U l        g )N)r"   )ÚsuperÚ__init__ÚAsyncLibpqWriterr!   ÚwriteÚ_write)ÚselfÚcursorr"   r!   Ú	__class__s       €ÚP/home/mande/repo/quber/.venv/lib/python3.13/site-packages/psycopg/_copy_async.pyr%   ÚAsyncCopy.__init__3   s2   ø€ ô 	‰Ñ˜ÐÑ/ÞÜ% fÓ-ˆFàŒØ—l‘lˆ�ó    c              ƒ  ó.   #   • U R                  5         U $ 7f©N)Ú_enter©r)   s    r,   Ú
__aenter__ÚAsyncCopy.__aenter__A   s   é € Ø�‰ŒØˆùs   ‚c              ƒ  óB   #   • U R                  U5      I S h  v•N   g  N7fr0   )Úfinish)r)   Úexc_typeÚexc_valÚexc_tbs       r,   Ú	__aexit__ÚAsyncCopy.__aexit__E   s   é € ð �k‰k˜'Ó"×"Ó"ùs   ‚—˜c               ó    #   • U R                  5       I Sh  v•N =n(       a'  U7v •  U R                  5       I Sh  v•N =n(       a  M&  gg N3 N7f)z5Implement block-by-block iteration on :sql:`COPY TO`.N)Úread©r)   Údatas     r,   Ú	__aiter__ÚAsyncCopy.__aiter__O   s:   é € à!ŸY™Y›[×(Ð)ˆdÕ)Ø‹Jð "ŸY™Y›[×(Ð)ˆd×)Ñ)Ó(ùs%   ‚A–A
—#AºA»AÁAÁAc              ƒ  óp   #   • U R                   R                  U R                  5       5      I Sh  v•N $  N7f)zk
Read an unparsed row after a :sql:`COPY TO` operation.

Return an empty string when the data is finished.
N)Ú
connectionÚwaitÚ	_read_genr2   s    r,   r=   ÚAsyncCopy.readT   s)   é € ð —_‘_×)Ñ)¨$¯.©.Ó*:Ó;×;Ð;Ñ;ùó   ‚-6¯4°6c               ó�   #   • U R                  5       I Sh  v•N =nb#  U7v •  U R                  5       I Sh  v•N =nb  M"  gg N+ N7f)zÉ
Iterate on the result of a :sql:`COPY TO` operation record by record.

Note that the records returned will be tuples of unparsed strings or
bytes, unless data types are specified using `set_types()`.
N)Úread_row)r)   Úrecords     r,   ÚrowsÚAsyncCopy.rows\   s9   é € ð !%§¡£×/Ð0ˆvÑ=Ø‹Lð !%§¡£×/Ð0ˆvÕ=Ó/ùs%   ‚A–A—A¶A·AÁ AÁAc              ƒ  óp   #   • U R                   R                  U R                  5       5      I Sh  v•N $  N7f)z÷
Read a parsed row of data from a table after a :sql:`COPY TO` operation.

Return `!None` when the data is finished.

Note that the records returned will be tuples of unparsed strings or
bytes, unless data types are specified using `set_types()`.
N)rC   rD   Ú_read_row_genr2   s    r,   rI   ÚAsyncCopy.read_rowf   s+   é € ð —_‘_×)Ñ)¨$×*<Ñ*<Ó*>Ó?×?Ð?Ñ?ùrG   c              ƒ  óˆ   #   • U R                   R                  U5      =n(       a  U R                  U5      I Sh  v•N   gg N7f)z¼
Write a block of data to a table after a :sql:`COPY FROM` operation.

If the :sql:`COPY` is in binary format `!buffer` must be `!bytes`. In
text mode it can be either `!bytes` or `!str`.
N)Ú	formatterr'   r(   )r)   Úbufferr?   s      r,   r'   ÚAsyncCopy.writeq   s;   é € ð —>‘>×'Ñ'¨Ó/Ð/ˆ4Õ/Ø—+‘+˜dÓ#×#Ñ#ð 0Ù#ùó   ‚7A¹A ºAc              ƒ  óˆ   #   • U R                   R                  U5      =n(       a  U R                  U5      I Sh  v•N   gg N7f)z=Write a record to a table after a :sql:`COPY FROM` operation.N)rQ   Ú	write_rowr(   )r)   Úrowr?   s      r,   rV   ÚAsyncCopy.write_row{   s9   é € à—>‘>×+Ñ+¨CÓ0Ð0ˆ4Õ0Ø—+‘+˜dÓ#×#Ñ#ð 1Ù#ùrT   c              ƒ  ó  #   • U R                   [        :X  al  U(       d:  U R                  R                  5       =n(       a  U R	                  U5      I Sh  v•N   U R
                  R                  U5      I Sh  v•N   SU l        gU(       d  gU R                  R                  [        :w  a  gU R                  R                  5       I Sh  v•N   U R                  R                  U R                  5       5      I Sh  v•N   g Nª N‰ N: N7f)zõTerminate the copy operation and free the resources allocated.

You shouldn't need to call this function yourself: it is usually called
by exit. It is available if, despite what is documented, you end up
using the `Copy` object outside a block.
NT)Ú
_directionÚCOPY_INrQ   Úendr(   r!   r6   Ú	_finishedÚ_pgconnÚtransaction_statusÚACTIVErC   Ú_try_cancelrD   Ú_end_copy_out_gen)r)   Úexcr?   s      r,   r6   ÚAsyncCopy.finish€   sÅ   é € ð �?‰?œgÓ%ÞØŸ>™>×-Ñ-Ó/Ð/�4Õ/ØŸ+™+ dÓ+×+Ð+Ø—+‘+×$Ñ$ SÓ)×)Ð)Ø!ˆD�NæØà�|‰|×.Ñ.´&Ó8ð ð —/‘/×-Ñ-Ó/×/Ð/Ø—/‘/×&Ñ& t×'=Ñ'=Ó'?Ó@×@Ñ@ñ# ,Ù)ñ 0Ù@ùsI   ‚ADÁC>Á"DÁ6D Á7ADÃDÃ0DÃ8DÃ9DÄ DÄDÄD)r]   r(   r!   )r*   úAsyncCursor[Any]r"   zbool | Noner!   zAsyncWriter | None)Úreturnr   )r7   ztype[BaseException] | Noner8   úBaseException | Noner9   zTracebackType | Nonerf   ÚNone)rf   zAsyncIterator[Buffer])rf   r   )rf   zAsyncIterator[tuple[Any, ...]])rf   ztuple[Any, ...] | None)rR   zBuffer | strrf   rh   )rW   zSequence[Any]rf   rh   ©rc   rg   rf   rh   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r%   r3   r:   r@   r=   rK   rI   r'   rV   r6   Ú__static_attributes__Ú__classcell__©r+   s   @r,   r   r       sž   ø‡ ñð €JàÓð #Ø%)ñ#à ð#ð ð	#ð
 #÷#ð #ôð#à,ð#ð &ð#ð %ð	#ð
 
ô#ôô
<ôô	@ô$ô$÷
Aò Ar.   r   zAsyncConnection[Any]c                  ó:   • \ rS rSrSr\SS j5       rSS	S jjrSrg)
r    éž   z?
A class to write copy data somewhere (for async connections).
c              ƒ  ó   #   • g7f)zWrite some data to destination.N© r>   s     r,   r'   ÚAsyncWriter.write£   s
   é € ð 	ùó   ‚Nc              ƒ  ó   #   • g7f)zq
Called when write operations are finished.

If operations finished with an error, it will be passed to ``exc``.
Nrv   )r)   rc   s     r,   r6   ÚAsyncWriter.finish¨   s
   é € ð 	ùrx   rv   ©r?   r   rf   rh   r0   ri   )	rj   rk   rl   rm   rn   r   r'   r6   rp   rv   r.   r,   r    r    ž   s%   † ñð óó ð÷ñ r.   r    c                  ó>   • \ rS rSrSrSrS	S jrS
S jrSSS jjrSrg)r&   é±   z=
An `AsyncWriter` to write copy data to a Postgres database.
úpsycopg.copyc                óh   • Xl         UR                  U l        U R                  R                  U l        g r0   )r*   rC   Úpgconnr^   )r)   r*   s     r,   r%   ÚAsyncLibpqWriter.__init__¸   s%   € ØŒØ ×+Ñ+ˆŒØ—‘×-Ñ-ˆ�r.   c           
   ƒ  óx  #   • [        U5      [        ::  a;  U R                  R                  [	        U R
                  U[        S95      I S h  v•N   g [        S[        U5      [        5       HF  nU R                  R                  [	        U R
                  XU[        -    [        S95      I S h  v•N   MH     g  Nj N7f)N©Úflushr   )Úlenr   rC   rD   r   r^   r   Úrange©r)   r?   Úis      r,   r'   ÚAsyncLibpqWriter.write½   s•   é € Üˆt‹9œÓ'ð —/‘/×&Ñ&¤w¨t¯|©|¸TÌÑ'VÓW×WÑWô ˜1œc $›i¬Ö9�Ø—o‘o×*Ñ*ÜØŸ™ d¨q´?Ñ/BÐ&CÌ<ñó÷ ò ò :ñ	 Xñ
ùs%   ‚A	B:ÁB6ÁA B:Â,B8Â-
B:Â8B:Nc              ƒ  ó~  #   • U(       aB  S[        U5      R                   SU 3nUR                  U R                  R                  S5      nOS n U R
                  R                  [        U R                  U5      5      I S h  v•N nU/U R                  l	        g  N! [        R                   a    U(       d  e  g f = f7f)Nzerror from Python: z - Úreplace)Útyperl   Úencoder^   Ú	_encodingrC   rD   r   r*   Ú_resultsÚeÚQueryCanceled)r)   rc   ÚmsgÚbmsgÚress        r,   r6   ÚAsyncLibpqWriter.finishÌ   s    é € æØ'¬¨S«	×(>Ñ(>Ð'?¸sÀ3À%ÐHˆCØ—:‘:˜dŸl™l×4Ñ4°iÓ@‰DàˆDð		)ØŸ™×,Ñ,¬X°d·l±lÀDÓ-IÓJ×JˆCð %( 5ˆD�K‰KÕ ñ Køô �‰ó 	ÞØñ ð	üs<   ‚AB=Á2B ÂBÂB ÂB=ÂB ÂB:Â7B=Â9B:Â:B=)r^   rC   r*   ©r*   re   r{   r0   ri   )	rj   rk   rl   rm   rn   r%   r'   r6   rp   rv   r.   r,   r&   r&   ±   s"   † ñð  €Jô.ô
÷)ñ )r.   r&   c                  ó\   ^ • \ rS rSrSrSrS	U 4S jjrS
S jrSS jrSSU 4S jjjrSr	U =r
$ )ÚAsyncQueuedLibpqWriteréà   zÞ
`AsyncWriter` using a buffer to queue data to write.

`write()` returns immediately, so that the main thread can be CPU-bound
formatting messages, while a worker thread can be IO-bound waiting to write
on the connection.
r~   c                ód   >• [         TU ]  U5        [        [        S9U l        S U l        S U l        g )N)Úmaxsize)r$   r%   r   r   Ú_queueÚ_workerÚ_worker_error)r)   r*   r+   s     €r,   r%   ÚAsyncQueuedLibpqWriter.__init__ë   s+   ø€ Ü‰Ñ˜Ô ä&,´ZÑ&@ˆŒØ'+ˆŒØ37ˆÕr.   c              ƒ  ór  #   •  U R                   R                  5       I Sh  v•N =n(       af  U R                  R                  [	        U R
                  U[        S95      I Sh  v•N   U R                   R                  5       I Sh  v•N =n(       a  Me  gg Nr N3 N! [         a  nX l         SnAgSnAff = f7f)zÅPush data to the server when available from the copy queue.

Terminate reading when the queue receives a false-y value, or in case
of error.

The function is designed to be run in a separate task.
Nrƒ   )	rœ   ÚgetrC   rD   r   r^   r   ÚBaseExceptionrž   )r)   r?   Úexs      r,   ÚworkerÚAsyncQueuedLibpqWriter.workerò   s”   é € ð	$Ø!%§¡§¡Ó!2×2Ð3�$Õ3Ø—o‘o×*Ñ*Ü˜DŸL™L¨$´lÑCó÷ ð ð "&§¡§¡Ó!2×2Ð3�$×3Ñ3Ñ2ññ 3øô ó 	$à!#×Ñûð	$üsc   ‚B7„B ¡B¢A B Á"BÁ#!B ÂBÂB ÂB7ÂB ÂB ÂB Â
B4Â$B/Â*B7Â/B4Â4B7c              ƒ  ó¬  #   • U R                   (       d  [        U R                  5      U l         U R                  (       a  U R                  e[	        U5      [
        ::  a$  U R                  R                  U5      I S h  v•N   g [        S[	        U5      [
        5       H/  nU R                  R                  XU[
        -    5      I S h  v•N   M1     g  NS N7f)Nr   )	r�   r   r¤   rž   r…   r   rœ   Úputr†   r‡   s      r,   r'   ÚAsyncQueuedLibpqWriter.write  s›   é € Ø�|�|ä! $§+¡+Ó.ˆDŒLð ××Ø×$Ñ$Ð$äˆt‹9œÓ'ð —+‘+—/‘/ $Ó'×'Ñ'ô ˜1œc $›i¬Ö9�Ø—k‘k—o‘o d¨q´?Ñ/BÐ&CÓD×DÒDò :ñ	 (ñ
 Eùs%   ‚A:CÁ<CÁ=A	CÃCÃ
CÃCc              ƒ  ó2  >#   • U R                   R                  S5      I S h  v•N   U R                  (       a$  [        U R                  5      I S h  v•N   S U l        U R                  (       a  U R                  e[
        TU ]  U5      I S h  v•N   g  Nn NB N	7f)Nr.   )rœ   r§   r�   r   rž   r$   r6   )r)   rc   r+   s     €r,   r6   ÚAsyncQueuedLibpqWriter.finish  st   øé € Ø�k‰k�o‰o˜cÓ"×"Ð"à�<�<Ü˜$Ÿ,™,Ó'×'Ð'ØˆDŒLð ××Ø×$Ñ$Ð$ä‰g‰n˜SÓ!×!Ñ!ñ 	#ñ (ñ 	"ùs3   ƒB¢B£-BÁBÁ:BÂBÂBÂBÂB)rœ   r�   rž   r–   )rf   rh   r{   r0   ri   )rj   rk   rl   rm   rn   r%   r¤   r'   r6   rp   rq   rr   s   @r,   r˜   r˜   à   s)   ø† ñð  €J÷8ô$ô"E÷&"÷ "r.   r˜   N)/rn   Ú
__future__r   Úabcr   r   Útypesr   Útypingr   r   Úcollections.abcr	   r
   Ú r   r�   r   Ú_compatr   Ú_acompatr   r   r   r   Ú
_copy_baser   r   r   r   Ú
generatorsr   r   r   Úcursor_asyncr   Úconnection_asyncr   Ú
ExecStatusr[   ÚCOPY_OUTÚTransactionStatusr`   r   r    r&   r˜   rv   r.   r,   Ú<module>rº      s­   ðñõ #ç #Ý ß %ß 3å Ý Ý ß 6Ó 6ß KÓ Kß )æÝÝ)Ý1à
�-‰-×
Ñ
€Ø�=‰=×!Ñ!€à	×	Ñ	×	$Ñ	$€ô{A�Ð/Ñ0ô {Aô|�#ô ô&,)�{ô ,)ô^A"Ð-õ A"r.   