
    vKg#                         S SK r S SKrS SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  \	" S	5       " S
 S5      5       rg)    N)system)DEVNULL)STDOUT)Popen)
deprecated)WebDriverException)utilsz?Use binary_location property in Firefox Options to set locationc                   l    \ rS rSrSrSS jrS rSS jrS rS r	SS	 jr
S
 rS rS rS rS rS rSrg)FirefoxBinary    zx_ignore_nofocus.soNc                    Xl         U=(       d    [        U l        SU l        [	        5       R                  5       U l        U R                   (       d  U R                  5       U l         U R                   R                  5       (       d  [        S5      e[        R                  R                  5       U l        SU R                  S'   SU R                  S'   SU R                  S'   g)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      i/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/selenium/webdriver/firefox/firefox_binary.py__init__FirefoxBinary.__init__$   s     ' ",W ("99;DO$$&&$;  JJOO-9<56-0/*-0/*    c                     Xl         g )N)r   )r   argss     r    add_command_line_options&FirefoxBinary.add_command_line_optionsE   s     r#   c                 x    Xl         U R                  U R                   R                  5        U R                  US9  g)z\Launches 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_browserFirefoxBinary.launch_browserH   s2    
 %%dll&7&78$$W$5r#   c                     U R                   (       a5  U R                   R                  5         U R                   R                  5         gg)z=Kill the browser.

This is useful when the browser is stuck.
N)processkillwait)r   s    r    r2   FirefoxBinary.killR   s0    
 <<LLLL r#   c                 6   XR                   S'   U R                  S:X  a  U R                  5         U R                  S/nU R                  (       a$  U R                   H  nUR                  U5        M     [        X R                  [        U R                   S9U l	        g )NXRE_PROFILE_PATHlinuxz-foreground)stdoutstderrenv)
r   r   _modify_link_library_pathr   r   appendr   r   r   r1   )r   r,   commandclis       r    r+   &FirefoxBinary._start_from_profile_path[   sw    04,-==G#**,??M2((s# )W^^FPTPaPabr#   c                    Sn[         R                  " U R                  R                  5      (       d  U R                  R                  5       (       a  [        S5      eX!:  a3  U R                  5         [        SU R                  R                   S35      eUS-  n[        R                  " S5        [         R                  " U R                  R                  5      (       d  M  g)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*   portr1   pollr   r2   r,   timesleep)r   r)   counts      r    r-   %FirefoxBinary._wait_until_connectablef   s    &&t||'8'899||  ""(K 
 		( LL--. /GG  QJEJJqM# &&t||'8'899$ r#   c                 X    SSK Jn  SSK Jn  SSK Jn  SSK Jn  SS KnSnSnU H  n U" X(5      n	U" U	S5      n  O   gU(       d  gUR                  U5      S   $ ! [
         a    SSKJnJnJnJn   NXf = f! [         a)     U" X5      n	U" U	S5      n   MX  ! [         a      M  f = ff = f)	Nr   )HKEY_CURRENT_USER)HKEY_LOCAL_MACHINE)OpenKey)
QueryValue)rL   rM   rK   rJ   )z/SOFTWARE\Classes\FirefoxHTML\shell\open\commandz<SOFTWARE\Classes\Applications\firefox.exe\shell\open\command )
_winregrJ   rK   rL   rM   ImportErrorwinregshlexOSErrorsplit)
r   rJ   rK   rL   rM   rR   keysr=   r,   keys
             r    _find_exe_in_registry#FirefoxBinary._find_exe_in_registry}   s    	Z12'* 	
 D
07$S"-	  {{7#A&&7  	ZYY	Z  !"3:C(b1G s:   A A6A32A36
B)B
B% B)$B%%B)c                 *   SnU R                   S:X  ad  SnU R                  U5      nU(       d  Sn[        R                  R	                  U5      (       d"  [        R                  R                  S5      U-   nU$ U R                   S:X  a)  U R                  5       =(       d    U R                  5       nU$ U R                   S:X  a&  [        R                  S:X  a  U R                  5       nU$ S	 H  nU R                  U5      nU(       d  M    U$    [        S
5      e)z$Return the command to start firefox.rN   darwinfirefoxz0/Applications/Firefox.app/Contents/MacOS/firefox~windowsjavant)r[   	iceweaselziCould not find firefox in your system PATH. Please specify the firefox binary location or install firefox)
r   whichr   r,   exists
expanduserrW   _default_windows_locationnameRuntimeError)r   	start_cmdffnames      r    r   $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.	9  3 #U r#   c                    [         R                  " SS5      [         R                  " SS5      /nU HQ  n[         R                  R                  US5      n[         R                  " U[         R
                  5      (       d  MO  Us  $    g)NPROGRAMFILESzC:\Program FileszPROGRAMFILES(X86)zC:\Program Files (x86)zMozilla Firefox\firefox.exerN   )r   getenvr,   joinaccessX_OK)r   program_filesr,   binary_paths       r    rd   'FirefoxBinary._default_windows_location   si    IIn&9:II)+DE
 "D'',,t-KLKyybgg.."" " r#   c                     [         R                  R                  SS5      nU R                  U R                  SS5      nX!-  nX R
                  S'   U R                  U R
                  S'   g )NLD_LIBRARY_PATHrN   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    r;   'FirefoxBinary._modify_link_library_path   s]    !zz~~.?D11$,,wO//>+,*.*D*D,'r#   c                    X#/nSnU H  n[         R                  R                  UR                  U5      n[         R                  R                  U5      (       d  [         R                  " U5        SS KnUR                  [         R                  R                  [         R                  R                  [        5      X`R                  5      U5        XWS-   -  nM     U$ )NrN   r   :)
r   r,   rm   rb   makedirsshutilr   dirname__file__rz   )	r   r*   ru   rv   paths
built_pathr,   library_pathr   s	            r    ry    FirefoxBinary._extract_and_check   s    
D77<<d;L77>>,//L)KKRWW__X%>F`F`acop,,J  r#   c                 X   [         R                  S   R                  [         R                  5       Hv  n[         R                  R                  X!5      n[         R                  " U[         R                  5      (       d  MN  [         R                  R                  U5      (       a  Mt  Us  $    g)zEReturns the fully qualified path by searching Path of the given
name.PATHN)	r   r   rT   pathsepr,   rm   rn   ro   isdir)r   fnamepe	checknames       r    ra   FirefoxBinary.which   sj     **V$**2::6BR/IyyBGG,,RWW]]95M5M   7 r#   )r   r   r   r   r   r1   r*   )NN)   )__name__
__module____qualname____firstlineno__rz   r!   r&   r.   r2   r+   r-   rW   r   rd   r;   ry   ra   __static_attributes__ r#   r    r   r       sH    11B!6 	c.!'F:	Er#   r   )r   rE   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#   