U e5d^@sdZddlZddlZddlZddlZddlZddlZddddddgZGd ddeZ e Z iZ da dadddZddZddZd d ddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGd d!d!eZGd"d#d#eZeZGd$d%d%eZGd&d'd'eZ Gd(d)d)eZ!Gd*d+d+eZ"d,d-Z#d.d/Z$ej%dd0d1krGd2d3d3eZ&ej%d4krGd5d6d6eZ'Gd7d8d8eZ(d9d:Z)e*d;kre)dS)?z?Interfaces for launching and remotely controlling Web browsers.NErroropenopen_new open_new_tabgetregisterc@s eZdZdS)rN)__name__ __module__ __qualname__r r "/usr/lib64/python3.8/webbrowser.pyrsF preferredc CsZtLtdkrt||gt|<|s4trB|tkrBtd|n t|W5QRXdS)zRegister a browser connector.Nr)_lock _tryorderregister_standard_browsers _browserslower_os_preferred_browserinsertappend)nameklassinstancerr r r rsc Cstdkr&ttdkrtW5QRX|dk r6|g}nt}|D]}d|krt|}|ddkrtt|ddSt|Sq>zt|}Wnt k rt |}YnX|ddk r|dS|ddk r>|dSq>t ddS)zCReturn a browser launcher instance appropriate for the environment.N%s&rz!could not locate runnable browser) rrrshlexsplitBackgroundBrowserGenericBrowserrrKeyError _synthesizer)ZusingZ alternativesbrowsercommandr r r r%s,     Tc CsPtdkr&ttdkrtW5QRXtD] }t|}||||r*dSq*dS)aDisplay url using the default browser. If possible, open url in a location determined by new. - 0: the same browser window (the default). - 1: a new browser window. - 2: a new browser page ("tab"). If possible, autoraise raises the window (the default) or not. NTF)rrrrr)urlnew autoraiserr$r r r rGs cCs t|dS)zuOpen url in a new window of the default browser. If not possible, then open url in the only browser window. rrr&r r r rZscCs t|dS)zOpen url in a new page ("tab") of the default browser. If not possible, then the behavior becomes equivalent to open_new(). r)r*r r r rascCs|d}t|sddgStj|}zt|}Wntk rVddgYSX|d}|r||jkrddl }| |}||_ tj||_t |d||dd|gSddgS)aAttempt to synthesize a controller based on existing controllers. This is useful to create a controller when a user specifies a path to an entry in the BROWSER environment variable -- we can copy a general controller to operate using a specific installation of the desired browser in this way. If we can't create a controller in this way, or if there is no executable for the requested browser, return [None, None]. rNr)rr) rshutilwhichospathbasenamerrr"copyrr)r$rcmdrr%Z controllerr1r r r r#is"    r#c@s:eZdZdZdgZdddZddd Zd d Zd d ZdS) BaseBrowserz3Parent class for all browsers. Do not use directly.rcCs||_||_dSN)rr0selfrr r r __init__szBaseBrowser.__init__rTcCstdSr5)NotImplementedErrorr7r&r'r(r r r rszBaseBrowser.opencCs ||dS)Nrr)r7r&r r r rszBaseBrowser.open_newcCs ||dS)Nr+r)r;r r r rszBaseBrowser.open_new_tabN)r4)rT) rr r __doc__argsr8rrrr r r r r3s   r3c@s"eZdZdZddZd ddZdS) r!zVClass for all browsers started with a command and without remote functionality.cCsFt|tr||_dg|_n|d|_|dd|_tj|j|_dS)Nrrr) isinstancestrrr=r.r/r0r6r r r r8s    zGenericBrowser.__init__rTcs|td|jgfdd|jD}z8tjdddkrHt|}ntj|dd}| WStk rvYdSXdS) Nwebbrowser.opencsg|]}|dqSrreplace.0argr*r r sz'GenericBrowser.open..winT) close_fdsF) sysauditrr=platform subprocessPopenwaitOSErrorr7r&r'r(cmdlinepr r*r rs   zGenericBrowser.openN)rTrr r r<r8rr r r r r!s r!c@seZdZdZdddZdS)r zHClass for all browsers which are to be started in the background.rTcs|jgfdd|jD}tdz.r@rHrIT)rJstart_new_sessionF) rr=rKrLrMrNrOpollrQrRr r*r rs  zBackgroundBrowser.openN)rTrr r r<rr r r r r sr c@sDeZdZdZdZdZdZddgZdZdZ dZ d ddZ d d d Z dS) UnixBrowserz=Parent class for all Unix browsers with remote functionality.NFT%actionrc Csg}|r*|jr*t|}|j|}|r*|g}|jg||}|sD|jrLtj}nd}tj|d||jrd|pfd|dd} |rz| d} | WStj k rYdSXn&|jr| dkrdSdSn |  SdS)NTrJstdinstdoutstderrrVF) raise_optsintr backgroundrNDEVNULLrOredirect_stdoutrPZTimeoutExpiredrW) r7r=Zremoter(r&Z raise_optoptrSZinoutrTrcr r r _invokes4        zUnixBrowser._invokercstd|dkr|jnB|dkr,|jn2|dkrN|jdkrF|jq^|jntdd|fdd|jD}d d|D}||d |}|sfd d|jD}||d d Sd SdS) Nr@rrr+zBad 'new' parameter to open(); zexpected 0, 1, or 2, got %scs g|]}|ddqS)rrZrBrDactionr&r r rGsz$UnixBrowser.open..cSsg|] }|r|qSr r rDr r r rGsTcsg|]}|dqSrArBrDr*r r rGsF) rKrL remote_actionremote_action_newwinremote_action_newtabr remote_argsrgr=)r7r&r'r(r=Zsuccessr rhr rs*   zUnixBrowser.open)N)rT) rr r r<r`rbrdrmrjrkrlrgrr r r r rYs #rYc@s(eZdZdZddgZdZdZdZdZdS) Mozillaz$Launcher class for Mozilla browsers.rZrr4z -new-windowz-new-tabTN rr r r<rmrjrkrlrbr r r r rns rnc@s0eZdZdZddgZddgZdZdZdZd Z d S) Netscapez$Launcher class for Netscape browser.-noraisez-raise-remoteopenURL(%s%action)r4 ,new-window,new-tabTN) rr r r<r`rmrjrkrlrbr r r r rp&srpc@s,eZdZdZddgZddgZdZdZdZd S) Galeonz,Launcher class for Galeon/Epiphany browsers.rqr4rZr-nz-wTN) rr r r<r`rmrjrkrbr r r r rv1s rvc@s(eZdZdZddgZdZdZdZdZdS)Chromez)Launcher class for Google Chrome browser.rZrr4 --new-windowTNror r r r rx;s rxc@s(eZdZdZddgZdZdZdZdZdS)Operaz!Launcher class for Opera browser.rZrr4ryTNror r r r rzGs rzc@s,eZdZdZddgZdZdZdZdZdZ dS) Elinksz#Launcher class for Elinks browsers.rrrsr4rtruFN) rr r r<rmrjrkrlrbrdr r r r r{Qsr{c@seZdZdZdddZdS) KonquerorzController for the KDE File Manager (kfm, or Konqueror). See the output of ``kfmclient --commands`` for more information on the Konqueror remote-control interface. rTcCstd||dkrd}nd}tj}ztjd||gd|||d}Wntk rVYnX|dSz tjdd |gd|||dd }Wntk rYnX|dkrdSz tjd d |gd|||dd }Wntk rYd SX|dkSdS)Nr@r+ZnewTabZopenURL kfmclientT)rJr\r]r^ konquerorz--silentr[kfmz-dF)rKrLrNrcrOrQrPrW)r7r&r'r(ridevnullrTr r r rfsN        zKonqueror.openN)rTrXr r r r r|_sr|c@s&eZdZddZddZd ddZd S) Grailc Csddl}ddl}ddl}ddl}tj|d}|t d}tj| || |d}||}|stdS||j |j } |D]T} z| | Wn8tk rzt| Wntk rYnXYqX| SqdS)Nrz .grail-unixz-*)globpwdsockettempfiler.r/joinZ gettempdirgetpwuidgetuidescapeZAF_UNIXZ SOCK_STREAMZconnectrQunlink) r7rrrrZtempdiruserfilenameZmaybessfnr r r _find_grail_rcs,   zGrail._find_grail_rccCs&|}|sdS|||dS)Nrr)rsendclose)r7rirr r r _remotes  z Grail._remoterTcCs2td||r |d|}n|d|}|S)Nr@zLOADNEW zLOAD )rKrLr)r7r&r'r(okr r r rs  z Grail.openN)rT)rr r rrrr r r r rsrcCstdrtddtddtjkr>tdr>tddtddtjkrbtdrbtddtddtjkrtdrtdttdtdrtddtddD]}t|rt|dt|qd D]}t|rt|dt|qtd rtd ttd ntd r"td ttd d D]"}t|r&t|dt |q&td rftd dtd dD]"}t|rjt|dt |qjtdrtddt dtdrtddtdtdrtdt ddS)Nzxdg-openZGNOME_DESKTOP_SESSION_IDz gvfs-openz gnome-openZKDE_FULL_SESSIONr}z x-www-browser)firefoxZ iceweaselZiceape seamonkey)zmozilla-firefoxzmozilla-firebirdfirebirdmozillanetscaperr~)ZgaleonZepiphanyZ skipstone)z google-chromechromeZchromiumzchromium-browseroperaZmosaicZgrail) r,r-rr r.environr|rnrprvrxrzr)r$r r r register_X_browserssD            rc Cs.gatjdkrNtddtdtddtdtddtdtddtdtjdddkrtd ttjtj d d d }dd dddd|fD]}t |rt|dt |qntj dstj dr&z(d}tj|tjd}|}Wn ttjttfk rYnX|attj drt drPtddtdt drltddtdt drtddtdt drtddtdt drtddtddtj kr*tj dtj}||D]>}|dkrt|dd}|d dkrt|dt|ddqdS)!NdarwinMacOSXdefaultrrZsafarirHrIzwindows-defaultZ PROGRAMFILESzC:\Program FileszInternet Explorer\IEXPLORE.EXErrrrrZDISPLAYZWAYLAND_DISPLAYz$xdg-settings get default-web-browser)r^ZTERMz www-browserZlinksZelinksZlynxZw3mZBROWSERr4Tr r)rrKrMrMacOSXOSAScriptWindowsDefaultr.r/rrrr,r-r rrNZ check_outputrcdecodestripFileNotFoundErrorZCalledProcessErrorPermissionErrorNotADirectoryErrorrrr!r{pathsepreverser#)Ziexplorer$r2Z raw_resultresultZ userchoicesrSr r r r s\           rrHrIc@seZdZdddZdS)rrTcCs:td|zt|Wntk r0YdSXdSdS)Nr@FT)rKrLr.Z startfilerQr:r r r rXs  zWindowsDefault.openN)rT)rr r rr r r r rWsrrc@s"eZdZdZddZd ddZdS) ra{Launcher class for Aqua browsers on Mac OS X Optionally specify a browser name on instantiation. Note that this will not work for Aqua browsers if the user has moved the application package after installation. If no browser is specified, the default browser, as specified in the Internet System Preferences panel, will be used. cCs ||_dSr5)rr6r r r r8sszMacOSX.__init__rTc Cstd|d|kstd|kr(d|}tt|}|jdkrPd|dd}n<|jd kr`d }n d |d }d |dd}d|j||f}tdd}|dkrdS| || }| S)Nr@':zfile:ropen location "%s""%22ZOmniWebr4z toWindow %drz OpenURL "%s"ztell application "%s" activate %s %s end tell osascriptwF) rKrLAssertionErrorraboolrrCr.popenwriter) r7r&r'r(scriptZtoWindowr2osapiperfr r r rvs(         z MacOSX.openN)rTrUr r r r ris rc@seZdZddZdddZdS) rcCs ||_dSr5)_namer6r r r r8szMacOSXOSAScript.__init__rTcCsb|jdkrd|dd}nd|j|ddf}tdd}|dkrJdS|||}| S) Nrrrrz tell application "%s" activate open location "%s" end rrF)rrCr.rrr)r7r&r'r(rrrfr r r rs   zMacOSXOSAScript.openN)rT)rr r r8rr r r r rsrc Csddl}dtjd}z|tjddd\}}WnJ|jk r~}z*t|tjdt|tjdtdW5d}~XYnXd}|D]"\}}|dkrd}q|dkrd}qt|dkrt|tjdtd|d}t||td dS) NrzDUsage: %s [-n | -t] url -n: open new window -t: open new tabrZntd)filerwz-tr+) getoptrKargverrorprintr^exitlenr) rZusageZoptsr=msgZnew_winoar&r r r mains,    r__main__)N)N)rT)+r<r.rr,rKrNZ threading__all__ ExceptionrRLockrrrrrrrrrr#objectr3r!r rYrnrprvrxZChromiumrzr{r|rrrrMrrrrrr r r r sR " "O     56AK /