U
    b*                     @   s2   d Z G dd dZG dd dZG dd dZdS )z
The Proxy implementation.
c                   @   s   e Zd ZdZedd ZdS )ProxyTypeFactoryz"
    Factory for proxy types.
    c                 C   s
   | |dS )NZff_valuestring r   r   r   C/tmp/pip-unpacked-wheel-3sqd7awy/selenium/webdriver/common/proxy.pymake   s    zProxyTypeFactory.makeN)__name__
__module____qualname____doc__staticmethodr   r   r   r   r   r      s   r   c                   @   sp   e Zd ZdZeddZeddZeddZedd	Z	ed
dZ
eddZeddZedd ZdS )	ProxyTypez
    Set of possible types of proxy.

    Each proxy type has 2 properties:
       'ff_value' is value of Firefox profile preference,
       'string' is id of proxy type.
        DIRECT   MANUAL   PAC   Z	RESERVED1   
AUTODETECT   SYSTEM   UNSPECIFIEDc                 C   sv   t |trd|kr|d }t| }t| D ]4}t| |}t |tr.d|kr.|d |kr.|  S q.td| d S )Nr   zNo proxy type is found for )
isinstancedictstrupperdirgetattr	Exception)clsvalueattr
attr_valuer   r   r   load2   s    

zProxyType.loadN)r   r   r	   r
   r   r   r   r   r   Z
RESERVED_1r   r   r   classmethodr%   r   r   r   r   r   !   s   r   c                   @   sv  e Zd ZdZejZdZdZdZ	dZ
dZdZdZdZdZdZd,ddZedd Zejd	d Zed
d Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd  Zejd!d  Zed"d# Zejd$d# Zed%d& Zejd'd& Zd(d) Zd*d+ Z dS )-ProxyzS
    Proxy contains information about proxy type and necessary proxy settings.
    F Nc                 C   s6  |r2d|kr&|d r&t |d | _d|kr@|d r@|d | _d|krZ|d rZ|d | _d|krt|d rt|d | _d|kr|d r|d | _d|kr|d r|d | _d|kr|d r|d | _d|kr|d r|d | _	d	|kr|d	 r|d	 | _
d
|kr|d
 r|d
 | _d|kr2|d r2|d | _dS )z~
        Creates a new Proxy.

        :Args:
         - raw: raw proxy data. If None, default class values are used.
        	proxyTypeftpProxy	httpProxynoProxyproxyAutoconfigUrlsslProxy
autodetect
socksProxysocksUsernamesocksPasswordsocksVersionN)r   r%   
proxy_type	ftp_proxy
http_proxyno_proxyproxy_autoconfig_urlr.   auto_detectsocks_proxysocks_usernamesocks_passwordsocks_version)selfrawr   r   r   __init__O   s.    








zProxy.__init__c                 C   s   | j S )z4
        Returns proxy type as `ProxyType`.
        )r)   r>   r   r   r   r4   n   s    zProxy.proxy_typec                 C   s   |  | || _dS )zT
        Sets proxy type.

        :Args:
         - value: The proxy type.
        N) _verify_proxy_type_compatibilityr)   r>   r"   r   r   r   r4   u   s    
c                 C   s   | j S )z-
        Returns autodetect setting.
        )r/   rA   r   r   r   r9      s    zProxy.auto_detectc                 C   s<   t |tr0| j|k	r8| tj tj| _|| _ntddS )zb
        Sets autodetect setting.

        :Args:
         - value: The autodetect value.
        z,Autodetect proxy value needs to be a booleanN)r   boolr/   rB   r   r   r)   
ValueErrorrC   r   r   r   r9      s    

c                 C   s   | j S )z,
        Returns ftp proxy setting.
        )r*   rA   r   r   r   r5      s    zProxy.ftp_proxyc                 C   s   |  tj tj| _|| _dS )z`
        Sets ftp proxy setting.

        :Args:
         - value: The ftp proxy value.
        N)rB   r   r   r)   r*   rC   r   r   r   r5      s    c                 C   s   | j S )z-
        Returns http proxy setting.
        )r+   rA   r   r   r   r6      s    zProxy.http_proxyc                 C   s   |  tj tj| _|| _dS )zb
        Sets http proxy setting.

        :Args:
         - value: The http proxy value.
        N)rB   r   r   r)   r+   rC   r   r   r   r6      s    c                 C   s   | j S )z*
        Returns noproxy setting.
        )r,   rA   r   r   r   r7      s    zProxy.no_proxyc                 C   s   |  tj tj| _|| _dS )z\
        Sets noproxy setting.

        :Args:
         - value: The noproxy value.
        N)rB   r   r   r)   r,   rC   r   r   r   r7      s    c                 C   s   | j S )z7
        Returns proxy autoconfig url setting.
        )r-   rA   r   r   r   r8      s    zProxy.proxy_autoconfig_urlc                 C   s   |  tj tj| _|| _dS )zv
        Sets proxy autoconfig url setting.

        :Args:
         - value: The proxy autoconfig url value.
        N)rB   r   r   r)   r-   rC   r   r   r   r8      s    c                 C   s   | j S )z.
        Returns https proxy setting.
        )r.   rA   r   r   r   	ssl_proxy   s    zProxy.ssl_proxyc                 C   s   |  tj tj| _|| _dS )zd
        Sets https proxy setting.

        :Args:
         - value: The https proxy value.
        N)rB   r   r   r)   r.   rC   r   r   r   rF      s    c                 C   s   | j S )z.
        Returns socks proxy setting.
        )r0   rA   r   r   r   r:      s    zProxy.socks_proxyc                 C   s   |  tj tj| _|| _dS )zd
        Sets socks proxy setting.

        :Args:
         - value: The socks proxy value.
        N)rB   r   r   r)   r0   rC   r   r   r   r:      s    c                 C   s   | j S )z7
        Returns socks proxy username setting.
        )r1   rA   r   r   r   r;   	  s    zProxy.socks_usernamec                 C   s   |  tj tj| _|| _dS )zv
        Sets socks proxy username setting.

        :Args:
         - value: The socks proxy username value.
        N)rB   r   r   r)   r1   rC   r   r   r   r;     s    c                 C   s   | j S )z7
        Returns socks proxy password setting.
        )r2   rA   r   r   r   r<     s    zProxy.socks_passwordc                 C   s   |  tj tj| _|| _dS )zv
        Sets socks proxy password setting.

        :Args:
         - value: The socks proxy password value.
        N)rB   r   r   r)   r2   rC   r   r   r   r<   #  s    c                 C   s   | j S )z6
        Returns socks proxy version setting.
        )r3   rA   r   r   r   r=   /  s    zProxy.socks_versionc                 C   s   |  tj tj| _|| _dS )zt
        Sets socks proxy version setting.

        :Args:
         - value: The socks proxy version value.
        N)rB   r   r   r)   r3   rC   r   r   r   r=   6  s    c                 C   s2   | j tjkr.| j |kr.td| d| j  dd S )NzSpecified proxy type (z') not compatible with current setting ())r)   r   r   r    )r>   ZcompatibleProxyr   r   r   rB   B  s    z&Proxy._verify_proxy_type_compatibilityc                 C   s   i }| j d |d< | jr"| j|d< | jr2| j|d< | jrB| j|d< | jrR| j|d< | jrb| j|d< | jrr| j|d< | jr| j|d	< | jr| j|d
< | j	r| j	|d< | j
r| j
|d< ||d< dS )z
        Adds proxy information as capability in specified capabilities.

        :Args:
         - capabilities: The capabilities to which proxy will be added.
        r   r)   r/   r*   r+   r-   r.   r,   r0   r1   r2   r3   proxyN)r)   r/   r*   r+   r-   r.   r,   r0   r1   r2   r3   )r>   ZcapabilitiesZ
proxy_capsr   r   r   add_to_capabilitiesF  s.    









zProxy.add_to_capabilities)N)!r   r   r	   r
   r   r   r)   r/   r*   r+   r,   r-   r.   r0   r1   r2   r3   r@   propertyr4   setterr9   r5   r6   r7   r8   rF   r:   r;   r<   r=   rB   rI   r   r   r   r   r'   >   sv   























r'   N)r
   r   r   r'   r   r   r   r   <module>   s   
