
    Mh]                        U d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZmZmZmZmZ ddlmZ d	d
gZ edeedf                   Zedd            ZdZded<    ed          Z G d d          ZefddZdS )z&
Implementation for async generators.
    )annotations)get_running_loop)asynccontextmanager)EmptyFullQueue)AnyAsyncGeneratorCallableIterableTypeVar   )run_in_executor_with_contextaclosinggenerator_to_async_generator_T_GeneratorN)boundthingreturn"AsyncGenerator[_T_Generator, None]c                  K   	 | W V  |                                   d{V  dS # |                                   d{V  w xY w)z1Similar to `contextlib.aclosing`, in Python 3.10.N)aclose)r   s    h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/eventloop/async_generator.pyr   r      sb      
llnnellnns	   % Ai  intDEFAULT_BUFFER_SIZE_Tc                      e Zd ZdS )_DoneN)__name__
__module____qualname__     r   r   r   1   s        Dr#   r   get_iterableCallable[[], Iterable[_T]]buffer_sizeAsyncGenerator[_T, None]c               |   K   dt          |          t                      }d fd}t          |          }	 	 	                                 }n1# t          $ r$ |                    dj                   d{V }Y nw xY wt          |t                    rn|W V  c	 d| d{V  dS # d| d{V  w xY w)	a]  
    Turn a generator or iterable into an async generator.

    This works by running the generator in a background thread.

    :param get_iterable: Function that returns a generator or iterable when
        called.
    :param buffer_size: Size of the queue between the async consumer and the
        synchronous generator that produces items.
    F)maxsizer   Nonec                 p   	              D ]} r= 	 	                      t                      d           dS # t          $ r rY dS Y 8w xY w	 	                      | d           nP# t          $ rC r>Y  	 	                      t                      d           dS # t          $ r rY dS Y 8w xY wY fw xY w	 	 	                      t                      d           dS # t          $ r rY dS Y 8w xY w# 	 	                      t                      d           n# t          $ r
 rY  Y dS Y 9w xY ww xY w)z~
        Consume the generator in background thread.
        When items are received, they'll be pushed to the queue.
        Tr   )timeoutN)putr   r   )itemr$   qquittings    r   runnerz,generator_to_async_generator.<locals>.runnerH   s   
	$    EE%''1E--- E     HdA...    ! ! !# #"FEE%''1E--- E     H !!
 "EE%''1E--- E     HEE%''1E---      H   s   C6 #9 A
AC6 A('C6 (B54C6 8#B B/.B/2C6 4B55C6 <#C! !C32C36D59#DD5D1)D5.D50D11D5TN)r   r*   )	r   r   r   
get_nowaitr   run_in_executorget
isinstancer   )r$   r&   loopr1   runner_fr.   r/   r0   s   `     @@r   r   r   5   s1      H 555AD       D ,F33H	?||~~ ? ? ?!11$>>>>>>>>?$&& 



	   	  s/   B/  A B/ +B B/ BB/ /B;)r   r   r   r   )r$   r%   r&   r   r   r'   )__doc__
__future__r   asyncior   
contextlibr   queuer   r   r   typingr	   r
   r   r   r   utilsr   __all__r   r   r   __annotations__r   r   r   r"   r#   r   <module>rA      sm     # " " " " " $ $ $ $ $ $ * * * * * * $ $ $ $ $ $ $ $ $ $ C C C C C C C C C C C C C C / / / / / / "
 w~^CI-FGGG    *       WT]]	 	 	 	 	 	 	 	 +H H H H H H Hr#   