
    &thY$                     "   d Z ddlZddlZ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 ddlmZmZ ddlmZ erddlmZ dd	lmZ  ej        e          Zd
Z ej        dej                  Z G d de          Z G d de          Zde ddfdZ!dS )zExecution Context Module.    N)AnyDictOptionalTYPE_CHECKING)helper)
CDPSession)ElementHandleErrorNetworkError)
debugError)ElementHandle)Frame__pyppeteer_evaluation_script__z(^[\040\t]*//[@#] sourceURL=\s*(\S*?)\s*$c                       e Zd ZdZ	 ddedededdddf
d	Zede	d         fd
            Z
dddedededefdZdddedededdfdZdedefdZddZdS )ExecutionContextzExecution Context class.NclientcontextPayloadobjectHandleFactoryframer   returnc                     || _         || _        |                    d          | _        |                    dddi          }t	          |                    d                    | _        || _        d S )NidauxData	isDefaultF)_client_frameget
_contextIdbool
_isDefault_objectHandleFactory)selfr   r   r   r   r   s         o/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/pyppeteer/execution_context.py__init__zExecutionContext.__init__    sh    (,,T22 $$Ye0DEEw{{;7788$7!!!    c                     | j         S )z4Return frame associated with this execution context.)r   r!   s    r"   r   zExecutionContext.frame*   s     {r$   F)
force_exprpageFunctionargsr'   c                  K    | j         |g|R d|i d{V }	 |                                 d{V }n=# t          $ r0}d|j        d         v rY d}~dS d|j        d         v rY d}~dS  d}~ww xY w|                                 d{V  |S )zmExecute ``pageFunction`` on this context.

        Details see :meth:`pyppeteer.page.Page.evaluate`.
        r'   Nz"Object reference chain is too longr   z$Object couldn't be returned by value)evaluateHandle	jsonValuer
   r)   dispose)r!   r(   r'   r)   handleresultes          r"   evaluatezExecutionContext.evaluate/   s      +t*88 8 8,68 8 8 8 8 8 8 8	!++--------FF 	 	 	3qvay@@6!&)CC	 nns!   6 
A0 A+A+*A++A0JSHandlec          
         K   dt            }|s|st          j        |          s	 t                              |          r|}n| d| } j                            d| j        dddd           d{V }n&# t          $ r}t          |           Y d}~nd}~ww xY w|
                    d          }|r4t          d	                    t          j        |                              |
                    d
          }	                     |	          S 	  j                            d| d| d j         fd|D             dddd           d{V }n&# t          $ r}t          |           Y d}~nd}~ww xY w|
                    d          }|r4t          d	                    t          j        |                              |
                    d
          }	                     |	          S )zsExecute ``pageFunction`` on this context.

        Details see :meth:`pyppeteer.page.Page.evaluateHandle`.
        z//# sourceURL=
zRuntime.evaluateFT)
expression	contextIdreturnByValueawaitPromiseuserGestureNexceptionDetailszEvaluation failed: {}r/   Runtime.callFunctionOnc                 :    g | ]}                     |          S  )_convertArgument).0argr!   s     r"   
<listcomp>z3ExecutionContext.evaluateHandle.<locals>.<listcomp>f   s'    IIISd33C88IIIr$   )functionDeclarationexecutionContextId	argumentsr7   r8   r9   )EVALUATION_SCRIPT_URLr   	is_jsfuncSOURCE_URL_REGEXmatchr   sendr   	Exception_rewriteErrorr   r	   formatgetExceptionMessager    )
r!   r(   r'   r)   suffixexpressionWithSourceUrl_objr0   r:   remoteObjects
   `         r"   r+   zExecutionContext.evaluateHandleB   s      :"799 	;d 	;6+;L+I+I 	;!#)),77 J.:++1=.I.I.I.I+!\../A"9!%%*$(#'D D          ! ! !a        !  $xx(:;; G(+2223CDDF FG G G  88H--L,,\:::
	**+C*6'D'D&'D'D'D&*oIIIIDIII!& $#F F        DD  	 	 	!	  88$677 	?$%<%C%C*+;<<&> &> ? ? ?xx))((666s0   AA9 9
BBB?E 
E8E33E8r@   c                    |t           j        k    rddiS |t           j         k    rddiS t          |t                    r|nd }|r|j        | k    rt          d          |j        rt          d          |j                            d          rd|j                            d          iS |j                            d          sd|j                            d          iS d|j                            d          iS d|iS )NunserializableValueInfinityz	-InfinityzAJSHandles can be evaluated only in the context they were created!zJSHandle is disposed!objectIdvalue)	mathinf
isinstancer2   _contextr	   	_disposed_remoteObjectr   )r!   r@   objectHandles      r"   r>   z!ExecutionContext._convertArgumentu   s   $(??):6648));77(h77AssT 		L$,,()lmmm% B()@AAA)--.CDD f-|/I/M/MNc/d/dee-11*== J!;!?!?!H!HII : > >z J JKK~r$   prototypeHandlec                 0  K   |j         rt          d          |j                            d          st          d          | j                            dd|j        d         i           d{V }|                     |                    d                    S )zSSend query.

        Details see :meth:`pyppeteer.page.Page.queryObjects`.
        zPrototype JSHandle is disposed!rU   z:Prototype JSHandle must not be referencing primitive valuezRuntime.queryObjectsprototypeObjectIdNobjects)r[   r	   r\   r   r   rI   r    )r!   r^   responses      r"   queryObjectszExecutionContext.queryObjects   s      
 $ 	H$%FGGG,00<< 	N$LN N N**+A!>z!JD
         ((i)@)@AAAr$   )N)r^   r2   r   r2   )__name__
__module____qualname____doc__r   r   r   r#   propertyr   r   strr   r1   r+   r>   rc   r=   r$   r"   r   r      sJ       "" =A8 8z 84 8&)8298EI8 8 8 8 x(    X
 +0  3 s #'47   ( 1617 17 17 17S 17)-17:D17 17 17 17fC D    $B B B B B Br$   r   c                       e Zd ZdZdedededdfdZedefd            Z	d	e
dd fd
Zdee
d f         fdZdefdZded         fdZddZde
fdZdS )r2   zJSHandle class.

    JSHandle represents an in-page JavaScript object. JSHandle can be created
    with the :meth:`~pyppeteer.page.Page.evaluateHandle` method.
    contextr   rQ   r   Nc                 >    || _         || _        || _        d| _        d S )NF)rZ   r   r\   r[   )r!   rk   r   rQ   s       r"   r#   zJSHandle.__init__   s#    )r$   c                     | j         S )z%Get execution context of this handle.)rZ   r&   s    r"   executionContextzJSHandle.executionContext   s     }r$   propertyNamec                    K   | j                             d| |           d{V }|                                 d{V }||         }|                                 d{V  |S )z'Get property value of ``propertyName``.z(object, propertyName) => {
                const result = {__proto__: null};
                result[propertyName] = object[propertyName];
                return result;
            }N)rZ   r+   getPropertiesr-   )r!   ro   r]   
propertiesr/   s        r"   getPropertyzJSHandle.getProperty   s      !]99 & & & & & & & & (5577777777
L)""$$$$$$$$$r$   c                 h  K   | j                             d| j                            dd          dd           d{V }t	                      }|d         D ][}|                    d          s| j                            |                    d	                    ||                    d
          <   \|S )z"Get all properties of this handle.zRuntime.getPropertiesrU    T)rU   ownPropertiesNr/   
enumerablerV   name)r   rI   r\   r   dictrZ   r    )r!   rb   r/   props       r"   rq   zJSHandle.getProperties   s      **+B*..z2>>!E
 E
         X& 	# 	#D88L)) '+}'I'I!!(# (#F488F##$$r$   c                    K   | j                             d          }|r@| j                            dd|ddd           d{V }t	          j        |d                   S t	          j        | j                   S )z"Get Jsonized value of this object.rU   r;   zfunction() { return this; }T)rB   rU   r7   r8   Nr/   )r\   r   r   rI   r   valueFromRemoteObject)r!   rU   rb   s      r"   r,   zJSHandle.jsonValue   s      %))*55 	D!\../G'D$!% $	J J        H /0BCCC+D,>???r$   r   c                     dS )z/Return either null or the object handle itself.Nr=   r&   s    r"   	asElementzJSHandle.asElement   s    tr$   c                    K   | j         rdS d| _         	 t          j        | j        | j                   d{V  dS # t
          $ r }t          t          |           Y d}~dS d}~ww xY w)zStop referencing the handle.NT)r[   r   releaseObjectr   r\   rJ   r   logger)r!   r0   s     r"   r-   zJSHandle.dispose   s      > 	F	"&t|T5GHHHHHHHHHHH 	" 	" 	"vq!!!!!!!!!	"s   %; 
A%A  A%c                     | j                             d          r9| j                             d          p| j                             d          }d| S d                    t          j        | j                             S )zGet string representation.rU   subtypetypez	JSHandle@zJSHandle:{})r\   r   rL   r   r|   )r!   _types     r"   toStringzJSHandle.toString   s    !!*-- 	''++I66 4'++F33 &u&&&##();<<> > 	>r$   )r   N)rd   re   rf   rg   r   r   r   r#   rh   rn   ri   rs   rq   r,   r   r~   r-   r   r=   r$   r"   r2   r2      s.         0 * #(,    "2    Xc j    T#z/%:    @ @ @ @ @8O4    " " " "># > > > > > >r$   r2   errorr   c                 z    | j         d                             d          rd} t          |           |          | )Nr   z%Cannot find context with specified idzEExecution context was destroyed, most likely because of a navigation.)r)   endswithr   )r   msgs     r"   rK   rK      s?    z!}EFF Ud5kk#
Kr$   )"rg   loggingrW   retypingr   r   r   r   	pyppeteerr   pyppeteer.connectionr   pyppeteer.errorsr	   r
   pyppeteer.helperr   pyppeteer.element_handler   pyppeteer.frame_managerr   	getLoggerrd   r   rE   compile	MULTILINErG   objectr   r2   rJ   rK   r=   r$   r"   <module>r      s        				 5 5 5 5 5 5 5 5 5 5 5 5       + + + + + + = = = = = = = = ' ' ' ' ' ' .666666------		8	$	$9 2:/L  wB wB wB wB wBv wB wB wBtP> P> P> P> P>v P> P> P>f t      r$   