
    ,h-                     L    d dl mZ  G d d      Z G d d      Z G d d      Zy)	    )command_builderc                   &    e Zd ZdZd Zed        Zy)NetworkEventzRepresents a network event.c                      || _         || _        y N)event_classparams)selfr   kwargss      h/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/selenium/webdriver/common/bidi/network.py__init__zNetworkEvent.__init__   s    &    c                 4     | dd|j                  d      i|S )Nr    )get)clsjsons     r   	from_jsonzNetworkEvent.from_json   s    ?txx6?$??r   N)__name__
__module____qualname____doc__r   classmethodr   r   r   r   r   r      s     % @ @r   r   c                   n    e Zd ZddddddddZd	d
ddZd Zg ddfdZddZd ZddZ	d Z
d Zd Zd Zy)Networkznetwork.beforeRequestSentznetwork.responseStartedznetwork.responseCompletedznetwork.authRequiredznetwork.fetchErrornetwork.continueRequestnetwork.continueWithAuth)before_requestresponse_startedresponse_completedauth_requiredfetch_errorcontinue_requestcontinue_authbeforeRequestSentresponseStartedauthRequired)r   r   r!   c                 <    || _         g | _        i | _        i | _        y r   )conn
intercepts	callbackssubscriptions)r
   r)   s     r   r   zNetwork.__init__2   s    	r   Nc                     i }|||d<   |||d<   t        |      dkD  r||d<   ndg|d<   t        d|      }| j                  j                  |      }| j                  j                  |d          |S )a  Add an intercept to the network.

        Parameters:
        ----------
            phases (list, optional): A list of phases to intercept.
                Default is empty list.
            contexts (list, optional): A list of contexts to intercept.
                Default is None.
            url_patterns (list, optional): A list of URL patterns to intercept.
                Default is None.

        Returns:
        -------
            str : intercept id
        contextsurlPatternsr   phasesr%   znetwork.addIntercept	intercept)lenr   r)   executer*   append)r
   r0   r.   url_patternsr	   cmdresults          r   _add_interceptzNetwork._add_intercept8   s      !)F:#$0F=!v;?%F8 34F84f=""3'vk23r   c                    |d| j                   j                         }|D ]D  }| j                  j                  t	        dd|i             | j                   j                  |       F y	 | j                  j                  t	        dd|i             | j                   j                  |       y# t        $ r}t        d|       d}~ww xY w)as  Remove a specific intercept, or all intercepts.

        Parameters:
        ----------
            intercept (str, optional): The intercept to remove.
                Default is None.

        Raises:
        ------
            Exception: If intercept is not found.

        Notes:
        -----
            If intercept is None, all intercepts will be removed.
        Nznetwork.removeInterceptr1   zException: )r*   copyr)   r3   r   remove	Exception)r
   r1   intercepts_to_removeintercept_ides        r   _remove_interceptzNetwork._remove_interceptW   s      #'??#7#7#9  4 5		!!/2Kk[gMh"ij&&|453		!!/2Kk[dMe"fg&&y1 3+aS 1223s   (AB+ +	C4CCc                      t        |      } fd} j                  j                  ||      }| j                  v r  j                  |   j	                  |       |S |g j                  |<   |S )a`  Set a callback function to subscribe to a network event.

        Parameters:
        ----------
            event_name (str): The event to subscribe to.
            callback (function): The callback function to execute on event.
                Takes Request object as argument.

        Returns:
        -------
            int : callback id
        c                    t        | j                  d   j                  dd       | j                  d   j                  dd       | j                  d   j                  dd       | j                  d   j                  dd       | j                  d   j                  dd       | j                  d   j                  dd       | j                  d   j                  dd             } |       y )	NrequestbodySizecookieszgoog:resourceTypeheadersSizetimingsurl)network
request_id	body_sizerE   resource_typeheaders_sizerG   rH   )Requestr	   r   )
event_datarC   callbackr
   s     r   	_callbackz&Network._on_request.<locals>._callback   s    %,,Y7;;ItL$++I6:::tL")))488DI(//	:>>?RTXY'..y9==mTR")))488DI%%i044UDA	G Wr   )r   r)   add_callbackr+   r4   )r
   
event_namerP   eventrQ   callback_ids   ` `   r   _on_requestzNetwork._on_requests   so     Z(	 ii,,UI>'NN:&--k:  +6DNN:&r   c                    	 | j                   |   }| j                  |   }| j	                  |g||      }| j                  ||      }|| j                  v r| j                  |   j                  |       n=i }	|g|	d<   | j                  j                  t        d|	             |g| j                  |<   |d   | j                  |<   |S # t        $ r t        d| d      w xY w)a0  Add a request handler to the network.

        Parameters:
        ----------
            event (str): The event to subscribe to.
            url_patterns (list, optional): A list of URL patterns to intercept.
                Default is None.
            contexts (list, optional): A list of contexts to intercept.
                Default is None.
            callback (function): The callback function to execute on request interception
                Takes Request object as argument.

        Returns:
        -------
            int : callback id
        Event 
 not found)r0   r5   r.   eventszsession.subscriber1   )EVENTSPHASESKeyErrorr<   r8   rV   r,   r4   r)   r3   r   r+   )
r
   rT   rP   r5   r.   rS   
phase_namer7   rU   r	   s
             r   add_request_handlerzNetwork.add_request_handler   s    $	8U+JU+J $$ZL|^f$g&&z8<+++z*11+>F *|F8IIo.A6JK.9]Dz*&,[&9{#  	8fUG:677	8s   C Cc                    	 | j                   |   }t        |      }| j                  j                  ||       | j                  | j                  |          | j                  |= | j                  |   j                  |       t        | j                  |         dk(  r;i }|g|d<   | j                  j                  t        d|             | j                  |= yy# t        $ r t        d| d      w xY w)zRemove a request handler from the network.

        Parameters:
        ----------
            event_name (str): The event to unsubscribe from.
            callback_id (int): The callback id to remove.
        rX   rY   r   rZ   session.unsubscribeN)r[   r]   r<   r   r)   remove_callbackr@   r+   r,   r;   r2   r3   r   )r
   rT   rU   rS   	net_eventr	   s         r   remove_request_handlerzNetwork.remove_request_handler   s    	8U+J !,			!!)[9t~~k:;NN;':&--k:t!!*-.!3F *|F8IIo.CVLM"":.	 4  	8fUG:677	8s   C C1c                 Z   | j                   D ]  }t        |      }| j                   |   D ]I  }| j                  j                  ||       | j	                  | j
                  |          | j
                  |= K i }|g|d<   | j                  j                  t        d|              i | _         y)z,Clear all request handlers from the network.rZ   ra   N)r,   r   r)   rb   r@   r+   r3   r   )r
   rS   rc   rU   r	   s        r   clear_request_handlerszNetwork.clear_request_handlers   s     ,, 	NJ$Z0I#11*= 0		)))[A&&t~~k'BCNN;/0 F *|F8IIo.CVLM	N  r   c                 :    d}fd}| j                  ||      S )a  Add an authentication handler to the network.

        Parameters:
        ----------
            username (str): The username to authenticate with.
            password (str): The password to authenticate with.

        Returns:
        -------
            int : callback id
        r!   c                 *    | j                         y r   )_continue_with_auth)rC   passwordusernames    r   rQ   z+Network.add_auth_handler.<locals>._callback   s    ''(;r   )r_   )r
   rk   rj   rT   rQ   s    ``  r   add_auth_handlerzNetwork.add_auth_handler   s$      	< ''y99r   c                 ,    d}| j                  ||       y)zRemove an authentication handler from the network.

        Parameters:
        ----------
            callback_id (int): The callback id to remove.
        r!   N)rd   )r
   rU   rT   s      r   remove_auth_handlerzNetwork.remove_auth_handler   s      ##E;7r   r   NN)r   r   r   r[   r\   r   r8   r@   rV   r_   rd   rf   rl   rn   r   r   r   r   r   !   sh    559/+53F .-'F  %'D >38$L$L/2 :&8r   r   c                   D    e Zd ZdZ	 	 	 	 	 	 	 	 ddefdZd Zd	dZd
dZy)rN   z*Represents an intercepted network request.NrI   c                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        y r   )
rI   rJ   rK   rE   rL   headersrM   methodrG   rH   )r
   rI   rJ   rK   rE   rL   rr   rM   rs   rG   rH   s              r   r   zRequest.__init__  sL     $"*(r   c                     | j                   st        d      d| j                   i}| j                  j                  j	                  t        d|             y)zFail this request.Request not found.rC   znetwork.failRequestNrJ   
ValueErrorrI   r)   r3   r   )r
   r	   s     r   fail_requestzRequest.fail_request  sE     122T__-!!/2G"PQr   c                     | j                   st        d      d| j                   i}|||d<   |||d<   |||d<   |||d<   |||d<   | j                  j                  j	                  t        d	|             y)
z)Continue after intercepting this request.ru   rC   Nbodyrs   rr   rE   rH   r   rv   )r
   rz   rs   rr   rE   rH   r	   s          r   r#   zRequest.continue_request(  s     122T__-!F6N%F8 'F9 'F9?F5M!!/2KV"TUr   c                     i }| j                   |d<   |r|sd|d<   nd|d<   d||d|d<   | j                  j                  j                  t	        d|             y	)
ay  Continue with authentication.

        Parameters:
        ----------
            request (Request): The request to continue with.
            username (str): The username to authenticate with.
            password (str): The password to authenticate with.

        Notes:
        -----
            If username or password is None, it attempts auth with no credentials
        rC   defaultactionprovideCredentialsrj   )typerk   rj   credentialsr   N)rJ   rI   r)   r3   r   )r
   rk   rj   r	   s       r   ri   zRequest._continue_with_auth<  sb      OOyx(F83F8-7X[c$dF=!!!/2Lf"UVr   )NNNNNNNN)NNNNNro   )	r   r   r   r   r   r   rx   r#   ri   r   r   r   rN   rN     s>    4 0RV(Wr   rN   N)%selenium.webdriver.common.bidi.commonr   r   r   rN   r   r   r   <module>r      s2   $ B	@ 	@`8 `8FOW OWr   