
    hg["                     f    d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
Z
 G d de          ZdS )    N)system)PopenSTDOUT)WebDriverException)utilsc                   `    e Zd ZdZddZd ZddZd Zd Zdd	Z	d
 Z
d Zd Zd Zd Zd ZdS )FirefoxBinaryzx_ignore_nofocus.soNc                    || _         |pt          t          j        d          | _        d| _        t                                                      | _        | j         s| 	                                | _         | j         
                                st          d          t          j                                        | _        d| j        d<   d| j        d<   d| j        d<   dS )a  
        Creates a new instance of Firefox binary.

        :Args:
         - firefox_path - Path to the Firefox executable. By default, it will be detected from the standard locations.
         - log_file - A file object to redirect the firefox process output to. It can be sys.stdout.
                      Please note that with parallel run the output won't be synchronous.
                      By default, it will be redirected to /dev/null.
        wbNzFailed to find firefox binary. You can set it by specifying the path to 'firefox_binary':

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('/path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)1MOZ_CRASHREPORTER_DISABLEMOZ_NO_REMOTENO_EM_RESTART)
_start_cmdopenosdevnull	_log_filecommand_liner   lowerplatform_get_firefox_start_cmdstripr   environcopy_firefox_env)selffirefox_pathlog_files      b/var/www/fb-scrape/myenv/lib/python3.11/site-packages/selenium/webdriver/firefox/firefox_binary.py__init__zFirefoxBinary.__init__   s     ' ";T"*d%;%; (( 	<"99;;DO$$&& 	<$;< < < JOO--9<56-0/*-0/***    c                     || _         d S )N)r   )r   argss     r    add_command_line_optionsz&FirefoxBinary.add_command_line_options@   s     r"      c                 ~    || _         |                     | j         j                   |                     |           dS )zkLaunches the browser for the given profile name.
        It is assumed the profile already exists.
        )timeoutN)profile_start_from_profile_pathpath_wait_until_connectable)r   r)   r(   s      r    launch_browserzFirefoxBinary.launch_browserC   sA     %%dl&7888$$W$55555r"   c                 |    | j         r4| j                                          | j                                          dS dS )zMKill the browser.

        This is useful when the browser is stuck.
        N)processkillwait)r   s    r    r0   zFirefoxBinary.killL   sF    
 < 	 LL	  	 r"   c                    || j         d<   | j        dk    r|                                  | j        dg}| j        r| j        D ]}|                    |           t          || j        t          | j                   | _	        d S )NXRE_PROFILE_PATHlinuxz-foreground)stdoutstderrenv)
r   r   _modify_link_library_pathr   r   appendr   r   r   r/   )r   r+   commandclis       r    r*   z&FirefoxBinary._start_from_profile_pathU   s    04,-=G##**,,,?M2 	$( $ $s####DN6!# # #r"   c                 p   d}t          j        | j        j                  s| j                                        rt          d          ||k    r0|                                  t          d| j        j        z            |dz  }t          j
        d           t          j        | j        j                  dS )z9Blocks until the extension is connectable in the firefox.r   zThe browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.zCan't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.   T)r   is_connectabler)   portr/   pollr   r0   r+   timesleep)r   r(   counts      r    r,   z%FirefoxBinary._wait_until_connectableb   s    &t|'899 	|  "" L(KL L L 		(G |(	*+ + + QJEJqMMM! &t|'899 	" tr"   c                 ^   	 ddl m}m}m}m} n# t
          $ r ddlm}m}m}m} Y nw xY wdd l}d}d}|D ]X}	  |||          }	 ||	d          } n># t          $ r/ 	  |||          }	 ||	d          }Y  n# t          $ r Y nw xY wY Uw xY wdS |sdS |	                    |          d         S )Nr   )OpenKey
QueryValueHKEY_LOCAL_MACHINEHKEY_CURRENT_USER)z/SOFTWARE\Classes\FirefoxHTML\shell\open\commandz<SOFTWARE\Classes\Applications\firefox.exe\shell\open\command )
_winregrE   rF   rG   rH   ImportErrorwinregshlexOSErrorsplit)
r   rE   rF   rG   rH   rM   keysr:   r+   keys
             r    _find_exe_in_registryz#FirefoxBinary._find_exe_in_registryx   sd   	ZZZZZZZZZZZZZZ 	Z 	Z 	ZYYYYYYYYYYYYYY	ZQ 	 	D
g0$77$*S"--   !'"3T::C(jb11GEE   DD 2 	2{{7##A&&s;    ((A
BA88
BBBB
Bc                    d}| j         dk    rDd}t          j                            |          s"t          j                            d          |z   }n| j         dk    r)|                                 p|                                 }n]| j         dk    r%t          j        dk    r|                                 }n-dD ]}|                     |          }|r nt          d	          |S )
z$Return the command to start firefox.rI   darwinz4/Applications/Firefox.app/Contents/MacOS/firefox-bin~windowsjavant)firefox	iceweaselziCould not find firefox in your system PATH. Please specify the firefox binary location or install firefox)
r   r   r+   exists
expanduserrR   _default_windows_location_namewhichRuntimeError)r   	start_cmdffnames      r    r   z$FirefoxBinary._get_firefox_start_cmd   s   	=H$$NI7>>),, @G..s33i?	]i''3355Y9W9W9Y9YII]f$$T)9)96688II2 V V JJv..	 E #UV V V r"   c                     t          j        dd          t          j        dd          g}|D ]E}t           j                            |d          }t          j        |t           j                  r|c S FdS )NPROGRAMFILESzC:\Program FileszPROGRAMFILES(X86)zC:\Program Files (x86)zMozilla Firefox\firefox.exerI   )r   getenvr+   joinaccessX_OK)r   program_filesr+   binary_paths       r    r]   z'FirefoxBinary._default_windows_location   s|    >3FGG#68QRRT! 	# 	#D',,t-KLLKybg.. #""""#rr"   c                     t           j                            dd          }|                     | j        | j        dd          }||z  }|| j        d<   | j        | j        d<   d S )NLD_LIBRARY_PATHrI   x86amd64
LD_PRELOAD)r   r   get_extract_and_checkr)   NO_FOCUS_LIBRARY_NAMEr   )r   existing_ld_lib_pathnew_ld_lib_paths      r    r8   z'FirefoxBinary._modify_link_library_path   so    !z~~.?DD11L$4eWF F 	///>+,*.*D,'''r"   c                    ||g}d}|D ]}t           j                            |j        |          }t           j                            |          st          j        |           dd l}	|	                    t           j                            t           j                            t                    || j	                  |           ||dz   z  }|S )NrI   r   :)
r   r+   rf   r[   makedirsshutilr   dirname__file__rr   )
r   r)   no_focus_so_namerm   rn   paths
built_pathr+   library_pathrx   s
             r    rq   z FirefoxBinary._extract_and_check   s    e
 
	- 
	-D7<<d;;L7>>,// *L)))MMMKK))*, , 	  
 ,,,JJr"   c                 .   t           j        d                             t           j                  D ]d}t           j                            ||          }t          j        |t           j                  r#t           j                            |          s|c S edS )zLReturns the fully qualified path by searching Path of the given
        namePATHN)	r   r   rO   pathsepr+   rf   rg   rh   isdir)r   fnamepe	checknames       r    r_   zFirefoxBinary.which   s|     *V$**2:66 	! 	!BR//IyBG,, !RW]]95M5M !    tr"   )NN)r&   )__name__
__module____qualname__rr   r!   r%   r-   r0   r*   r,   rR   r   r]   r8   rq   r_    r"   r    r	   r	      s        11 1 1 1B! ! !6 6 6 6     # # #   ,' ' ':  0  	E 	E 	E  $    r"   r	   )r   r   r   
subprocessr   r   selenium.common.exceptionsr   selenium.webdriver.commonr   rA   objectr	   r   r"   r    <module>r      s   & 
			       $ $ $ $ $ $ $ $ 9 9 9 9 9 9 + + + + + +     F     r"   