
    >i0                        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 d dl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 d dlmZmZmZm Z  d dl!m"Z"m#Z#  G d	 d
      Z$y)    )annotations)TYPE_CHECKINGOptional)Command)
AuthChallengeResponseContinueRequestParamsContinueResponseParamsContinueWithAuthParamsEnableParamsFailRequestParamsFetchMethodFulfillRequestParamsGetResponseBodyParamsTakeResponseBodyAsStreamParams)RequestPattern)	ContinueRequestCommandContinueResponseCommandContinueWithAuthCommandDisableCommandEnableCommandFailRequestCommandFulfillRequestCommandGetResponseBodyCommandTakeResponseBodyAsStreamCommand)AuthChallengeResponseTypeHeaderEntryRequestStageResourceType)ErrorReasonRequestMethodc                  J   e Zd ZdZe	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 	 	 dd       Zedd       Ze	 	 	 d	 	 	 	 	 	 	 	 	 dd       Zedd       Z	e	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd       Z
edd	       Ze	 	 	 d	 	 	 	 	 	 	 	 	 dd
       Ze	 	 	 	 dd       Zy)FetchCommandsa  
    This class encapsulates the fetch commands of the Chrome DevTools Protocol (CDP).

    CDP's Fetch domain allows interception and modification of network requests
    at the application layer. This enables developers to examine, modify, and
    control network traffic, which is particularly useful for testing, debugging,
    and advanced automation scenarios.

    The commands defined in this class provide functionality for:
    - Enabling and disabling fetch request interception
    - Continuing, fulfilling, or failing intercepted requests
    - Handling authentication challenges
    - Retrieving and modifying response bodies
    - Processing response data as streams
    Nc                    t        |       }|||d<   |||d<   |||d<   |||d<   |||d<   t        t        j                  |      S )a  
        Creates a command to continue a paused fetch request.

        This command allows the browser to resume a fetch operation that has
        been intercepted. You can modify the fetch request URL, method,
        headers, and body before continuing.

        Args:
            request_id (str): The ID of the fetch request to continue.
            url (Optional[str]): The new URL for the fetch request. Defaults to None.
            method (Optional[RequestMethod]): The HTTP method to use (e.g., 'GET',
                'POST'). Defaults to None.
            post_data (Optional[dict]): The body data to send with the fetch
                request. Defaults to None.
            headers (Optional[list[HeaderEntry]]): A list of HTTP headers to include
                in the fetch request. Defaults to None.
            intercept_response (Optional[bool]): Indicates if the response
                should be intercepted. Defaults to None.

        Returns:
            Command[Response]: A command for continuing the fetch request.
        	requestIdurlmethodpostDataheadersinterceptResponser'   params)r   r   r   CONTINUE_REQUEST)
request_idr&   r'   	post_datar)   intercept_responser,   s          d/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/commands/fetch_commands.pycontinue_requestzFetchCommands.continue_request:   sp    > '<?F5M%F8 !*F: 'F9)*<F&'k::6JJ    c                    t        |      }|||d<   |||d<   t        | |      }t        t        j                  |      S )a8  
        Creates a command to continue a paused fetch request with
        authentication.

        This command is used when the fetch operation requires authentication.
        It provides the necessary credentials to continue the request.

        Args:
            request_id (str): The ID of the fetch request to continue.
            auth_challenge_response (AuthChallengeResponseType): The authentication
                challenge response type.
            proxy_username (Optional[str]): The username for proxy authentication.
                Defaults to None.
            proxy_password (Optional[str]): The password for proxy authentication.
                Defaults to None.

        Returns:
            Command[Response]: A command for continuing the fetch request with
                authentication.
        )responseusernamepassword)r%   authChallengeResponser+   )r   r
   r   r   CONTINUE_WITH_AUTH)r.   auth_challenge_responseproxy_usernameproxy_passwordauth_challenge_response_dictr,   s         r1   continue_request_with_authz(FetchCommands.continue_request_with_authf   sW    6 (=F]'^$%7E(4%7E(4' ">
 k<<VLLr3   c                 6    t        t        j                        S )z
        Creates a command to disable fetch interception.

        This command stops the browser from intercepting fetch requests.

        Returns:
            Command[Response]: A command for disabling fetch interception.
        )r'   )r   r   DISABLE r3   r1   disablezFetchCommands.disable   s     k1122r3   c                    t        |      }|||d<   |||d<   t        |g|       }t        t        j                  |      S )a/  
        Creates a command to enable fetch interception.

        This command allows the browser to start intercepting fetch requests.
        You can specify whether to handle authentication challenges and the
        types of resources to intercept.

        Args:
            handle_auth_requests (bool): Indicates if authentication requests
                should be handled.
            url_pattern (str): Pattern to match URLs for interception. Defaults to '*'.
            resource_type (Optional[ResourceType]): The type of resource to intercept.
                Defaults to None.
            request_stage (Optional[RequestStage]): The stage of the request to intercept.
                Defaults to None.

        Returns:
            Command[Response]: A command for enabling fetch interception.
        )
urlPatternresourceTyperequestStage)patternshandleAuthRequestsr+   )r   r   r   r   ENABLE)handle_auth_requestsurl_patternresource_typerequest_stagerequest_patternr,   s         r1   enablezFetchCommands.enable   sQ    4 )K@$.;ON+$.;ON+'8Mabk00@@r3   c                R    t        | |      }t        t        j                  |      S )a  
        Creates a command to simulate a failure in a fetch request.

        This command allows you to simulate a failure for a specific fetch
        operation, providing a reason for the failure.

        Args:
            request_id (str): The ID of the fetch request to fail.
            error_reason (ErrorReason): The reason for the failure.

        Returns:
            Command[Response]: A command for failing the fetch request.
        )r%   errorReasonr+   )r   r   r   FAIL_REQUEST)r.   error_reasonr,   s      r1   fail_requestzFetchCommands.fail_request   s#     #Z\Rk66vFFr3   c                |    t        | |      }|||d<   |||d<   |||d<   t        t        j                  |      S )a0  
        Creates a command to fulfill a fetch request with a custom response.

        This command allows you to provide a custom response for a fetch
        operation, including the HTTP status code, headers, and body content.

        Args:
            request_id (str): The ID of the fetch request to fulfill.
            response_code (int): The HTTP status code to return.
            response_headers (Optional[list[HeaderEntry]]): A list of response headers.
                Defaults to None.
            body (Optional[dict]): The body content of the response. Defaults to None.
            response_phrase (Optional[str]): The response phrase (e.g., 'OK',
                'Not Found'). Defaults to None.

        Returns:
            Command[Response]: A command for fulfilling the fetch request.
        )r%   responseCoderesponseHeadersbodyresponsePhraser+   )r   r   r   FULFILL_REQUEST)r.   response_coderesponse_headersrX   response_phraser,   s         r1   fulfill_requestzFetchCommands.fulfill_request   sZ    4 & &
 '(8F$%!F6N&'6F#$k99&IIr3   c                P    t        |       }t        t        j                  |      S )a  
        Creates a command to retrieve the response body of a fetch request.

        This command allows you to access the body of a completed fetch
        operation, which can be useful for analyzing the response data.

        Args:
            request_id (str): The ID of the fetch request to retrieve the body
                from.

        Returns:
            Command[GetResponseBodyResponse]: A command for getting the response body.
        r$   r+   )r   r   r   GET_RESPONSE_BODYr.   r,   s     r1   get_response_bodyzFetchCommands.get_response_body   s!     '<k;;FKKr3   c                z    t        |       }|||d<   |||d<   |||d<   t        t        j                  |      S )aN  
        Creates a command to continue a fetch response for an intercepted
        request.

        This command allows the browser to continue the response flow for a
        specific fetch request, including customizing the HTTP status code,
        headers, and response phrase.

        Args:
            request_id (str): The ID of the fetch request to continue the
                response for.
            response_code (Optional[int]): The HTTP status code to send.
                Defaults to None.
            response_headers (Optional[list[HeaderEntry]]): A list of response headers.
                Defaults to None.
            response_phrase (Optional[str]): The response phrase (e.g., 'OK').
                Defaults to None.

        Returns:
            Command[Response]: A command for continuing the fetch response.
        r$   rV   rW   rY   r+   )r	   r   r   CONTINUE_RESPONSE)r.   r[   r\   r]   r,   s        r1   continue_responsezFetchCommands.continue_response  sS    8 (*=$%2F>"'(8F$%&'6F#$k;;FKKr3   c                P    t        |       }t        t        j                  |      S )a  
        Creates a command to take the response body as a stream.

        This command allows you to receive the response body as a stream
        which can be useful for handling large responses.

        Args:
            request_id (str): The ID of the fetch request to take the response
                body stream from.

        Returns:
            Command[TakeResponseBodyAsStreamResponse]: A command for taking the response
                body as a stream.
        r$   r+   )r   r   r   TAKE_RESPONSE_BODY_AS_STREAMra   s     r1   take_response_body_as_streamz*FetchCommands.take_response_body_as_stream+  s!    $ 0*EkFFvVVr3   )NNNNN)r.   strr&   Optional[str]r'   zOptional['RequestMethod']r/   rj   r)   Optional[list['HeaderEntry']]r0   zOptional[bool]returnr   )NN)
r.   ri   r:   r   r;   rj   r<   rj   rl   r   )rl   r   )*NN)
rJ   boolrK   ri   rL   zOptional['ResourceType']rM   zOptional['RequestStage']rl   r   )r.   ri   rS   r   rl   r   )NNN)r.   ri   r[   intr\   rk   rX   rj   r]   rj   rl   r   )r.   ri   rl   r   )
r.   ri   r[   zOptional[int]r\   rk   r]   rj   rl   r   )r.   ri   rl   r   )__name__
__module____qualname____doc__staticmethodr2   r>   rB   rO   rT   r^   rb   re   rh   rA   r3   r1   r"   r"   )   s<      ",0#'15-1)K)K)K *)K !	)K
 /)K +)K 
 )K )KV  )-(,	$M$M!:$M &$M &	$M
 
!$M $ML 	3 	3  2626	 A" A A 0 A 0	 A
 
 A  AD G G"  ;?")-#J#J#J 8#J 	#J
 '#J 
#J #JJ L L"  (,:>)-	"L"L$"L 8"L '	"L
 
!"L "LH WW	(W Wr3   r"   N)%
__future__r   typingr   r   pydoll.protocol.baser   pydoll.protocol.fetch.methodsr   r   r	   r
   r   r   r   r   r   r   pydoll.protocol.fetch.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   pydoll.protocol.network.typesr   r    r"   rA   r3   r1   <module>r{      sR    " * (   7
 
 
  IUW UWr3   