
    >iQ                        d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ er*d dlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*  G d d      Z+y)	    )annotations)TYPE_CHECKINGOptional)Command)AddBindingParamsAwaitPromiseParamsCallFunctionOnParamsCompileScriptParamsEvaluateParamsGetPropertiesParamsGlobalLexicalScopeNamesParamsQueryObjectsParamsReleaseObjectGroupParamsReleaseObjectParamsRemoveBindingParamsRunScriptParamsRuntimeMethodSetAsyncCallStackDepthParams%SetCustomObjectFormatterEnabledParams"SetMaxCallStackSizeToCaptureParams)AddBindingCommandAwaitPromiseCommandCallArgumentCallFunctionOnCommandCompileScriptCommandDisableCommandEnableCommandEvaluateCommandGetPropertiesCommandGlobalLexicalScopeNamesCommandQueryObjectsCommandReleaseObjectCommandReleaseObjectGroupCommandRemoveBindingCommandRunScriptCommandSerializationOptionsSetAsyncCallStackDepthCommand&SetCustomObjectFormatterEnabledCommand#SetMaxCallStackSizeToCaptureCommandc                     e Zd ZdZeddd       Ze	 	 d	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 	 	 dd       Zedd       Z	edd       Z
e	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	       Ze	 	 	 	 d 	 	 	 	 	 	 	 	 	 	 	 d!d
       Ze	 d	 	 	 d"d       Ze	 d	 	 	 	 	 d#d       Ze	 	 	 	 d$d       Ze	 	 	 	 d%d       Ze	 	 	 	 d&d       Ze	 	 	 	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(d       Ze	 	 	 	 d)d       Ze	 	 	 	 d*d       Ze	 	 	 	 d+d       Zy),RuntimeCommandsa/  
    A class for interacting with the JavaScript runtime using Chrome
    DevTools Protocol.

    This class provides methods to create commands for evaluating JavaScript
    expressions, calling functions on JavaScript objects, and retrieving
    object properties through CDP.

    Attributes:
        EVALUATE_TEMPLATE (dict): Template for the Runtime.evaluate command.
        CALL_FUNCTION_ON_TEMPLATE (dict): Template for the
            Runtime.callFunctionOn command.
        GET_PROPERTIES (dict): Template for the Runtime.getProperties command.
    Nc                ^    t        |       }|||d<   t        t        j                  |      S )a>  
        Creates a command to add a JavaScript binding.

        Args:
            name (str): Name of the binding to add.
            execution_context_name (Optional[str]): Name of the execution context to bind to.

        Returns:
            AddBindingCommand: Command object to add a JavaScript binding.
        nameexecutionContextNamemethodparams)r   r   r   ADD_BINDING)r.   execution_context_namer2   s      f/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/commands/runtime_commands.pyadd_bindingzRuntimeCommands.add_bindingA   s2     "t,!--CF)*m77GG    c                l    t        |       }|||d<   |||d<   t        t        j                  |      S )a  
        Creates a command to await a JavaScript promise and return its result.

        Args:
            promise_object_id (str): ID of the promise to await.
            return_by_value (Optional[bool]): Whether to return the result by value instead
                of reference.
            generate_preview (Optional[bool]): Whether to generate a preview for the result.

        Returns:
            AwaitPromiseCommand: Command object to await a promise.
        )promiseObjectIdreturnByValuegeneratePreviewr0   )r   r   r   AWAIT_PROMISE)promise_object_idreturn_by_valuegenerate_previewr2   s       r5   await_promisezRuntimeCommands.await_promiseS   sC    $ $4EF&&5F?#'(8F$%m99&IIr7   c                    t        |       }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d	<   |	|	|d
<   |
|
|d<   |||d<   |||d<   t        t        j                  |      S )a  
        Creates a command to call a function with a given declaration on a specific object.

        Args:
            function_declaration (str): Declaration of the function to call.
            object_id (Optional[str]): ID of the object to call the function on.
            arguments (Optional[list[CallArgument]]): Arguments to pass to the function.
            silent (Optional[bool]): Whether to silence exceptions.
            return_by_value (Optional[bool]): Whether to return the result by value instead
                of reference.
            generate_preview (Optional[bool]): Whether to generate a preview for the result.
            user_gesture (Optional[bool]): Whether to treat the call as initiated by user gesture.
            await_promise (Optional[bool]): Whether to await promise result.
            execution_context_id (Optional[int]): ID of the execution context to call the
                function in.
            object_group (Optional[str]): Symbolic group name for the result.
            throw_on_side_effect (Optional[bool]): Whether to throw if side effect cannot be
                ruled out.
            unique_context_id (Optional[str]): Unique context ID for the function call.
            serialization_options (Optional[SerializationOptions]): Serialization options for
                the result.

        Returns:
            CallFunctionOnCommand: Command object to call a function on an object.
        )functionDeclarationobjectId	argumentssilentr:   r;   userGestureawaitPromiseexecutionContextIdobjectGroupthrowOnSideEffectuniqueContextIdserializationOptionsr0   )r	   r   r   CALL_FUNCTION_ON)function_declaration	object_idrD   rE   r>   r?   user_gesturer@   execution_context_idobject_groupthrow_on_side_effectunique_context_idserialization_optionsr2   s                 r5   call_function_onz RuntimeCommands.call_function_onm   s    R &:NO !*F: "+F;%F8&&5F?#'(8F$%#$0F=!$%2F>"++?F'(#$0F=!+*>F&'((9F$% ,-BF)*m<<VLLr7   c                b    t        | ||      }|||d<   t        t        j                  |      S )a  
        Creates a command to compile a JavaScript expression.

        Args:
            expression (str): JavaScript expression to compile.
            source_url (str): URL of the source file for the script.
            persist_script (bool): Whether to persist the compiled script.
            execution_context_id (Optional[int]): ID of the execution context to compile
                the script in.

        Returns:
            CompileScriptCommand: Command object to compile a script.
        )
expression	sourceURLpersistScriptrH   r0   )r
   r   r   COMPILE_SCRIPT)rX   
source_urlpersist_scriptrQ   r2   s        r5   compile_scriptzRuntimeCommands.compile_script   s;    ( %!Z~
  ++?F'(m::6JJr7   c                 6    t        t        j                        S )z
        Disables the runtime domain.

        Returns:
            DisableCommand: Command object to disable the runtime domain.
        r1   )r   r   DISABLE r7   r5   disablezRuntimeCommands.disable   s     m3344r7   c                 6    t        t        j                        S )z
        Enables the runtime domain.

        Returns:
            EnableCommand: Command object to enable the runtime domain.
        r`   )r   r   ENABLErb   r7   r5   enablezRuntimeCommands.enable   s     m2233r7   c                "   t        |       }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d	<   |	|	|d
<   |
|
|d<   |||d<   |||d<   |||d<   |||d<   |||d<   t        t        j                  |      S )aJ  
        Creates a command to evaluate a JavaScript expression in the global context.

        Args:
            expression (str): JavaScript expression to evaluate.
            object_group (Optional[str]): Symbolic group name for the result.
            include_command_line_api (Optional[bool]): Whether to include command line API.
            silent (Optional[bool]): Whether to silence exceptions.
            context_id (Optional[int]): ID of the execution context to evaluate in.
            return_by_value (Optional[bool]): Whether to return the result by value instead
                of reference.
            generate_preview (Optional[bool]): Whether to generate a preview for the result.
            user_gesture (Optional[bool]): Whether to treat evaluation as initiated by user gesture.
            await_promise (Optional[bool]): Whether to await promise result.
            throw_on_side_effect (Optional[bool]): Whether to throw if side effect cannot be
                ruled out.
            timeout (Optional[float]): Timeout in milliseconds.
            disable_breaks (Optional[bool]): Whether to disable breakpoints during evaluation.
            repl_mode (Optional[bool]): Whether to execute in REPL mode.
            allow_unsafe_eval_blocked_by_csp (Optional[bool]): Allow unsafe evaluation.
            unique_context_id (Optional[str]): Unique context ID for evaluation.
            serialization_options (Optional[SerializationOptions]): Serialization
                for the result.

        Returns:
            EvaluateCommand: Command object to evaluate JavaScript.
        )rX   rI   includeCommandLineAPIrE   	contextIdr:   r;   rF   rG   rJ   timeoutdisableBreaksreplModeallowUnsafeEvalBlockedByCSPrK   rL   r0   )r   r   r   EVALUATE)rX   rR   include_command_line_apirE   
context_idr>   r?   rP   r@   rS   rj   disable_breaks	repl_mode allow_unsafe_eval_blocked_by_csprT   rU   r2   s                    r5   evaluatezRuntimeCommands.evaluate   s   \  :6#$0F=!#/.FF*+%F8!",F;&&5F?#'(8F$%#$0F=!$%2F>"+*>F&' 'F9%&4F?# !*F:+74TF01((9F$% ,-BF)*m44VDDr7   c                    t        |       }|||d<   |||d<   |||d<   |||d<   t        t        j                  |      S )a  
        Creates a command to get properties of a JavaScript object.

        Args:
            object_id (str): ID of the object to get properties for.
            own_properties (Optional[bool]): Whether to return only own properties.
            accessor_properties_only (Optional[bool]): Whether to return only accessor properties.
            generate_preview (Optional[bool]): Whether to generate previews for property values.
            non_indexed_properties_only (Optional[bool]): Whether to return only non-indexed
                properties.

        Returns:
            GetPropertiesCommand: Command object to get object properties.
        rC   ownPropertiesaccessorPropertiesOnlyr;   nonIndexedPropertiesOnlyr0   )r   r   r   GET_PROPERTIES)rO   own_propertiesaccessor_properties_onlyr?   non_indexed_properties_onlyr2   s         r5   get_propertieszRuntimeCommands.get_properties2  sd    , %i8%&4F?##//GF+,'(8F$%&21LF-.m::6JJr7   c                Z    t               }| | |d<   t        t        j                  |      S )ac  
        Creates a command to retrieve names of variables from global lexical scope.

        Args:
            execution_context_id (Optional[int]): ID of the execution context to get scope
                names from.

        Returns:
            GlobalLexicalScopeNamesCommand: Command object to get global lexical
                scope names.
        rH   r0   )r   r   r   GLOBAL_LEXICAL_SCOPE_NAMES)rQ   r2   s     r5   global_lexical_scope_namesz*RuntimeCommands.global_lexical_scope_namesT  s0     /0++?F'(mFFvVVr7   c                ^    t        |       }|||d<   t        t        j                  |      S )aA  
        Creates a command to query objects with a given prototype.

        Args:
            prototype_object_id (str): ID of the prototype object.
            object_group (Optional[str]): Symbolic group name for the results.

        Returns:
            QueryObjectsCommand: Command object to query objects.
        )prototypeObjectIdrI   r0   )r   r   r   QUERY_OBJECTS)prototype_object_idrR   r2   s      r5   query_objectszRuntimeCommands.query_objectsi  s2     $6IJ#$0F=!m99&IIr7   c                P    t        |       }t        t        j                  |      S )z
        Creates a command to release a JavaScript object.

        Args:
            object_id (str): ID of the object to release.

        Returns:
            ReleaseObjectCommand: Command object to release an object.
        rv   r0   )r   r   r   RELEASE_OBJECT)rO   r2   s     r5   release_objectzRuntimeCommands.release_object~  s!     %i8m::6JJr7   c                P    t        |       }t        t        j                  |      S )z
        Creates a command to release all objects in a group.

        Args:
            object_group (str): Name of the object group to release.

        Returns:
            ReleaseObjectGroupCommand: Command object to release an object group.
        )rI   r0   )r   r   r   RELEASE_OBJECT_GROUP)rR   r2   s     r5   release_object_groupz$RuntimeCommands.release_object_group  s!     *lCm@@PPr7   c                P    t        |       }t        t        j                  |      S )z
        Creates a command to remove a JavaScript binding.

        Args:
            name (str): Name of the binding to remove.

        Returns:
            RemoveBindingCommand: Command object to remove a JavaScript binding.
        r-   r0   )r   r   r   REMOVE_BINDING)r.   r2   s     r5   remove_bindingzRuntimeCommands.remove_binding  s!     %$/m::6JJr7   c                    t        |       }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   t        t        j                  |	      S )
aQ  
        Creates a command to run a compiled script.

        Args:
            script_id (str): ID of the compiled script to run.
            execution_context_id (Optional[int]): ID of the execution context to run the script in.
            object_group (Optional[str]): Symbolic group name for the result.
            silent (Optional[bool]): Whether to silence exceptions.
            include_command_line_api (Optional[bool]): Whether to include command line API.
            return_by_value (Optional[bool]): Whether to return the result by value instead
                of reference.
            generate_preview (Optional[bool]): Whether to generate a preview for the result.
            await_promise (Optional[bool]): Whether to await promise result.

        Returns:
            RunScriptCommand: Command object to run a script.
        )scriptIdrH   rI   rE   rh   r:   r;   rG   r0   )r   r   r   
RUN_SCRIPT)		script_idrQ   rR   rE   ro   r>   r?   r@   r2   s	            r5   
run_scriptzRuntimeCommands.run_script  s    8 !)4++?F'(#$0F=!%F8#/.FF*+&&5F?#'(8F$%$%2F>"m66vFFr7   c                P    t        |       }t        t        j                  |      S )a  
        Creates a command to set the async call stack depth.

        Args:
            max_depth (int): Maximum depth of async call stacks.

        Returns:
            SetAsyncCallStackDepthCommand: Command object to set async call stack depth.
        )maxDepthr0   )r   r   r   SET_ASYNC_CALL_STACK_DEPTH)	max_depthr2   s     r5   set_async_call_stack_depthz*RuntimeCommands.set_async_call_stack_depth  s!     .yAmFFvVVr7   c                P    t        |       }t        t        j                  |      S )a:  
        Creates a command to enable or disable custom object formatters.

        Args:
            enabled (bool): Whether to enable custom object formatters.

        Returns:
            SetCustomObjectFormatterEnabledCommand: Command object to enable/disable custom
                object formatters.
        )enabledr0   )r   r   r   #SET_CUSTOM_OBJECT_FORMATTER_ENABLED)r   r2   s     r5   #set_custom_object_formatter_enabledz3RuntimeCommands.set_custom_object_formatter_enabled  s"     7wGmOOX^__r7   c                P    t        |       }t        t        j                  |      S )a  
        Creates a command to set the maximum call stack size to capture.

        Args:
            size (int): Maximum call stack size to capture.

        Returns:
            SetMaxCallStackSizeToCaptureCommand: Command object to set max call stack size.
        )sizer0   )r   r   r   "SET_MAX_CALL_STACK_SIZE_TO_CAPTURE)r   r2   s     r5   "set_max_call_stack_size_to_capturez2RuntimeCommands.set_max_call_stack_size_to_capture  s"     4>mNNW]^^r7   )N)r.   strr4   Optional[str]returnr   )NN)r=   r   r>   Optional[bool]r?   r   r   r   )NNNNNNNNNNNN)rN   r   rO   r   rD   zOptional[list[CallArgument]]rE   r   r>   r   r?   r   rP   r   r@   r   rQ   Optional[int]rR   r   rS   r   rT   r   rU   Optional[SerializationOptions]r   r   )FN)
rX   r   r\   r   r]   boolrQ   r   r   r   )r   r   )r   r   )NNNNNNNNNNNNNNN)"rX   r   rR   r   ro   r   rE   r   rp   r   r>   r   r?   r   rP   r   r@   r   rS   r   rj   zOptional[float]rq   r   rr   r   rs   r   rT   r   rU   r   r   r   )NNNN)rO   r   r{   r   r|   r   r?   r   r}   r   r   r   )rQ   r   r   r    )r   r   rR   r   r   r!   )rO   r   r   r"   )rR   r   r   r#   )r.   r   r   r$   )NNNNNNN)r   r   rQ   r   rR   r   rE   r   ro   r   r>   r   r?   r   r@   r   r   r%   )r   intr   r'   )r   r   r   r(   )r   r   r   r)   )__name__
__module____qualname____doc__staticmethodr6   r@   rV   r^   rc   rf   rt   r~   r   r   r   r   r   r   r   r   r   rb   r7   r5   r+   r+   1   s    H H"  +/+/JJ'J )J 
	J J2  $(26!%*.+/'+(,.2&*/3+/@DBM!BM BM 0BM 	BM
 (BM )BM %BM &BM ,BM $BM -BM )BM  >BM 
BM BMH   %.2	KKK K ,	K
 
K K6 5 5 4 4  '+37!%$(*.+/'+(,/3#')-$(;?+/@D!MEME#ME #1ME 	ME
 "ME (ME )ME %ME &ME -ME !ME 'ME "ME +9ME )ME   >!ME" 
#ME ME^  *.37+/6:KK&K #1K )	K
 &4K 
K KB .2W+W	'W W(  '+J J#J 
J J( KK	K K  QQ	"Q Q KK	K K  /3&*!%37*.+/(,+G+G++G $+G 	+G
 #1+G (+G )+G &+G 
+G +GZ WW	&W W ``	/` `  __	,_ _r7   r+   N),
__future__r   typingr   r   pydoll.protocol.baser   pydoll.protocol.runtime.methodsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r+   rb   r7   r5   <module>r      sX    " * (    &      .[_ [_r7   