U
    g(                     @   s~   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	Z	d dl
mZ d dl
mZ G dd deZG d	d
 d
ZdS )    N)Enum)Optional)parse)Proxy)	ProxyTypec                   @   s   e Zd ZdZdZdZdS )AuthTypeZBasicZBearerz	X-API-KeyN)__name__
__module____qualname__BASICBEARER	X_API_KEY r   r   K/tmp/pip-unpacked-wheel-3ysq0mf8/selenium/webdriver/remote/client_config.pyr      s   r   c                   @   s  e Zd Zdedejidddddddejdddfee	e
 e	e e	e
 e	e e	e e	e e	e e	e e	e e	e e	e e	e ddddZeed	d
dZejeddddZee
d	ddZeje
ddddZeed	ddZejeddddZee
d	ddZeje
ddddZeed	ddZejeddddZeed	ddZejeddd dZdd	d!d"Zeed	d#d$Zejedd%d&d$Zeed	d'd(Zejeddd)d(Zeed	d*d+Zejeddd,d+Zeed	d-d.Zejeddd/d.Zeed	d0d1Zejeddd2d1Zeed	d3d4Zejeddd5d4Zeed	d6d7Zejeddd8d7Ze	e d	d9d:Ze	e d	d;d<ZdS )=ClientConfigTZ	proxyType)rawFN)remote_server_addr
keep_aliveproxyignore_certificatesinit_args_for_pool_managertimeoutca_certsusernamepassword	auth_typetoken
user_agentextra_headersreturnc                 C   s   || _ || _|| _|| _|pi | _|| _|| _|	| _|
| _|| _	|| _
|| _|d krtdd k	rzttdtt qt n|| _|d krdtjkrtdqt n|| _d S )NZGLOBAL_DEFAULT_TIMEOUTREQUESTS_CA_BUNDLE)r   r   r   r   r   r   r   r   r   r   r   r   osgetenvfloatstrsocketgetdefaulttimeoutenvironcertifiwherer   )selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __init__%   s0    
zClientConfig.__init__)r   c                 C   s   | j S )z+:Returns: The address of the remote server.Z_remote_server_addrr*   r   r   r   r   R   s    zClientConfig.remote_server_addr)valuer   c                 C   s
   || _ dS )z*Provides the address of the remote server.Nr,   r*   r.   r   r   r   r   W   s    c                 C   s   | j S )z:Returns: The keep alive value._keep_aliver-   r   r   r   r   \   s    zClientConfig.keep_alivec                 C   s
   || _ dS )zrToggles the keep alive value.

        :Args:
         - value: whether to keep the http connection alive
        Nr0   r/   r   r   r   r   a   s    c                 C   s   | j S )z@:Returns: The proxy used for communicating to the driver/server._proxyr-   r   r   r   r   j   s    zClientConfig.proxy)r   r   c                 C   s
   || _ dS )zProvides the information for communicating with the driver or
        server.
        For example: Proxy(raw={"proxyType": ProxyType.SYSTEM})

        :Args:
         - value: the proxy information to use to communicate with the driver or server
        Nr2   )r*   r   r   r   r   r   o   s    	c                 C   s   | j S )z-:Returns: The ignore certificate check value.Z_ignore_certificatesr-   r   r   r   r   z   s    z ClientConfig.ignore_certificates)r   r   c                 C   s
   || _ dS )zrToggles the ignore certificate check.

        :Args:
         - value: value of ignore certificate check
        Nr4   )r*   r   r   r   r   r      s    c                 C   s   | j S )zc:Returns: The dictionary of arguments will be appended while
        initializing the pool manager.Z_init_args_for_pool_managerr-   r   r   r   r      s    z'ClientConfig.init_args_for_pool_manager)r   r   c                 C   s
   || _ dS )a%  Provides dictionary of arguments will be appended while initializing the pool manager.
        For example: {"init_args_for_pool_manager": {"retries": 3, "block": True}}

        :Args:
         - value: the dictionary of arguments will be appended while initializing the pool manager
        Nr5   )r*   r   r   r   r   r      s    c                 C   s   | j S )zW:Returns: The timeout (in seconds) used for communicating to the
        driver/server._timeoutr-   r   r   r   r      s    zClientConfig.timeout)r   r   c                 C   s
   || _ dS )zProvides the timeout (in seconds) for communicating with the driver
        or server.

        :Args:
         - value: the timeout (in seconds) to use to communicate with the driver or server
        Nr6   )r*   r   r   r   r   r      s    c                 C   s   t  | _dS )z2Resets the timeout to the default value of socket.N)r%   r&   r7   r-   r   r   r   reset_timeout   s    zClientConfig.reset_timeoutc                 C   s   | j S )z0:Returns: The path to bundle of CA certificates.Z	_ca_certsr-   r   r   r   r      s    zClientConfig.ca_certs)r   r   c                 C   s
   || _ dS )zProvides the path to bundle of CA certificates for establishing
        secure connections.

        :Args:
         - value: the path to bundle of CA certificates for establishing secure connections
        Nr9   )r*   r   r   r   r   r      s    c                 C   s   | j S )zPReturns the username used for basic authentication to the remote
        server.Z	_usernamer-   r   r   r   r      s    zClientConfig.usernamec                 C   s
   || _ dS )zMSets the username used for basic authentication to the remote
        server.Nr:   r/   r   r   r   r      s    c                 C   s   | j S )zPReturns the password used for basic authentication to the remote
        server.Z	_passwordr-   r   r   r   r      s    zClientConfig.passwordc                 C   s
   || _ dS )zMSets the password used for basic authentication to the remote
        server.Nr;   r/   r   r   r   r      s    c                 C   s   | j S )z8Returns the type of authentication to the remote server.Z
_auth_typer-   r   r   r   r      s    zClientConfig.auth_typec                 C   s
   || _ dS )zSets the type of authentication to the remote server if it is not
        using basic with username and password.

        :Args: value - AuthType enum value. For others, please use `extra_headers` instead
        Nr<   r/   r   r   r   r      s    c                 C   s   | j S )z?Returns the token used for authentication to the remote server._tokenr-   r   r   r   r      s    zClientConfig.tokenc                 C   s
   || _ dS )z^Sets the token used for authentication to the remote server if
        auth_type is not basic.Nr=   r/   r   r   r   r      s    c                 C   s   | j S )z6Returns user agent to be added to the request headers.Z_user_agentr-   r   r   r   r      s    zClientConfig.user_agentc                 C   s
   || _ dS )z3Sets user agent to be added to the request headers.Nr?   r/   r   r   r   r      s    c                 C   s   | j S )z1Returns extra headers to be added to the request._extra_headersr-   r   r   r   r      s    zClientConfig.extra_headersc                 C   s
   || _ dS )z.Sets extra headers to be added to the request.Nr@   r/   r   r   r   r      s    c                 C   s   | j j}t| j}|tjkr"dS |tjkrtj	
dtj	
d}|rttj|dD ]F}|dkrj dS t|}|jr|j|jkr dS |j|jkrX dS qXtj	
| jdrdndtj	
| jdrd	nd
S |tjkr| jdr| j jS | j jS dS )z0Returns the proxy URL to use for the connection.Nno_proxyZNO_PROXY,*zhttps://Zhttps_proxy
http_proxyZHTTPS_PROXYZ
HTTP_PROXY)r   
proxy_typer   urlparser   r   ZDIRECTSYSTEMr!   r'   getmapr$   stripsplitnetlocpath
startswithZMANUALZsslProxyrE   )r*   rF   Z
remote_addZ	_no_proxyentryZn_urlr   r   r   get_proxy_url   s,    



zClientConfig.get_proxy_urlc                 C   s   | j tjkrV| jrV| jrV| j d| j }t|dd}dtjj	 d| iS | j tj
kr| jrdtj
j	 d| j iS | j tjkr| jrtjj	 | j iS dS )z8Returns the authorization to add to the request headers.:zutf-8Authorization N)r   r   r   r   r   base64	b64encodeencodedecoder.   r   r   r   )r*   credentialsZencoded_credentialsr   r   r   get_auth_header  s    zClientConfig.get_auth_header) r   r	   r
   r   r   rH   r   r   r$   r   booldictintr+   propertyr   setterr   r   r   r   r   r8   r   r   r   r   r   r   r   rQ   rZ   r   r   r   r   r   $   s   -
			r   )rU   r!   r%   enumr   typingr   urllibr   r(   Zselenium.webdriver.common.proxyr   r   r   r   r   r   r   r   <module>   s   