a
    >Šxd  ã                   @   s~   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 e¡ZG dd	„ d	e	ƒZdS )
zWorker module.é    N)ÚAnyÚCallableÚDictÚListÚTYPE_CHECKING)ÚEventEmitter)ÚExecutionContextÚJSHandle)Ú
debugError)Ú
CDPSessionc                       sœ   e Zd ZdZdeeeee gdf eegdf ddœ‡ fdd„Z	e
ddœdd	„Zeed
œdd„ƒZe
d
œdd„Zeeedœdd„Zeeedœdd„Z‡  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))
    r   N)ÚclientÚurlÚconsoleAPICalledÚexceptionThrownÚreturnc              
      sà   t ƒ  ¡  ˆ ˆ_|ˆ_ˆ jˆ_ˆj ¡ ˆ_ttdœdd„‰td dœ‡ ‡‡fdd„}ˆj 	d|¡ zˆj 
di ¡ W n. ty  } ztt|ƒ W Y d }~n
d }~0 0 td dœ‡‡fd	d
„}ˆj 	d|¡ ˆj 	d‡fdd„¡ d S )N©ÚremoteObjectr   c                 S   s   d S ©N© ©r   r   r   úH/var/www/html/Ranjet/env/lib/python3.9/site-packages/pyppeteer/worker.pyÚjsHandleFactory)   s    z(Worker.__init__.<locals>.jsHandleFactory)Úeventr   c                    s4   t tdœ‡‡ fdd„‰tˆ| d ˆƒ‰ ˆ ˆ ¡ d S )Nr   c                    s   t ˆˆ | ƒS r   )r	   r   )r   ÚexecutionContextr   r   r   /   s    zKWorker.__init__.<locals>.onExecutionContentCreated.<locals>.jsHandleFactoryÚcontext)r   r	   r   Ú_executionContextCallback)r   )r   r   Úself)r   r   ÚonExecutionContentCreated,   s
    
ÿz2Worker.__init__.<locals>.onExecutionContentCreatedzRuntime.executionContextCreatedzRuntime.enablec                    s6   g }|   dg ¡D ]}| ˆ|ƒ¡ qˆ | d |ƒ d S )NÚargsÚtype)ÚgetÚappend)r   r   Úarg)r   r   r   r   ÚonConsoleAPICalled?   s    z+Worker.__init__.<locals>.onConsoleAPICalledzRuntime.consoleAPICalledzRuntime.exceptionThrownc                    s   ˆ | d ƒS )NZexceptionDetailsr   )Ú	exception)r   r   r   Ú<lambda>H   ó    z!Worker.__init__.<locals>.<lambda>)ÚsuperÚ__init__Z_clientÚ_urlÚ_loopÚcreate_futureÚ_executionContextPromiser   r	   ÚonÚsendÚ	Exceptionr
   Úlogger)r   r   r   r   r   r   Úer$   ©Ú	__class__)r   r   r   r   r   r   r)      s(    

ÿ 
þzWorker.__init__)Úvaluer   c                 C   s   | j  |¡ d S r   )r-   Ú
set_result)r   r5   r   r   r   r   K   s    z Worker._executionContextCallback)r   c                 C   s   | j S )zReturn URL.)r*   ©r   r   r   r   r   N   s    z
Worker.urlc                 Ã   s   | j I dH S )zReturn ExecutionContext.N)r-   r7   r   r   r   r   S   s    zWorker.executionContext)ÚpageFunctionr   r   c                 Ç   s    | j I dH j|g|¢R Ž I dH S )zŠEvaluate ``pageFunction`` with ``args``.

        Shortcut for ``(await worker.executionContext).evaluate(pageFunction, *args)``.
        N)r-   Úevaluate©r   r8   r   r   r   r   r9   W   s
    ÿÿzWorker.evaluatec                 Ç   s    | j I dH j|g|¢R Ž I dH S )zÊEvaluate ``pageFunction`` with ``args`` and return :class:`~pyppeteer.execution_context.JSHandle`.

        Shortcut for ``(await worker.executionContext).evaluateHandle(pageFunction, *args)``.
        N)r-   ÚevaluateHandler:   r   r   r   r;   _   s
    ÿÿzWorker.evaluateHandle)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r	   r   r)   r   r   Úpropertyr   r   r   r9   r;   Ú__classcell__r   r   r3   r   r      s   
ý,r   )r?   ÚloggingÚtypingr   r   r   r   r   Zpyeer   Zpyppeteer.execution_contextr   r	   Zpyppeteer.helperr
   Zpyppeteer.connectionr   Ú	getLoggerr<   r1   r   r   r   r   r   Ú<module>   s   
