ó
    ±vKgÛ  ã                   ó8   • S r SSKJr  SSKJr  Sr " S S5      rg)	a  
h2/windows
~~~~~~~~~~

Defines tools for managing HTTP/2 flow control windows.

The objects defined in this module are used to automatically manage HTTP/2
flow control windows. Specifically, they keep track of what the size of the
window is, how much data has been consumed from that window, and how much data
the user has already used. It then implements a basic algorithm that attempts
to manage the flow control window without user input, trying to ensure that it
does not emit too many WINDOW_UPDATE frames.
é    )Údivisioné   )ÚFlowControlErroriÿÿÿc                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚWindowManageré   z…
A basic HTTP/2 window manager.

:param max_window_size: The maximum size of the flow control window.
:type max_window_size: ``int``
c                 óB   • U[         ::  d   eXl        Xl        SU l        g )Nr   )ÚLARGEST_FLOW_CONTROL_WINDOWÚmax_window_sizeÚcurrent_window_sizeÚ_bytes_processed)Úselfr   s     ÚJ/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/h2/windows.pyÚ__init__ÚWindowManager.__init__   s%   € ØÔ"=Ó=Ð=Ð=Ø.ÔØ#2Ô Ø !ˆÕó    c                 ód   • U =R                   U-  sl         U R                   S:  a  [        S5      eg)a  
We have received a certain number of bytes from the remote peer. This
necessarily shrinks the flow control window!

:param size: The number of flow controlled bytes we received from the
    remote peer.
:type size: ``int``
:returns: Nothing.
:rtype: ``None``
r   z"Flow control window shrunk below 0N)r   r   ©r   Úsizes     r   Úwindow_consumedÚWindowManager.window_consumed%   s4   € ð 	× Ò  DÑ(Õ Ø×#Ñ# aÓ'Ü"Ð#GÓHÐHð (r   c                 óÒ   • U =R                   U-  sl         U R                   [        :”  a  [        S[        -  5      eU R                   U R                  :”  a  U R                   U l        gg)aí  
The flow control window has been incremented, either because of manual
flow control management or because of the user changing the flow
control settings. This can have the effect of increasing what we
consider to be the "maximum" flow control window size.

This does not increase our view of how many bytes have been processed,
only of how much space is in the window.

:param size: The increment to the flow control window we received.
:type size: ``int``
:returns: Nothing
:rtype: ``None``
z%Flow control window mustn't exceed %dN)r   r
   r   r   r   s     r   Úwindow_openedÚWindowManager.window_opened4   se   € ð 	× Ò  DÑ(Õ à×#Ñ#Ô&AÓAÜ"Ø7Ü+ñ,óð ð
 ×#Ñ# d×&:Ñ&:Ó:Ø#'×#;Ñ#;ˆDÕ ð ;r   c                 óL   • U =R                   U-  sl         U R                  5       $ )aî  
The application has informed us that it has processed a certain number
of bytes. This may cause us to want to emit a window update frame. If
we do want to emit a window update frame, this method will return the
number of bytes that we should increment the window by.

:param size: The number of flow controlled bytes that the application
    has processed.
:type size: ``int``
:returns: The number of bytes to increment the flow control window by,
    or ``None``.
:rtype: ``int`` or ``None``
)r   Ú_maybe_update_windowr   s     r   Úprocess_bytesÚWindowManager.process_bytesN   s$   € ð 	×Ò Ñ%ÕØ×(Ñ(Ó*Ð*r   c                 ó¨  • U R                   (       d  gU R                  U R                  -
  nSnU R                  S:X  aE  U R                   [        SU R                  S-  5      :”  a  [        U R                   U5      nSU l         O:U R                   U R                  S-  :¼  a  [        U R                   U5      nSU l         U =R                  U-  sl        U$ )aø  
Run the algorithm.

Our current algorithm can be described like this.

1. If no bytes have been processed, we immediately return 0. There is
   no meaningful way for us to hand space in the window back to the
   remote peer, so let's not even try.
2. If there is no space in the flow control window, and we have
   processed at least 1024 bytes (or 1/4 of the window, if the window
   is smaller), we will emit a window update frame. This is to avoid
   the risk of blocking a stream altogether.
3. If there is space in the flow control window, and we have processed
   at least 1/2 of the window worth of bytes, we will emit a window
   update frame. This is to minimise the number of window update frames
   we have to emit.

In a healthy system with large flow control windows, this will
irregularly emit WINDOW_UPDATE frames. This prevents us starving the
connection by emitting eleventy bajillion WINDOW_UPDATE frames,
especially in situations where the remote peer is sending a lot of very
small DATA frames.
Nr   i   é   é   )r   r   r   Úmin)r   Úmax_incrementÚ	increments      r   r   Ú"WindowManager._maybe_update_window_   s¿   € ð4 ×$×$Øà×-Ñ-°×0HÑ0HÑHˆØˆ	ð
 ×$Ñ$¨Ó)Ø×%Ñ%¬¨D°$×2FÑ2FÈ!Ñ2KÓ(LÓLÜ˜D×1Ñ1°=ÓAˆIØ$%ˆDÕ!Ø×"Ñ" t×';Ñ';¸qÑ'@ÓAÜ˜D×1Ñ1°=ÓAˆIØ$%ˆDÔ!à× Ò  IÑ-Õ ØÐr   )r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r   Ú__static_attributes__© r   r   r   r      s!   † ñò"òIò<ò4+õ",r   r   N)r*   Ú
__future__r   Ú
exceptionsr   r
   r   r,   r   r   Ú<module>r/      s&   ðñõ  å (ð (Ð ÷sò sr   