ó
     ·Úi  ã                   ó$   • S r SSKr " S S5      rg)zt
Async version of gunicorn/http/unreader.py for ASGI workers.

Provides async reading with pushback buffer support.
é    Nc                   óP   • \ rS rSrSrSS jrS rS rS rSS jr	S	 r
S
 rS rSrg)ÚAsyncUnreaderé   a$  Async socket reader with pushback buffer support.

This class wraps an asyncio StreamReader and provides the ability
to "unread" data back into a buffer for re-parsing.

Performance optimization: Reuses BytesIO buffer with truncate/seek
instead of creating new objects to reduce GC pressure.
c                 ó^   • Xl         [        R                  " 5       U l        X l        SU l        g)z}Initialize the async unreader.

Args:
    reader: asyncio.StreamReader instance
    max_chunk: Maximum bytes to read at once
r   N)ÚreaderÚioÚBytesIOÚbufÚ	max_chunkÚ
_buf_start)Úselfr   r   s      ÚH/var/www/ias/venv/lib/python3.13/site-packages/gunicorn/asgi/unreader.pyÚ__init__ÚAsyncUnreader.__init__   s"   € ð ŒÜ—:’:“<ˆŒØ"ŒØˆó    c                 ó~   • U R                   R                  S5        U R                   R                  S5        SU l        g)z7Reset buffer for reuse instead of creating new BytesIO.r   N)r
   ÚseekÚtruncater   ©r   s    r   Ú_reset_bufferÚAsyncUnreader._reset_buffer$   s+   € à‰‰aÔØ‰×Ñ˜!ÔØˆr   c                 ó¤   • U R                   R                  U R                  5        U R                   R                  5       nU R	                  5         U$ )z'Get all buffered data and reset buffer.)r
   r   r   Úreadr   )r   Údatas     r   Ú_get_buffered_dataÚ AsyncUnreader._get_buffered_data*   s6   € à‰‰d—o‘oÔ&Øx‰x}‰}‹ˆØ×ÑÔØˆr   c                 ór   • U R                   R                  S[        R                  5      nXR                  -
  $ )zGet size of buffered data.r   )r
   r   r   ÚSEEK_ENDr   )r   Úends     r   Ú_buffer_sizeÚAsyncUnreader._buffer_size1   s'   € àh‰hm‰m˜AœrŸ{™{Ó+ˆØ—_‘_Ñ$Ð$r   Nc              ƒ   óŽ  #   • Ub   [        U[        5      (       d  [        S5      eUb  US:X  a  gUS:  a  SnU R                  5       nUc  US:”  a  U R	                  5       $ Uc  U R                  5       I Sh  v•N nU$ X!:  a‰  U R                  5       I Sh  v•N nU(       d  U R	                  5       $ U R                  R                  S[        R                  5        U R                  R                  U5        U[        U5      -  nX!:  a  M‰  U R                  R                  U R                  5        U R                  R                  U5      nU =R                  U-  sl        U R                  S:”  aL  U R                  R                  5       nU R                  5         U(       a  U R                  R                  U5        U$  GNH GN,7f)zÛRead data from the stream, using buffered data first.

Args:
    size: Number of bytes to read. If None, returns all buffered
          data or reads a single chunk.

Returns:
    bytes: Data read from buffer or stream
Nz&size parameter must be an int or long.r   r   é    )Ú
isinstanceÚintÚ	TypeErrorr    r   Ú_read_chunkr
   r   r   r   ÚwriteÚlenr   r   r   )r   ÚsizeÚbuf_sizeÚchunkr   Ú	remainings         r   r   ÚAsyncUnreader.read6   sn  é € ð Ñ¤J¨t´S×$9Ñ$9ÜÐDÓEÐEàÑØq‹yØØa‹xØà×$Ñ$Ó&ˆð ‰<˜H q›LØ×*Ñ*Ó,Ð,Ø‰<Ø×*Ñ*Ó,×,ˆEØˆLð ‹oØ×*Ñ*Ó,×,ˆEÞØ×.Ñ.Ó0Ð0ØH‰HM‰M˜!œRŸ[™[Ô)ØH‰HN‰N˜5Ô!Øœ˜E›
Ñ"ˆHð oð 	‰‰d—o‘oÔ&Øx‰x}‰}˜TÓ"ˆð 	Š˜4Ñð ?‰?˜TÓ!ØŸ™Ÿ™›ˆIØ×ÑÔ ÞØ—‘—‘˜yÔ)àˆò5 -ò
 -ùs,   ‚A5GÁ7F?Á8GÂGÂA3GÄB4GÇGc              ƒ   óŠ   #   •  U R                   R                  U R                  5      I Sh  v•N $  N! [         a     gf = f7f)z0Read a chunk of data from the underlying stream.Nr   )r   r   r   Ú	Exceptionr   s    r   r'   ÚAsyncUnreader._read_chunkk   s:   é € ð	ØŸ™×)Ñ)¨$¯.©.Ó9×9Ð9Ñ9øÜó 	Ùð	üs/   ‚A„(3 ¬1­3 °A±3 ³
A ½A¿A Á Ac                 ó.  • U(       aŽ  U R                   R                  U R                  5        U R                   R                  5       nU R	                  5         U R                   R                  U5        U(       a  U R                   R                  U5        ggg)z•Push data back into the buffer for re-reading.

Args:
    data: bytes to push back

Note: This prepends data to the buffer so it will be read first.
N)r
   r   r   r   r   r(   )r   r   Úexistings      r   ÚunreadÚAsyncUnreader.unreadr   se   € ö àH‰HM‰M˜$Ÿ/™/Ô*Ø—x‘x—}‘}“ˆHð ×ÑÔ ØH‰HN‰N˜4Ô ÞØ—‘—‘˜xÕ(ð ð r   c                 ó(   • U R                  5       S:„  $ )z-Check if there's data in the pushback buffer.r   )r    r   s    r   Úhas_buffered_dataÚAsyncUnreader.has_buffered_data…   s   € à× Ñ Ó" QÑ&Ð&r   )r   r
   r   r   )r#   )N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r    r   r'   r4   r7   Ú__static_attributes__© r   r   r   r      s0   † ñô
òòò%ô
3òjò)õ&'r   r   )r=   r   r   r?   r   r   Ú<module>r@      s   ðñ
ó 
÷y'ò y'r   