
    &th                         d Z ddlZddlmZ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 erddlmZ  ej        e          Z G d d	e	          ZdS )
zWorker module.    N)AnyCallableDictListTYPE_CHECKING)EventEmitter)ExecutionContextJSHandle)
debugError)
CDPSessionc            
            e Zd ZdZdddedeeee         gdf         deegdf         ddf
 fd	Z	d
e
ddfdZedefd            Zde
fdZdededefdZdededefdZ xZS )Workera  The Worker class represents a WebWorker.

    The events `workercreated` and `workerdestroyed` are emitted on the page
    object to signal the worker lifecycle.

    .. code::

        page.on('workercreated', lambda worker: print('Worker created:', worker.url))
    clientr   urlconsoleAPICalledNexceptionThrownreturnc                 b    t                                                        _        | _        j         _         j                                         _        dt          dt          fddt          dd f fd} j        	                    d|           	  j        
                    di            n,# t          $ r}t          t          |           Y d }~nd }~ww xY wdt          dd ffd} j        	                    d	|            j        	                    d
fd           d S )NremoteObjectr   c                     d S N )r   s    d/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/pyppeteer/worker.pyjsHandleFactoryz(Worker.__init__.<locals>.jsHandleFactory)   s    4    eventc                     dt           dt          ffdt          | d                                                  d S )Nr   r   c                 &    t          |           S r   )r
   )r   r   executionContexts    r   r   zKWorker.__init__.<locals>.onExecutionContentCreated.<locals>.jsHandleFactory/   s     0&,GGGr   context)r   r
   r	   _executionContextCallback)r   r   r   r   selfs    @r   onExecutionContentCreatedz2Worker.__init__.<locals>.onExecutionContentCreated,   sw    Hd Hx H H H H H H H  0i(/ ;  ;**+;<<<<<r   zRuntime.executionContextCreatedzRuntime.enablec                     g }|                      dg           D ] }|                     |                     ! | d         |           d S )Nargstype)getappend)r   r%   argr   r   s      r   onConsoleAPICalledz+Worker.__init__.<locals>.onConsoleAPICalled?   sa    #%Dyy,, 2 2OOC001111U6]D11111r   zRuntime.consoleAPICalledzRuntime.exceptionThrownc                 &     | d                   S )NexceptionDetailsr   )	exceptionr   s    r   <lambda>z!Worker.__init__.<locals>.<lambda>H   s    ooi8J.KLL r   )super__init___client_url_loopcreate_future_executionContextPromiser   r
   onsend	Exceptionr   logger)
r"   r   r   r   r   r#   er*   r   	__class__s
   `` ``   @r   r0   zWorker.__init__   s    		\
(,
(@(@(B(B%	$ 	8 	 	 	 		=T 	=d 	= 	= 	= 	= 	= 	= 	= 	= 	91	3 	3 	3	" L.3333 	" 	" 	"vq!!!!!!!!	"	2d 	2t 	2 	2 	2 	2 	2 	2 	2 	24FGGG%LLLL	
 	
 	
 	
 	
s   B: :
C#CC#valuec                 :    | j                             |           d S r   )r5   
set_result)r"   r<   s     r   r!   z Worker._executionContextCallbackK   s    %0077777r   c                     | j         S )zReturn URL.)r2   r"   s    r   r   z
Worker.urlN   s     yr   c                     K   | j          d{V S )zReturn ExecutionContext.N)r5   r@   s    r   r   zWorker.executionContextS   s!      22222222r   pageFunctionr%   c                 D   K    | j          d{V j        |g|R   d{V S )zEvaluate ``pageFunction`` with ``args``.

        Shortcut for ``(await worker.executionContext).evaluate(pageFunction, *args)``.
        N)r5   evaluater"   rB   r%   s      r   rD   zWorker.evaluateW   sc      
 DD9999999C!! ! ! ! ! ! ! ! ! 	!r   c                 D   K    | j          d{V j        |g|R   d{V S )zEvaluate ``pageFunction`` with ``args`` and return :class:`~pyppeteer.execution_context.JSHandle`.

        Shortcut for ``(await worker.executionContext).evaluateHandle(pageFunction, *args)``.
        N)r5   evaluateHandlerE   s      r   rG   zWorker.evaluateHandle_   sc      
 JD9999999I!! ! ! ! ! ! ! ! ! 	!r   )__name__
__module____qualname____doc__strr   r   r
   r   r0   r	   r!   propertyr   r   r   rD   rG   __classcell__)r;   s   @r   r   r      sF        *
| *
# *
#+S$x.,A4,G#H*
"*D64<"8*
 *
 *
 *
 *
 *
 *
X8/? 8D 8 8 8 8 S    X3(8 3 3 3 3!3 !s !s ! ! ! !! !S !X ! ! ! ! ! ! ! !r   r   )rK   loggingtypingr   r   r   r   r   pyeer   pyppeteer.execution_contextr	   r
   pyppeteer.helperr   pyppeteer.connectionr   	getLoggerrH   r9   r   r   r   r   <module>rV      s       ; ; ; ; ; ; ; ; ; ; ; ; ; ;       B B B B B B B B ' ' ' ' ' ' 0//////		8	$	$Q! Q! Q! Q! Q!\ Q! Q! Q! Q! Q!r   