3
#+]!                 @   s|   d dl mZ yd dljZW n ek
r6   d dlZY nX 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 )
    )WebDriverExceptionN)DesiredCapabilities)	WebDriver   )Service)SafariRemoteConnectionc               @   sJ   e Zd ZdZdddejdddfddZd	d
 Zdd Zdd Z	dd Z
dS )r   zI
    Controls the SafariDriver and allows you to drive the browser.

    r   z/usr/bin/safaridriverFTNc       	      C   sP   || _ t||||d| _|s&| jj  t| jj|d}tj| ||d d| _dS )a  

        Creates a new Safari driver instance and launches or finds a running safaridriver service.

        :Args:
         - port - The port on which the safaridriver service should listen for new connections. If zero, a free port will be found.
         - executable_path - Path to a custom safaridriver executable to be used. If absent, /usr/bin/safaridriver is used.
         - reuse_service - If True, do not spawn a safaridriver instance; instead, connect to an already-running service that was launched externally.
         - desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
         - quiet - If True, the driver's stdout and stderr is suppressed.
         - keep_alive - Whether to configure SafariRemoteConnection to use
             HTTP keep-alive. Defaults to False.
         - service_args : List of args to pass to the safaridriver service
        )portquietservice_args)Zremote_server_addr
keep_alive)Zcommand_executordesired_capabilitiesFN)	_reuse_servicer   servicestartr   Zservice_urlRemoteWebDriver__init__Z
_is_remote)	selfr   Zexecutable_pathZreuse_servicer   r	   r   r
   executor r   I/tmp/pip-install-ke3synd2/selenium/selenium/webdriver/safari/webdriver.pyr   $   s    
zWebDriver.__init__c             C   sB   z*yt j|  W n tjk
r&   Y nX W d| js<| jj  X dS )z
        Closes the browser and shuts down the SafariDriver executable
        that is started when starting the SafariDriver
        N)r   quithttp_clientBadStatusLiner   r   stop)r   r   r   r   r   E   s    
zWebDriver.quitc             C   s2   t |tstdi }|||< | j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_permissionV   s
    
zWebDriver.set_permissionc             C   sD   | j 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_permission_   s    
zWebDriver.get_permissionc             C   s   | j d | jd d S )NZATTACH_DEBUGGERz	debugger;)r   Zexecute_script)r   r   r   r   debugo   s    
zWebDriver.debug)__name__
__module____qualname____doc__r   ZSAFARIr   r   r!   r"   r#   r   r   r   r   r      s   	r   )Zselenium.common.exceptionsr   http.clientclientr   ImportErrorhttplibZ.selenium.webdriver.common.desired_capabilitiesr   Z#selenium.webdriver.remote.webdriverr   r   r   r   Zremote_connectionr   r   r   r   r   <module>   s   