U
    Pf                     @   s\   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
 ddlmZ G d	d
 d
eZdS )    )WebDriverException)	WebDriver   )DriverFinder   )Options)SafariRemoteConnection)Servicec                       sP   e Zd ZdZdeedd fddZ fddZd	d
 Zdd Z	dd Z
  ZS )r   z>Controls the SafariDriver and allows you to drive the browser.TN)optionsservicereturnc                    s   |r|nt  | _|r|nt }t| j| | j_| jjsD| j  t| jj	||j
d}zt j||d W n tk
r   |    Y nX d| _dS )a  Creates a new Safari driver instance and launches or finds a running
        safaridriver service.

        :Args:
         - keep_alive - Whether to configure SafariRemoteConnection to use
             HTTP keep-alive. Defaults to True.
         - options - Instance of ``options.Options``.
         - service - Service object for handling the browser driver if you need to pass extra details
        )Zremote_server_addr
keep_aliveZignore_proxy)Zcommand_executorr
   FN)r	   r   r   r   Zget_driver_pathpathreuse_servicestartr   Zservice_urlZ_ignore_local_proxysuper__init__	ExceptionquitZ
_is_remote)selfr   r
   r   executor	__class__ G/tmp/pip-unpacked-wheel-ds5t_0qj/selenium/webdriver/safari/webdriver.pyr      s     
zWebDriver.__init__c                    sB   z(zt   W n tk
r$   Y nX W 5 | j js<| j   X dS )z>Closes the browser and shuts down the SafariDriver executable.N)r   r   stopr   r   r   r   r   r   r   r   C   s    
zWebDriver.quitc                 C   s.   t |tstd||i}| dd|i d S )Nz;Value of a session permission must be set to True or False.ZSET_PERMISSIONSpermissions)
isinstanceboolr   execute)r   
permissionvaluepayloadr   r   r   set_permissionR   s    
zWebDriver.set_permissionc                 C   sD   |  dd }|d }|sd S ||kr*d S || }t|ts@d S |S )NZGET_PERMISSIONSr"   r   )r    r   r   )r   r!   r#   r   r"   r   r   r   get_permissionZ   s    
zWebDriver.get_permissionc                 C   s   |  d | d d S )NZATTACH_DEBUGGERz	debugger;)r    Zexecute_scriptr   r   r   r   debugj   s    
zWebDriver.debug)TNN)__name__
__module____qualname____doc__r   r	   r   r   r$   r%   r&   __classcell__r   r   r   r   r      s      %r   N)Zselenium.common.exceptionsr   Z#selenium.webdriver.remote.webdriverr   ZRemoteWebDriverZcommon.driver_finderr   r
   r   Zremote_connectionr   r   r	   r   r   r   r   <module>   s   