
    ,h                         d dl Z d dlZd dlZd dlZd dlZ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  ej                  e      Z G d d      Zy)    N)Path)List)Optional)WebDriverExceptionc                   r    e Zd ZdZdedefdZedefd       Z	edee
   defd       Zedee   fd       Zy	)
SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    argsreturnc                 R   t        | j                               g|z   }t        j                         t        j
                  k(  r|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       | j                  |      S )zDetermines the locations of the requested assets.

        :Args:
         - args: the commands to send to the selenium manager binary.
        :Returns: dictionary of assets and their path
        z--debugz--language-bindingpythonz--outputjson)str_get_binaryloggergetEffectiveLevelloggingDEBUGappend_run)selfr	   s     l/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/selenium/webdriver/common/selenium_manager.pybinary_pathszSeleniumManager.binary_paths'   s     D$$&'(4/##%6KK	"()HJFyy    c                  P   t        t              j                  j                  d      } t	        j
                  d      }|| j                  |      } d}t        j                  d      x}"t        j                  d|       t        |      }n| j                         r| }nddddddd	}t        j                  d
v rt        j                         nd}t        j                  dv r$t        j                  dt        j                         |j!                  t        j                  |f      }|t#        dt        j                   d|       t        t              j                  j                  |      }||j%                         st#        d|       t        j                  d|       |S )zDetermines the path of the correct Selenium Manager binary.

        :Returns: The Selenium Manager executable location

        :Raises: WebDriverException if the platform is unsupported
        zselenium-managerEXENSE_MANAGER_PATHz2Selenium Manager set by env SE_MANAGER_PATH to: %szmacos/selenium-managerzwindows/selenium-manager.exezlinux/selenium-manager))darwinany)win32r   )cygwinr   )linuxx86_64)freebsdr"   )openbsdr"   )r!   r#   r$   r   )r#   r$   zFSelenium Manager binary may not be compatible with %s; verify settingsz/Unsupported platform/architecture combination: /z2Unable to obtain working Selenium Manager binary; z$Selenium Manager binary found at: %s)r   __file__parentjoinpath	sysconfigget_config_varwith_suffixosgetenvr   debugexistssysplatformmachinewarninggetr   is_file)compiled_pathexepathenv_pathallowedarchlocations          r   r   zSeleniumManager._get_binary9   su    X--667IJ&&u-?)55c:M#		"344HALLMxX>D!!# D $<"@#A%='?'?G *-9X)X8##%^cD||55giliuiuv{{CLL$#78H(+Z[^[g[gZhhijnio)pqq>((11(;D<t||~$'YZ^Y_%`aa;TBr   c           
         dj                  |       }t        j                  d|       	 t        j                  dk(  r't        j                  | dt
        j                        }nt        j                  | d      }|j                  j                  d      j                  d      }|j                  j                  d      j                  d      }|d	k7  rt        j                  |      ng i d
}t         j#                  |d          |d   }|j$                  r!t        d| d|j$                   d| d|       |S # t        $ r}t        d|       |d}~ww xY w)zExecutes the Selenium Manager Binary.

        :Args:
         - args: the components of the command being executed.
        :Returns: The log string containing the driver location.
         zExecuting process: %sr   T)capture_outputcreationflags)r?   zutf-8
 )logsresultzUnsuccessful command executed: NrC   rD   z; code: )joinr   r.   r0   r1   
subprocessrunCREATE_NO_WINDOWstdoutdecoderstripstderrr   loads	Exceptionr   r   _process_logs
returncode)r	   commandcompleted_procrI   rL   outputerrrD   s           r   r   zSeleniumManager._runi   sG    ((4.,g6		[||w&!+TYcYtYt!u!+T!J#**11':AA$GF#**11':AA$GF+1R<TZZ'bTV=WF 	%%fVn5!$$$1'(>C\C\B]]_`f_ggijpiqr    	[$'Fwi%PQWZZ	[s   CD9 9	EEE	log_itemsc                     | D ]C  }|d   dk(  rt         j                  |d          $|d   dv s,t         j                  |d          E y )NlevelWARNmessage)r   INFO)r   r3   r.   )rU   items     r   rO   zSeleniumManager._process_logs   sJ     	.DG}&tI/g"33T)_-		.r   N)__name__
__module____qualname____doc__r   dictr   staticmethodr   r   r   r   rO    r   r   r   r   !   s{    
 $ $ - - -^ 49   8 .d . .r   r   )r   r   r,   r1   rF   r0   r)   pathlibr   typingr   r   selenium.commonr   	getLoggerr\   r   r   rb   r   r   <module>rg      sF   "   	   
     .			8	$k. k.r   