U
    g4                     @   s   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mZ d dl	m
Z
 G dd deeZG d	d
 d
ZG dd dZG dd dZG dd dZG dd dZG dd dedZG dd deZdS )    N)ABCMeta)abstractmethod)Enum)InvalidArgumentException)Proxyc                   @   s   e Zd ZdZdZdZdZdS )PageLoadStrategya  Enum of possible page load strategies.

    Selenium support following strategies:
        * normal (default) - waits for all resources to download
        * eager - DOM access is ready, but other resources like images may still be loading
        * none - does not block `WebDriver` at all

    Docs: https://www.selenium.dev/documentation/webdriver/drivers/options/#pageloadstrategy.
    normaleagernoneN)__name__
__module____qualname____doc__r   r	   r
    r   r   E/tmp/pip-unpacked-wheel-3ysq0mf8/selenium/webdriver/common/options.pyr      s   
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_BaseOptionsDescriptorc                 C   s
   || _ d S Nnameselfr   r   r   r   __init__,   s    z_BaseOptionsDescriptor.__init__c                 C   sz   | j dkr(|jd}|dkp&t|tS | j dkrR|j| j }t|tsNd S |S | j dkrl|j| j dS |j| j S )N
enableBidiwebSocketUrlT)acceptInsecureCertsstrictFileInteractabilitysetWindowRectse:downloadsEnabledF)r   _capsget
isinstancestr)r   objclsvaluer   r   r   __get__/   s    


z_BaseOptionsDescriptor.__get__c                 C   s*   | j dkr|d| n|| j | d S )Nr   r   )r   set_capabilityr   r"   r$   r   r   r   __set__<   s    
z_BaseOptionsDescriptor.__set__N)r   r   r   r   r%   r(   r   r   r   r   r   +   s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_PageLoadStrategyDescriptorzDetermines the point at which a navigation command is returned:
    https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies.

    :param strategy: the strategy corresponding to a document readiness state
    c                 C   s
   || _ d S r   r   r   r   r   r   r   J   s    z$_PageLoadStrategyDescriptor.__init__c                 C   s   |j | jS r   r   r   r   r   r"   r#   r   r   r   r%   M   s    z#_PageLoadStrategyDescriptor.__get__c                 C   s$   |dkr| | j| ntdd S )N)r   r	   r
   z>Strategy can only be one of the following: normal, eager, noner&   r   
ValueErrorr'   r   r   r   r(   P   s    z#_PageLoadStrategyDescriptor.__set__Nr   r   r   r   r   r%   r(   r   r   r   r   r)   C   s   r)   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	"_UnHandledPromptBehaviorDescriptorad  How the driver should respond when an alert is present and the:
    command sent is not handling the alert:
    https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies:

    :param behavior: behavior to use when an alert is encountered

    :returns: Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
    c                 C   s
   || _ d S r   r   r   r   r   r   r   a   s    z+_UnHandledPromptBehaviorDescriptor.__init__c                 C   s   |j | jS r   r*   r+   r   r   r   r%   d   s    z*_UnHandledPromptBehaviorDescriptor.__get__c                 C   s$   |dkr| | j| ntdd S )N)Zdismissacceptzdismiss and notifyzaccept and notifyignoreziBehavior can only be one of the following: dismiss, accept, dismiss and notify, accept and notify, ignorer,   r'   r   r   r   r(   g   s
    z*_UnHandledPromptBehaviorDescriptor.__set__Nr.   r   r   r   r   r/   W   s   	r/   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_TimeoutsDescriptoraL  How long the driver should wait for actions to complete before:
    returning an error https://w3c.github.io/webdriver/#timeouts:

    :param timeouts: values in milliseconds for implicit wait, page load and script timeout

    :returns: Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
    c                 C   s
   || _ d S r   r   r   r   r   r   r   z   s    z_TimeoutsDescriptor.__init__c                 C   s   |j | jS r   r*   r+   r   r   r   r%   }   s    z_TimeoutsDescriptor.__get__c                 C   s2   t dd | D r&|| j| ntdd S )Nc                 s   s   | ]}|d kV  qdS ))ZimplicitZpageLoadscriptNr   ).0xr   r   r   	<genexpr>   s     z._TimeoutsDescriptor.__set__.<locals>.<genexpr>zITimeout keys can only be one of the following: implicit, pageLoad, script)allkeysr&   r   r-   r'   r   r   r   r(      s    z_TimeoutsDescriptor.__set__Nr.   r   r   r   r   r2   q   s   r2   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_ProxyDescriptorz':Returns: Proxy if set, otherwise None.c                 C   s
   || _ d S r   r   r   r   r   r   r      s    z_ProxyDescriptor.__init__c                 C   s   |j S r   )_proxyr+   r   r   r   r%      s    z_ProxyDescriptor.__get__c                 C   s,   t |tstd||_| |j| j< d S )Nz$Only Proxy objects can be passed in.)r    r   r   r:   to_capabilitiesr   r   r'   r   r   r   r(      s    
z_ProxyDescriptor.__set__Nr.   r   r   r   r   r9      s   r9   c                       s   e Zd ZdZedZedZedZedZedZ	edZ
edZed	Zed
ZedZedZedZedZdd fddZedd ZddddZdeje eje eje ddddZedd Zeedd ZddddZ   Z!S ) BaseOptionsz*Base class for individual browser options.ZbrowserVersionZplatformNamer   r   r   r   r   pageLoadStrategyZunhandledPromptBehaviortimeoutsproxyr   Nreturnc                    s6   t    | j| _d | _| dtj d | _d| _	d S )Nr=   F)
superr   default_capabilitiesr   r:   r&   r   r   mobile_options_ignore_local_proxyr   	__class__r   r   r     s    
zBaseOptions.__init__c                 C   s   | j S r   r   rF   r   r   r   capabilities  s    zBaseOptions.capabilitiesc                 C   s   || j |< dS )zSets a capability.NrI   )r   r   r$   r   r   r   r&     s    zBaseOptions.set_capability)android_packageandroid_activitydevice_serialrA   c                 C   s6   |st dd|i| _|r$|| jd< |r2|| jd< dS )zEnables mobile browser use for browsers that support it.

        :Args:
            android_activity: The name of the android package to start
        z!android_package must be passed inZandroidPackageZandroidActivityZandroidDeviceSerialN)AttributeErrorrD   )r   rK   rL   rM   r   r   r   enable_mobile  s    

zBaseOptions.enable_mobilec                 C   s   dS )z-Convert options into capabilities dictionary.Nr   rF   r   r   r   r;     s    zBaseOptions.to_capabilitiesc                 C   s   dS )z6Return minimal capabilities necessary as a dictionary.Nr   rF   r   r   r   rC     s    z BaseOptions.default_capabilitiesc                 C   s
   d| _ dS )aBy calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
        being picked up and used.TN)rE   rF   r   r   r   (ignore_local_proxy_environment_variables  s    z4BaseOptions.ignore_local_proxy_environment_variables)NNN)"r   r   r   r   r   Zbrowser_versionZplatform_nameZaccept_insecure_certsZstrict_file_interactabilityZset_window_rectZenable_bidiZweb_socket_urlr)   Zpage_load_strategyr/   Zunhandled_prompt_behaviorr2   r>   r9   r?   Zenable_downloadsr   propertyrJ   r&   typingOptionalr!   rO   r   r;   rC   rQ   __classcell__r   r   rG   r   r<      sB   
   
r<   )	metaclassc                       sj   e Zd ZdZdZdd fddZedd Zddd	d
Zdd fddZ	dd Z
edd Z  ZS )
ArgOptionsz Binary Location Must be a Stringzfedcm:accountsNr@   c                    s   t    g | _d S r   )rB   r   
_argumentsrF   rG   r   r   r     s    
zArgOptions.__init__c                 C   s   | j S )z5:Returns: A list of arguments needed for the browser.)rX   rF   r   r   r   	arguments  s    zArgOptions.argumentsc                 C   s   |r| j | ntddS )zTAdds an argument to the list.

        :Args:
         - Sets the arguments
        zargument can not be nullN)rX   appendr-   )r   argumentr   r   r   add_argument  s    zArgOptions.add_argumentc                    s   t jdtdd t   dS )rP   a  using ignore_local_proxy_environment_variables in Options has been deprecated, instead, create a Proxy instance with ProxyType.DIRECT to ignore proxy settings, pass the proxy instance into a ClientConfig constructor, pass the client config instance into the Webdriver constructor   )
stacklevelN)warningswarnDeprecationWarningrB   rQ   rF   rG   r   r   rQ     s    	z3ArgOptions.ignore_local_proxy_environment_variablesc                 C   s   | j S r   rI   rF   r   r   r   r;     s    zArgOptions.to_capabilitiesc                 C   s   i S r   r   rF   r   r   r   rC     s    zArgOptions.default_capabilities)r   r   r   ZBINARY_LOCATION_ERRORZFEDCM_CAPABILITYr   rR   rY   r\   rQ   r;   rC   rU   r   r   rG   r   rW     s   
rW   )rS   r_   abcr   r   enumr   Zselenium.common.exceptionsr   Zselenium.webdriver.common.proxyr   r!   r   r   r)   r/   r2   r9   r<   rW   r   r   r   r   <module>   s      W