o
    LDi;                     @   s   d dl Z d dlmZmZmZmZ d dl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 d d	lmZ d dlmZ erJd d
lmZ G dd dZdS )    N)TYPE_CHECKINGAnyOptionalcast)greenlet)ChannelOwner
Connection)Error)MainGreenlet)create_remote_object)
Playwright)PipeTransport)AbstractChildWatcherc                   @   sD   e Zd ZdddZdefddZdefddZd	eddfd
dZdS )PlaywrightContextManagerreturnNc                 C   s   |  |  d| _ d | _d| _d S )NF)	_own_loop_watcher_exit_was_calledself r   p/var/www/www-root/data/www/77.83.87.30/venv/lib/python3.10/site-packages/playwright/sync_api/_context_manager.py__init__!   s
   
z!PlaywrightContextManager.__init__c                    s   zt  _W n ty   t  _d_Y nw j r"tdd
fdd}t|}t	|t
tjj_t  dtdd f fdd}jd	| |  j}j|_|S )NTzjIt looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.r   c                      s    j  j  d S N)_looprun_until_complete_connectionrun_as_syncr   r   r   r   greenlet_main7   s   z9PlaywrightContextManager.__enter__.<locals>.greenlet_mainchannel_ownerc                    s    t t| }t|_   d S r   )r   r   SyncPlaywright_playwrightswitch)r   playwright_implg_selfr   r   r   callback_wrapperE   s   

z<PlaywrightContextManager.__enter__.<locals>.callback_wrapperr   r   N)asyncioget_running_loopr   RuntimeErrornew_event_loopr   
is_runningr	   r
   r   r   r   r   r   
getcurrentr   call_on_object_with_known_namer"   r!   __exit__stop)r   r   dispatcher_fiberr&   
playwrightr   r$   r   	__enter__(   s2   


z"PlaywrightContextManager.__enter__c                 C   s   |   S r   )r3   r   r   r   r   startS   s   zPlaywrightContextManager.startargsc                 G   s|   | j rd S d| _ | j  | jr| j  | jr<t| j}dd |D D ]}|	  q%| j
| j  | j  d S d S )NTc                 S   s    g | ]}|  s| s|qS r   )done	cancelled).0tr   r   r   
<listcomp>_   s     z5PlaywrightContextManager.__exit__.<locals>.<listcomp>)r   r   	stop_syncr   closer   r(   	all_tasksr   cancelr   shutdown_asyncgens)r   r5   tasksr9   r   r   r   r/   V   s   


z!PlaywrightContextManager.__exit__r'   )	__name__
__module____qualname__r   r    r3   r4   r   r/   r   r   r   r   r       s
    
+r   )r(   typingr   r   r   r   r   playwright._impl._connectionr   r   playwright._impl._errorsr	   playwright._impl._greenletsr
    playwright._impl._object_factoryr   playwright._impl._playwrightr   playwright._impl._transportr   playwright.sync_api._generatedr    asyncio.unix_eventsr   r   r   r   r   r   <module>   s   