3 \U@sddlZddlZddlZddlZddlZddddddgZGdddeZiZgZ dNd dZ dOd dZ dPd dZ ddZ ddZdQddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGd d!d!eZeZGd"d#d#eZGd$d%d%eZGd&d'd'eZGd(d)d)eZd*d+Zejj d,rheejj d-rej d.re d.ded.ej d/re d/ded/ej d0re d0ded0ej d1re d1ded1ej d2re d2ded2ej!dd3d4krGd5d6d6eZ"gZ iZe d7e"ej#j$ejj d8d9d:Z%x8d;dd?d@e%fD]"Z&ej e&rde e&dee&qdWej!dAkrGdBdCdCeZ'GdDdEdEeZ(e dFde(dFdRe d;de(d;dSe dGde(dGdTe dCde(dHdUdIejkrpejdIj)ej*Z+e+j,xBe+D]:Z-e-dJkr*ee-dVZ.e.d dkr*e e-dee-dWq*WdZ-[-[+dKdLZ/e0dMkre/dS)XNErroropenopen_new open_new_tabgetregisterc@s eZdZdS)rN)__name__ __module__ __qualname__r r "/usr/lib64/python3.6/webbrowser.pyr scCs<||gt|j<|dkr$tj|n|dkr8tjd|dS)Nr) _browserslower _tryorderappendinsert)nameklassinstanceupdate_tryorderr r r rs  c Cs|dk r|g}nt}x|D]}d|krVtj|}|ddkrLt|ddSt|Sqyt|j}Wntk rt|}YnX|ddk r|dS|ddk r|dSqWt ddS)Nz%sr &rz!could not locate runnable browserr) rshlexsplitBackgroundBrowserGenericBrowserrrKeyError _synthesizer)ZusingZ alternativesbrowsercommandr r r rs$      TcCs,x&tD]}t|}|j|||rdSqWdS)NTF)rrr)urlnew autoraiserrr r r r9s  cCs t|dS)Nr )r)r!r r r r@scCs t|dS)N)r)r!r r r rCsc Cs|jd}tj|sddgStjj|}yt|j}Wntk rRddgSX|d}|r|j|jkrddl }|j |}||_ tjj||_t |d||d|gSddgS)Nrr ) rshutilwhichospathbasenamerrrcopyrr)rrcmdrr Z controllerr*r r r rGs"     rc@s6eZdZdgZdddZdddZd d Zd d Zd S) BaseBrowserz%scCs||_||_dS)N)rr))selfrr r r __init__nszBaseBrowser.__init__rTcCstdS)N)NotImplementedError)r.r!r"r#r r r rrszBaseBrowser.opencCs |j|dS)Nr )r)r.r!r r r ruszBaseBrowser.open_newcCs |j|dS)Nr$)r)r.r!r r r rxszBaseBrowser.open_new_tabN)r-)rT)rr r argsr/rrrr r r r r,is   r,c@seZdZddZdddZdS) rcCsFt|tr||_dg|_n|d|_|dd|_tjj|j|_dS)Nz%srr ) isinstancestrrr1r'r(r))r.rr r r r/s    zGenericBrowser.__init__rTc sl|jgfdd|jD}y6tjdddkrsz'GenericBrowser.open..winT) close_fdsF)rr1sysplatform subprocessPopenwaitOSError)r.r!r"r#cmdlinepr )r!r rs   zGenericBrowser.openN)rT)rr r r/rr r r r r|s rc@seZdZdddZdS)rrTc sp|jgfdd|jD}y:tjdddkr.r8r9T)r:start_new_sessionF)rr1r;r<r=r>pollr@)r.r!r"r#rArBr )r!r rs   zBackgroundBrowser.openN)rT)rr r rr r r r rsrc@s>eZdZdZdZdZddgZdZdZdZ ddZ d d d Z dS) UnixBrowserNFTz%actionz%sc Csg}|r*|jr*t|}|j|}|r*|g}|jg||}|sD|jrLtj}nd}tj|d||jrd|pfd|dd}|ry|jd} | Stj k rdSXn&|jr|j dkrdSdSn |j SdS)NT)r:stdinstdoutstderrrCF) raise_optsintr backgroundr=DEVNULLr>redirect_stdoutr?ZTimeoutExpiredrD) r.r1Zremoter#Z raise_optoptrAZinoutrBrcr r r _invokes0        zUnixBrowser._invokercs|dkr|jnB|dkr |jn2|dkrB|jdkr:|jqR|jntdd|fdd|jD}dd|D}|j|d |}|sfd d|jD}|j|d d Sd SdS) Nrr r$zBad 'new' parameter to open(); zexpected 0, 1, or 2, got %scs g|]}|jdjdqS)z%sz%action)r4)r5r6)actionr!r r r7sz$UnixBrowser.open..cSsg|] }|r|qSr r )r5r6r r r r7sTcsg|]}|jdqS)z%s)r4)r5r6)r!r r r7sF) remote_actionremote_action_newwinremote_action_newtabr remote_argsrQr1)r.r!r"r#r1Zsuccessr )rRr!r rs$    zUnixBrowser.open)rT) rr r rJrLrNrVrSrTrUrQrr r r r rEs#rEc@s$eZdZddgZdZdZdZdZdS)Mozillaz%actionz%sr-z -new-windowz-new-tabTN)rr r rVrSrTrUrLr r r r rWs rWc@s,eZdZddgZddgZdZdZdZdZd S) Netscapez-noraisez-raisez-remotezopenURL(%s%action)r-z ,new-windowz,new-tabTN) rr r rJrVrSrTrUrLr r r r rXs rXc@s(eZdZddgZddgZdZdZdZdS) Galeonz-noraiser-z%actionz%sz-nz-wTN)rr r rJrVrSrTrLr r r r rY s rYc@s$eZdZddgZdZdZdZdZdS)Chromez%actionz%sr-z --new-windowTN)rr r rVrSrTrUrLr r r r rZs rZc@s$eZdZddgZdZdZdZdZdS)Operaz%actionz%sr-z --new-windowTN)rr r rVrSrTrUrLr r r r r["s r[c@s(eZdZddgZdZdZdZdZdZdS)Elinksz-remotezopenURL(%s%action)r-z ,new-windowz,new-tabFN) rr r rVrSrTrUrLrNr r r r r\,s r\c@seZdZdddZdS) KonquerorrTcCs|dkrd}nd}tj}ytjd||gd|||d}Wntk rJYnX|jdSy tjdd|gd|||dd }Wntk rYnX|jdkrdSy tjd d |gd|||dd }Wntk rd SX|jdkSdS) Nr$ZnewTabZopenURL kfmclientT)r:rFrGrH konquerorz--silent)r:rFrGrHrCkfmz-dF)r=rMr>r@r?rD)r.r!r"r#rRdevnullrBr r r rAs:      zKonqueror.openN)rT)rr r rr r r r r]:sr]c@s&eZdZddZddZd ddZd S) Grailc Csddl}ddl}ddl}ddl}tjj|jd}|jtj d}tjj||d}|j|}|shdS|j|j |j } xX|D]P} y| j | Wn8t k rytj| Wnt k rYnXYq~X| Sq~WdS)Nrz .grail-unixz-*)globpwdsockettempfiler'r(joinZ gettempdirgetpwuidgetuidZAF_UNIXZ SOCK_STREAMZconnectr@unlink) r.rcrdrerfZtempdiruserfilenameZmaybessfnr r r _find_grail_rcrs*    zGrail._find_grail_rccCs&|j}|sdS|j||jdS)Nrr )rosendclose)r.rRrmr r r _remotes  z Grail._remoterTcCs&|r|jd|}n|jd|}|S)NzLOADNEW zLOAD )rr)r.r!r"r#okr r r rsz Grail.openN)rT)rr r rorrrr r r r rbnsrbcCstjdrtddtddtjkr>tjdr>tddtddtjkrbtjdrbtddtddtjkrtjdrtdttdtjdrtddtdx&dD]}tj|rt|dt|qWx&dD]}tj|rt|dt|qWtjdrtdttdntjdr*tdttdx*dD]"}tj|r0t|dt |q0Wtjdrrtddtdx*d D]"}tj|rxt|dt |qxWtjdrtddt dtjdrtddtdtjdrtdt ddS)!Nzxdg-openZGNOME_DESKTOP_SESSION_IDz gvfs-openz gnome-openZKDE_FULL_SESSIONr^z x-www-browserfirefox iceweaseliceape seamonkeymozilla-firefoxmozilla-firebirdfirebirdmozillanetscaper`r_galeonepiphanyZ skipstone google-chromechromechromiumchromium-browseroperaZmosaicZgrail)rtrurvrw)rxryrzr{r|)r}r~)rrrr) r%r&rrr'environr]rWrXrYrZr[rb)rr r r register_X_browserssH               rZDISPLAYZTERMz www-browserZlinksZelinksZlynxZw3mr8r9c@seZdZdddZdS)WindowsDefaultrTc Cs,ytj|Wntk r"dSXdSdS)NFT)r'Z startfiler@)r.r!r"r#r r r rs zWindowsDefault.openN)rT)rr r rr r r r rsrzwindows-defaultZ PROGRAMFILESzC:\Program FileszInternet Explorer\IEXPLORE.EXErtrzrwr{r|rdarwinc@seZdZddZdddZdS) MacOSXcCs ||_dS)N)r)r.rr r r r/&szMacOSX.__init__rTc Csd|krd|}tt|}|jdkr8d|jdd}n<|jdkrHd}n d |d }d |jdd}d |j||f}tjd d}|dkrdS|j||j}| S)N:zfile:defaultzopen location "%s""z%22ZOmniWebr-z toWindow %dr z OpenURL "%s"ztell application "%s" activate %s %s end tell osascriptwF)rKboolrr4r'popenwriterq) r.r!r"r#scriptZtoWindowr+osapiperPr r r r)s       z MacOSX.openN)rT)rr r r/rr r r r rs rc@seZdZddZdddZdS) MacOSXOSAScriptcCs ||_dS)N)_name)r.rr r r r/KszMacOSXOSAScript.__init__rTcCsb|jdkrd|jdd}nd|j|jddf}tjdd}|dkrJdS|j||j}| S) Nrzopen location "%s"rz%22z tell application "%s" activate open location "%s" end rrF)rr4r'rrrq)r.r!r"r#rrrPr r r rNs   zMacOSXOSAScript.openN)rT)rr r r/rr r r r rJsrZsafarirrZBROWSERr-c Csddl}dtjd}y|jtjddd\}}WnJ|jk r~}z,t|tjdt|tjdtjdWYdd}~XnXd}x*|D]"\}}|dkrd}q|dkrd}qWt|dkrt|tjdtjd|d}t||td dS) NrzDUsage: %s [-n | -t] url -n: open new window -t: open new tabr Zntd)filez-nz-tr$) getoptr;argverrorprintrHexitlenr) rZusageZoptsr1msgZnew_winoar!r r r main~s(   r__main__)Nr )N)rT)r rrrrrr)1r'rr%r;r=__all__ Exceptionrrrrrrrrrobjectr,rrrErWrXrYrZZChromiumr[r\r]rbrrr&r<rr(rgZiexplorerrrrpathsepZ _userchoicesreverserAr+rrr r r r s    "N     45B          .