1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
U
\±d!ã@sÎddlZddlZddlZddlZddlZddlmZddlmZddlm    Z    ddlm
Z
ddlm Z ddl m Z ddlmZdd    lmZdd
lmZdd lmZdd lmZe e¡Zd ZGdd„deƒZdS)éN)ÚABC)Úabstractmethod)Úsystem)ÚDEVNULL)ÚPIPE)Úsleep)Úrequest)ÚURLError)ÚWebDriverException)ÚSubprocessStdAlias)ÚutilsTc@seZdZdZdeddfeeeej    ej
ej ej fej    eddœdd„Z e edœdd    „ƒZeejedœd
d „ƒZe edœd d „ƒZejeddœdd „ƒZddœdd„Zddœdd„Zedœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zeddœdd „ZdS)!ÚServiceacThe abstract base class for all service objects.  Services typically
    launch a child program in a new process as an interim process to
    communicate with a browser.
 
    :param executable: install path of the executable.
    :param port: Port for the service to run on, defaults to 0 where the operating system will decide.
    :param log_file: (Optional) file descriptor (pos int) or file object with a valid file descriptor.
        subprocess.PIPE & subprocess.DEVNULL are also valid values.
    :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
    rN)Ú
executableÚportÚlog_fileÚenvÚstart_error_messageÚreturncKsj||_|pt ¡|_ts,|tkr,ttjdƒn||_    |p8d|_
|  di¡|_ |j   dd¡|_ |pbtj|_dS)NÚwbÚÚpopen_kwÚcreation_flagsr)Ú_pathr Z    free_portrÚ_HAS_NATIVE_DEVNULLrÚopenÚosÚdevnullrrÚpoprrÚenvironr)ÚselfrrrrrÚkwargs©r!úXd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\selenium/webdriver/common/service.pyÚ__init__5s    
zService.__init__)rcCsdt d|j¡›S)zGets the url of the Service.zhttp://Ú    localhost)r Zjoin_host_portr©rr!r!r"Ú service_urlGszService.service_urlcCs tdƒ‚dS)z7A List of program arguments (excluding the executable).z2This method needs to be implemented in a sub classN)ÚNotImplementedErrorr%r!r!r"Úcommand_line_argsLszService.command_line_argscCs|jS©N)rr%r!r!r"ÚpathQsz Service.path)ÚvaluercCst|ƒ|_dSr))Ústrr)rr+r!r!r"r*UscCsP| |j¡d}| ¡| ¡r"qL|d7}tdƒ|dkrtd|j›ƒ‚qdS)z³Starts the Service.
 
        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        régà?é<zCan not connect to the Service N)Ú_start_processrÚassert_process_still_runningÚis_connectablerr
)rÚcountr!r!r"ÚstartYs z Service.startcCs(|j ¡}|r$td|j›d|›ƒ‚dS)z1Check if the underlying process is still running.zService z' unexpectedly exited. Status code was: N)ÚprocessÚpollr
r)rZ return_coder!r!r"r0ms
z$Service.assert_process_still_runningcCs t |j¡S)zfEstablishes a socket connection to determine if the service running
        on the port is accessible.)r r1rr%r!r!r"r1sszService.is_connectablecCsTzt |j›d¡Wntk
r,YdSXtdƒD]}| ¡sFqPtdƒq6dS)zcDispatch an HTTP request to the shutdown endpoint for the service in
        an attempt to stop it.z    /shutdownNér-)rÚurlopenr&r    Úranger1r)rÚ_r!r!r"Úsend_remote_shutdown_commandxs z$Service.send_remote_shutdown_commandcCs€|jtkrH|jtkrtsHzt|jdƒr0|j ¡Wntk
rFYnX|jdk    r|z | ¡Wnt    k
rrYnX| 
¡dS)zStops the service.ÚcloseN) rrrrÚhasattrr;Ú    Exceptionr4r:Ú    TypeErrorÚ_terminate_processr%r!r!r"Ústop…s 
 z Service.stopc    CsÄzœ|jj|jj|jj}}}|||fD]&}z | ¡Wq(tk
rLYq(Xq(|j ¡z|j d¡Wn.tj    k
r˜t
j ddd|j  ¡YnXWn"t k
r¾t
j dddYnXdS)a#Terminate the child process.
 
        On POSIX this attempts a graceful SIGTERM followed by a SIGKILL,
        on a Windows OS kill is an alias to terminate.  Terminating does
        not raise itself if something has gone wrong but (currently)
        silently ignores errors here.
        r.zTService process refused to terminate gracefully with SIGTERM, escalating to SIGKILL.T)Úexc_infoz"Error terminating service process.N)r4ÚstdinÚstdoutÚstderrr;ÚAttributeErrorÚ    terminateÚwaitÚ
subprocessÚ TimeoutErrorÚloggerÚerrorÚkillÚOSError)rrBrCrDÚstreamr!r!r"r?–s$ 
þzService._terminate_processcCs&z | ¡Wntk
r YnXdSr))r@r=r%r!r!r"Ú__del__±s zService.__del__)r*rc CsX|g}| | ¡¡|j dtƒdk¡}zLtj|f|j||j|jt    |j
dœ|j—Ž|_ t   d|j›d|j j›¡WnÞtk
rŠ‚YnÊtk
r}z^|jtjkrÈtdtj |j¡›d|j›ƒ‚|jtjkrôtdtj |j¡›d|j›ƒ‚‚W5d    }~XYnNtk
rR}z.td
tj |j¡›d |j›d t|ƒ›ƒ‚W5d    }~XYnXd    S) zmCreates a subprocess by executing the command provided.
 
        :param cmd: full command to execute
        Ú    close_fdsÚWindows)rrPrCrDrBÚ creationflagszStarted executable: `z` in a child process with pid: ú'z"' executable needs to be in PATH. z)' executable may have wrong permissions. NzThe executable z$ needs to be available in the path. Ú
)Úextendr(rrrrHÚPopenrrrrr4rJÚdebugrÚpidr>rMÚerrnoÚENOENTr
rr*ÚbasenamerÚEACCESr=r,)rr*ÚcmdZclose_file_descriptorsÚerrÚer!r!r"r/¼sBÿùø
  ÿ ÿ$ÿzService._start_process)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr,Úintr ÚtypingÚOptionalÚMappingÚAnyr#Úpropertyr&rÚListr(r*Úsetterr3r0Úboolr1r:r@r?rOr/r!r!r!r"r )s:úø   r )rYÚloggingrrHreÚabcrrÚplatformrrrÚtimerÚurllibrÚ urllib.errorr    Zselenium.common.exceptionsr
Zselenium.typesr Zselenium.webdriver.commonr Ú    getLoggerr`rJrr r!r!r!r"Ú<module>s$