
    tfY$                     &   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j4                  dej6                        Z G d de      Z G d de      Zde ddfdZ!y)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y)ExecutionContextzExecution Context class.NclientcontextPayloadobjectHandleFactoryframer   returnc                     || _         || _        |j                  d      | _        |j                  dddi      }t	        |j                  d            | _        || _        y )NidauxData	isDefaultF)_client_frameget
_contextIdbool
_isDefault_objectHandleFactory)selfr   r   r   r   r   s         e/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/pyppeteer/execution_context.py__init__zExecutionContext.__init__    sV    (,,T2 $$Ye0DEw{{;7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                4  K    | j                   |g|d|i d{   }	 |j                          d{   }|j	                          d{    |S 7 77  # t        $ r2}d|j                  d   v rY d}~yd|j                  d   v rY d}~y d}~ww xY w7 Hw)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,68 8	!++--F nn8 . 	3qvvay@6!&&)C	 	se   BABA AA BBBA 	B!B2B7BBBBBJSHandlec                  K   dt          }|s|st        j                  |      s	 t        j	                  |      r|}n| d| }| j
                  j                  d|| j                  dddd       d{   }j                  d      }|r-t        d	j                  t        j                  |                  |j                  d
      }	| j                  |	      S 	 | j
                  j                  d| d| d| j                  |D 
cg c]  }
| j                  |
       c}
dddd       d{   }j                  d      }|r-t        d	j                  t        j                  |                  |j                  d
      }	| j                  |	      S 7 "# t        $ r}t        |       Y d}~:d}~ww xY wc c}
w 7 # t        $ r}t        |       Y d}~d}~ww xY ww)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.callFunctionOn)functionDeclarationexecutionContextId	argumentsr7   r8   r9   )EVALUATION_SCRIPT_URLr   	is_jsfuncSOURCE_URL_REGEXmatchr   sendr   	Exception_rewriteErrorr   r	   formatgetExceptionMessager    _convertArgument)r!   r(   r'   r)   suffixexpressionWithSourceUrl_objr0   r:   remoteObjectargs              r"   r+   zExecutionContext.evaluateHandleB   s     ""7!89d6+;+;L+I!#)),7.:+1=b.I+!\\../A"9!%%*$(#'D    $xx(:;(+22223CDFG G  88H-L,,\::
	**+C*6r&'D&*ooDHISd33C8I!& $#F  D  88$67$%<%C%C**+;<&> ? ?xx)((66G  !a  ! J  	!	s   #G#AF 4F5F 9A"G#,G F; G /G 0G 4A"G#F 	F8"F3-G#3F88G#;G 	G GG#G  G#rM   c                    |t         j                  k(  rddiS |t         j                   k(  rddiS t        |t              r|nd }|r|j                  | k7  rt        d      |j                  rt        d      |j                  j                  d      rd|j                  j                  d      iS |j                  j                  d      sd|j                  j                  d      iS d|j                  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!   rM   objectHandles      r"   rH   z!ExecutionContext._convertArgumentu   s    $((?):66488));77(h7sT$$,()lmm%%()@AA))--.CD-|/I/I/M/MNc/dee--11*=!;!;!?!?!HII : : > >z JKK~r$   c                 .  K   |j                   rt        d      |j                  j                  d      st        d      | j                  j                  dd|j                  d   i       d{   }| j                  |j                  d            S 7 $w)zSSend query.

        Details see :meth:`pyppeteer.page.Page.queryObjects`.
        zPrototype JSHandle is disposed!rQ   z:Prototype JSHandle must not be referencing primitive valuezRuntime.queryObjectsprototypeObjectIdNobjects)rW   r	   rX   r   r   rC   r    )r!   prototypeHandleresponses      r"   queryObjectszExecutionContext.queryObjects   s     
 $$$%FGG,,00<$LN N**+A!>!>z!JD
   ((i)@AAs   A,B.B/%B)N)r]   r2   r   r2   )__name__
__module____qualname____doc__r   r   r   r#   propertyr   r   strr   r1   r+   rH   r_    r$   r"   r   r      s    " =A8z 84 8&)8298EI8 x(  
 +03 s #'47( 1617 17S 17)-17:D17fC D $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y)r2   zJSHandle class.

    JSHandle represents an in-page JavaScript object. JSHandle can be created
    with the :meth:`~pyppeteer.page.Page.evaluateHandle` method.
    contextr   rL   r   Nc                 <    || _         || _        || _        d| _        y )NF)rV   r   rX   rW   )r!   rh   r   rL   s       r"   r#   zJSHandle.__init__   s    )r$   c                     | j                   S )z%Get execution context of this handle.)rV   r&   s    r"   executionContextzJSHandle.executionContext   s     }}r$   propertyNamec                    K   | j                   j                  d| |       d{   }|j                          d{   }||   }|j                          d{    |S 7 ;7 %7 
w)z'Get property value of ``propertyName``.z(object, propertyName) => {
                const result = {__proto__: null};
                result[propertyName] = object[propertyName];
                return result;
            }N)rV   r+   getPropertiesr-   )r!   rl   rY   
propertiesr/   s        r"   getPropertyzJSHandle.getProperty   sn     !]]99 & & (5577
L)""$$$& 8$s1   !A%AA%A!A%A#A%!A%#A%c                 X  K   | j                   j                  d| j                  j                  dd      dd       d{   }t	               }|d   D ]P  }|j                  d      s| j
                  j                  |j                  d	            ||j                  d
      <   R |S 7 hw)z"Get all properties of this handle.zRuntime.getPropertiesrQ    T)rQ   ownPropertiesNr/   
enumerablerR   name)r   rC   rX   r   dictrV   r    )r!   r^   r/   props       r"   rn   zJSHandle.getProperties   s     **+B**..z2>!E
   X& 	#D88L)'+}}'I'I!(#F488F#$	#
 s   =B*B( A)B*c                   K   | j                   j                  d      }|rA| j                  j                  dd|ddd       d{   }t	        j
                  |d         S t	        j
                  | j                         S 7 ;w)z"Get Jsonized value of this object.rQ   r;   zfunction() { return this; }T)r<   rQ   r7   r8   Nr/   )rX   r   r   rC   r   valueFromRemoteObject)r!   rQ   r^   s      r"   r,   zJSHandle.jsonValue   s     %%))*5!\\../G'D$!% $	J  H //0BCC++D,>,>??s   ABB <Br   c                      y)z/Return either null or the object handle itself.Nrf   r&   s    r"   	asElementzJSHandle.asElement   s    r$   c                    K   | j                   ryd| _         	 t        j                  | j                  | j                         d{    y7 # t
        $ r}t        t        |       Y d}~yd}~ww xY ww)zStop referencing the handle.NT)rW   r   releaseObjectr   rX   rD   r   logger)r!   r0   s     r"   r-   zJSHandle.dispose   sX     >>	"&&t||T5G5GHHH 	"vq!!	"s@   A3-A AA 
A3A 	A0A+&A3+A00A3c                    | j                   j                  d      r=| j                   j                  d      xs | j                   j                  d      }d| S dj                  t        j                  | j                               S )zGet string representation.rQ   subtypetypez	JSHandle@zJSHandle:{})rX   r   rF   r   ry   )r!   _types     r"   toStringzJSHandle.toString   s|    !!*-''++I6 4''++F3 ug&&##((););<> 	>r$   )r   N)r`   ra   rb   rc   r   r   r   r#   rd   rk   re   rp   rn   r,   r   r{   r-   r   rf   r$   r"   r2   r2      s     0 * #(, "2  c j T#z/%: @ @8O4 "># >r$   r2   errorr   c                 h    | j                   d   j                  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"   rE   rE      s4    zz!}EFUd5k#
Kr$   )"rc   loggingrS   retypingr   r   r   r   	pyppeteerr   pyppeteer.connectionr   pyppeteer.errorsr	   r
   pyppeteer.helperr   pyppeteer.element_handler   pyppeteer.frame_managerr   	getLoggerr`   r~   r?   compile	MULTILINErA   objectr   r2   rD   rE   rf   r$   r"   <module>r      s        	 5 5  + = '6-			8	$9 2::/LL wBv wBtP>v P>f t r$   