
    Oj                         d dl Z d dlmZ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 d d	lmZ erd d
lmZ  G d d      Zy)    N)TYPE_CHECKINGAnyOptional)greenlet)
Connection)Error)MainGreenlet)create_remote_object)PipeTransport)
Playwright)AbstractChildWatcherc                   <    e Zd ZddZdefdZdefdZdeddfdZy)	PlaywrightContextManagerreturnNc                 6    |  |  d| _         d | _        d| _        y )NF)	_own_loop_watcher_exit_was_calledselfs    {/var/www/origus_pro_usr/data/www/origus.pro/core/.venv/lib/python3.12/site-packages/playwright/sync_api/_context_manager.py__init__z!PlaywrightContextManager.__init__    s    8< %    c                     	 t        j                          _         j                  j                         rt        d      d fd}t        |      }t        |t        t         j                         j                         _        t        j                          j                  j                  j!                  fd       |j#                          	 t%         j                  j                  j'                                _         j,                   j(                  _         j(                  S # t        $ r$ t        j                          _        d _        Y <w xY w# t*        $ r  j-                           w xY w)NTzjIt looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.c                  l     j                   j                   j                  j                                y N)_looprun_until_complete_connectionrun_as_syncr   s   r   greenlet_mainz9PlaywrightContextManager.__enter__.<locals>.greenlet_main6   s$    JJ))$*:*:*F*F*HIr   c                 $    j                         S r   )switch)_g_selfs    r   <lambda>z4PlaywrightContextManager.__enter__.<locals>.<lambda>E   s    v}} r   r   N)asyncioget_running_loopr   RuntimeErrornew_event_loopr   
is_runningr   r	   r   r
   r   r   r   
getcurrentplaywright_futureadd_done_callbackr#   SyncPlaywrightresult_playwrightBaseException__exit__stop)r   r!   dispatcher_fiberr%   s   `  @r   	__enter__z"PlaywrightContextManager.__enter__'   s>   	" 113DJ ::  "% 	J (6% $**%JJ	
 $$& 	**<<=VW!	-  2299; D !%M  	" //1DJ!DN	"D  	MMO	s   D- 2E -)EEE8c                 "    | j                         S r   )r7   r   s    r   startzPlaywrightContextManager.startR   s    ~~r   argsc                 6   | j                   ry d| _         | j                  j                          | j                  r| j                  j	                          | j
                  rt        j                  | j                        }|D cg c]&  }|j                         r|j                         r%|( c}D ]  }|j                           | j                  j                  | j                  j                                | j                  j	                          y y c c}w )NT)r   r   	stop_syncr   closer   r(   	all_tasksr   done	cancelledcancelr   shutdown_asyncgens)r   r:   tasksts       r   r4   z!PlaywrightContextManager.__exit__U   s       $""$==MM!>>%%djj1E!&JAqvvx1;;=aJ 
JJ))$***G*G*IJJJ Js   DD+Dr'   )	__name__
__module____qualname__r   r0   r7   r9   r   r4    r   r   r   r      s3    &) > ) V ~  c d r   r   )r(   typingr   r   r   r   playwright._impl._connectionr   playwright._impl._errorsr   playwright._impl._greenletsr	    playwright._impl._object_factoryr
   playwright._impl._transportr   playwright.sync_api._generatedr   r0   asyncio.unix_eventsr   r   rH   r   r   <module>rQ      s7     / /  3 * 4 A 5 G8B Br   