
    ,h#                         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	 d dl
mZ d dlmZ  e	d	       G d
 d             Zy)    N)system)DEVNULL)STDOUT)Popen)
deprecated)WebDriverException)utilsz?Use binary_location property in Firefox Options to set locationc                   ^    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y)FirefoxBinaryzx_ignore_nofocus.soNc                    || _         |xs t        | _        d| _        t	               j                         | _        | j                   s| j                         | _         | j                   j                         st        d      t        j                  j                         | _        d| j                  d<   d| j                  d<   d| j                  d<   y)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.
        NzFailed 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_cmdr   	_log_filecommand_liner   lowerplatform_get_firefox_start_cmdstripr   osenvironcopy_firefox_env)selffirefox_pathlog_files      k/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/selenium/webdriver/firefox/firefox_binary.py__init__zFirefoxBinary.__init__$   s     ' ",W ("99;DO$$&$;  JJOO-9<56-0/*-0/*    c                     || _         y )N)r   )r   argss     r   add_command_line_optionsz&FirefoxBinary.add_command_line_optionsE   s
     r!   c                     || _         | j                  | j                   j                         | j                  |       y)zlLaunches 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_browserH   s4    
 %%dll&7&78$$W$5r!   c                     | j                   r5| j                   j                          | j                   j                          yy)zMKill the browser.

        This is useful when the browser is stuck.
        N)processkillwait)r   s    r   r.   zFirefoxBinary.killR   s0    
 <<LLLL r!   c                 0   || j                   d<   | j                  dk(  r| j                          | j                  dg}| j                  r"| j                  D ]  }|j                  |        t        || j                  t        | j                         | _	        y )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_path[   s    04,-==G#**,??M2(( $s#$WT^^FPTPaPabr!   c                    d}t        j                  | j                  j                        s| j                  j                         rt        d      ||k\  r3| j                          t        d| j                  j                   d      |dz  }t        j                  d       t        j                  | j                  j                        sy)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.zzCan't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: zT If you specified a log_file in the FirefoxBinary constructor, check it for details.   T)r	   is_connectabler'   portr-   pollr   r.   r)   timesleep)r   r&   counts      r   r*   z%FirefoxBinary._wait_until_connectablef   s    &&t||'8'89||  "(K 
 		( LL--. /GG  QJEJJqM# &&t||'8'89$ r!   c                 H   	 ddl m} ddl m} ddl m} ddl m} dd l}d}d}|D ]  }	  |||      }	 ||	d      } n y|sy|j                  |      d   S # t
        $ r ddlm}m}m}m} Y Rw xY w# t        $ r( 	  |||      }	 ||	d      }Y  Q# t        $ r Y nw xY wY |w xY w)	Nr   )HKEY_CURRENT_USER)HKEY_LOCAL_MACHINE)OpenKey)
QueryValue)rE   rF   rD   rC   )z/SOFTWARE\Classes\FirefoxHTML\shell\open\commandz<SOFTWARE\Classes\Applications\firefox.exe\shell\open\command )
_winregrC   rD   rE   rF   ImportErrorwinregshlexOSErrorsplit)
r   rC   rD   rE   rF   rK   keysr8   r)   keys
             r   _find_exe_in_registryz#FirefoxBinary._find_exe_in_registry}   s    	Z12'* 	
  	D
0$7$S"-		 {{7#A&&7  	ZYY	Z  !"3T:C(b1G s@   A A0A-,A-0	B!:B	BB!BB! B!c                    d}| j                   dk(  rZd}| j                  |      }|sd}t        j                  j	                  |      s"t        j                  j                  d      |z   }|S | j                   dk(  r$| j                         xs | j                         }|S | j                   dk(  r%t        j                  dk(  r| j                         }|S d	D ]  }| j                  |      }|s |S  t        d
      )z$Return the command to start firefox.rG   darwinfirefoxz0/Applications/Firefox.app/Contents/MacOS/firefox~windowsjavant)rS   	iceweaselziCould not find firefox in your system PATH. Please specify the firefox binary location or install firefox)
r   whichr   r)   exists
expanduserrP   _default_windows_locationnameRuntimeError)r   	start_cmdffnames      r   r   z$FirefoxBinary._get_firefox_start_cmd   s   	==H$F

6*IN	77>>),GG..s3i?	   ]]i'224X8V8V8XI  ]]f$D668I  3 	 JJv.	 	 #U r!   c                     t        j                  dd      t        j                  dd      g}|D ]J  }t         j                  j                  |d      }t        j                  |t         j
                        sH|c S  y)NPROGRAMFILESzC:\Program FileszPROGRAMFILES(X86)zC:\Program Files (x86)zMozilla Firefox\firefox.exerG   )r   getenvr)   joinaccessX_OK)r   program_filesr)   binary_paths       r   r\   z'FirefoxBinary._default_windows_location   sk    IIn&9:II)+DE
 " 	#D'',,t-KLKyybgg.""	# r!   c                     t         j                  j                  dd      }| j                  | j                  dd      }||z  }|| j
                  d<   | j                  | j
                  d<   y )NLD_LIBRARY_PATHrG   x86amd64
LD_PRELOAD)r   r   get_extract_and_checkr'   r   NO_FOCUS_LIBRARY_NAME)r   existing_ld_lib_pathnew_ld_lib_paths      r   r6   z'FirefoxBinary._modify_link_library_path   sb    !zz~~.?D11$,,wO///>+,*.*D*D,'r!   c                    ||g}d}|D ]  }t         j                  j                  |j                  |      }t         j                  j                  |      st        j                  |       dd l}|j                  t         j                  j                  t         j                  j                  t              || j                        |       ||dz   z  } |S )NrG   r   :)
r   r)   rd   rZ   makedirsshutilr   dirname__file__rp   )	r   r'   rk   rl   paths
built_pathr)   library_pathrv   s	            r   ro   z FirefoxBinary._extract_and_check   s    e
 	-D77<<d;L77>>,/L)KKRWW__X%>dF`F`acop,,,J	- r!   c                 >   t         j                  d   j                  t         j                        D ]j  }t         j                  j                  ||      }t        j                  |t         j                        sHt         j                  j                  |      rh|c S  y)zMReturns the fully qualified path by searching Path of the given
        name.PATHN)	r   r   rM   pathsepr)   rd   re   rf   isdir)r   fnamepe	checknames       r   rY   zFirefoxBinary.which   sk     **V$**2::6 	!BR/IyyBGG,RWW]]95M  	! r!   )NN)   )__name__
__module____qualname__rp   r    r$   r+   r.   r(   r*   rP   r   r\   r6   ro   rY    r!   r   r   r       sH    11B!6 	c.!'F:	Er!   r   )r   r?   r   r   
subprocessr   r   r   typing_extensionsr   selenium.common.exceptionsr   selenium.webdriver.commonr	   r   r   r!   r   <module>r      sE   & 
      ( 9 + MNF F OFr!   