@sdZddlZddlZddlZddlZddlZddddddgZGd ddeZiZ gZ dd d dZ dd dZ dd ddZ ddZddZd ddZGdddeZGdddeZGdddeZGdddeZGdddeZeZGdddeZGdd d eZeZGd!d"d"eZGd#d$d$eZGd%d&d&eZGd'd(d(eZd)d*Zej j d+renej j d,rej!d-r6e d-ded-nej!d.r^e d.ded.nej!d/re d/ded/nej!d0re d0ded0nej!d1re d1ded1qnej"dd2d3krGd4d5d5eZ#gZ iZ e d6e#ej$j%ej j d7d8d9Z&xNd:d;d<d=d>d?e&fD].Z'ej!e'rae e'dee'qaqaWnej"d@krGdAdBdBeZ(GdCdDdDeZ)e dEde)dEdLe d:de)d:dMe dBde)dFdNndGej krej dGj*ej+Z,e,j-xXe,D]PZ.e.dHkrXee.dOZ/e/d dkre e.dee.dPqqXqXWdZ.[.[,ndIdJZ0e1dKkre0ndS)Qz?Interfaces for launching and remotely controlling Web browsers.NErroropenopen_new open_new_tabgetregisterc@seZdZdS)rN)__name__ __module__ __qualname__r r /usr/lib/python3.4/webbrowser.pyr s cCsU||gt|j<|dkr2tj|n|dkrQtjd|ndS)z9Register a browser connector and, optionally, connection.rN) _browserslower _tryorderappendinsert)nameklassinstanceupdate_tryorderr r r rs   c Cs|dk r|g}nt}x|D]}d|krwtj|}|ddkrjt|ddSt|Sq%yt|j}Wntk rt|}YnX|ddk r|dS|ddk r%|dSq%Wt ddS) zCReturn a browser launcher instance appropriate for the environment.Nz%sr &rz!could not locate runnable browserr) rshlexsplitBackgroundBrowserGenericBrowserrrKeyError _synthesizer)ZusingZ alternativesbrowsercommandr r r rs$      TcCs:x3tD]+}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|s)ddgStjj|}yt|j}Wntk rmddgSYnX|d}|r|j|jkrddl }|j |}||_ tjj||_t |d||d|gSddgS)aAttempt to synthesize a controller base 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 ) rshutilwhichospathbasenamerrrcopyrr)rrcmdrr Z controllerr*r r r rGs"       rc@sXeZdZdZdgZdddZdddd Zd d Zd d ZdS) BaseBrowserz3Parent class for all browsers. Do not use directly.z%scCs||_||_dS)N)rr))selfrr r r __init__ns zBaseBrowser.__init__rTcCs tdS)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) rr r __doc__argsr/rrrr r r r r,is   r,c@s4eZdZdZddZddddZdS) rzVClass for all browsers started with a command and without remote functionality.cCsct|tr'||_dg|_n |d|_|dd|_tjj|j|_dS)Nz%srr ) isinstancestrrr2r'r(r))r.rr r r r/s   zGenericBrowser.__init__rTc s|jgfdd|jD}yOtjdddkrTtj|}ntj|dd}|j SWntk rdSYnXdS)Ncs"g|]}|jdqS)z%s)replace).0arg)r!r r s z'GenericBrowser.open..win close_fdsTF)rr2sysplatform subprocessPopenwaitOSError)r.r!r"r#cmdlinepr )r!r rs zGenericBrowser.openN)rr r r1r/rr r r r r|s  rc@s(eZdZdZddddZdS)rzHClass for all browsers which are to be started in the background.rTc s|jgfdd|jD}yZtjdddkrTtj|}ntj|dddd}|jdkSWntk rdSYnXdS) Ncs"g|]}|jdqS)z%s)r5)r6r7)r!r r r8s z*BackgroundBrowser.open..r9r:r;Tstart_new_sessionF)rr2r<r=r>r?pollrA)r.r!r"r#rBrCr )r!r rs  zBackgroundBrowser.openN)rr r r1rr r r r rs rc@sdeZdZdZdZdZdZddgZdZdZ dZ ddZ d dd d Z dS) UnixBrowserz=Parent class for all Unix browsers with remote functionality.NFTz%actionz%sc Cs&g}|rC|jrCt|}|j|}|rC|g}qCn|jg||}|sf|jrrtj}nd}tj|ddd|d|jr|pdd|dd}|ry|jd} | SWq"tj k rdSYq"Xn1|jr|j dkrdSdSn |j SdS) Nr;TstdinstdoutstderrrDF) raise_optsintr backgroundr>DEVNULLr?redirect_stdoutr@ZTimeoutExpiredrE) r.r2Zremoter#Z raise_optZoptrBZinoutrCrcr r r _invokes0      zUnixBrowser._invokercs|dkr|jn_|dkr0|jnG|dkrc|jdkrW|jqw|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)r5)r6r7)actionr!r r r8s z$UnixBrowser.open..cSsg|]}|r|qSr r )r6r7r r r r8s Tcs"g|]}|jdqS)z%s)r5)r6r7)r!r r r8s F) remote_actionremote_action_newwinremote_action_newtabr remote_argsrQr2)r.r!r"r#r2successr )rRr!r rs$        zUnixBrowser.open) rr r r1rKrMrOrVrSrTrUrQrr r r r rFs   #rFc@sFeZdZdZddgZddgZdZdZdZd Z d S) Mozillaz-Launcher class for Mozilla/Netscape browsers.z-noraisez-raisez-remotezopenURL(%s%action)r-z ,new-windowz,new-tabTN) rr r r1rKrVrSrTrUrMr r r r rXs   rXc@s@eZdZdZddgZddgZdZdZdZd S) Galeonz,Launcher class for Galeon/Epiphany browsers.z-noraiser-z%actionz%sz-nz-wTN) rr r r1rKrVrSrTrMr r r r rYs   rYc@s:eZdZdZddgZdZdZdZdZdS)Chromez)Launcher class for Google Chrome browser.z%actionz%sr-z --new-windowTN) rr r r1rVrSrTrUrMr r r r rZs  rZc@sFeZdZdZddgZddgZdZdZdZdZ d S) Operaz!Launcher class for Opera browser.z-noraiser-z-remotezopenURL(%s%action)z ,new-windowz ,new-pageTN) rr r r1rKrVrSrTrUrMr r r r r[s   r[c@s@eZdZdZddgZdZdZdZdZdZ dS) Elinksz#Launcher class for Elinks browsers.z-remotezopenURL(%s%action)r-z ,new-windowz,new-tabFN) rr r r1rVrSrTrUrMrOr r r r r\%s  r\c@s(eZdZdZddddZdS) KonquerorzController for the KDE File Manager (kfm, or Konqueror). See the output of ``kfmclient --commands`` for more information on the Konqueror remote-control interface. rTc"CsG|dkrd}nd}tj}y4tjd||gddd|d|d |}Wntk rlYnX|jdSy:tjd d |gddd|d|d |d d}Wntk rYnX|jdkrdSy:tjd d|gddd|d|d |d d}Wntk r2dSYnX|jdkSdS)Nr$ZnewTabZopenURL kfmclientr;TrGrHrI konquerorz--silentrDkfmz-dF)r>rNr?rAr@rE)r.r!r"r#rRdevnullrCr r r r:s:               zKonqueror.openN)rr r r1rr r r r r]3s r]c@s:eZdZddZddZddddZd S) Grailc Csddl}ddl}ddl}ddl}tjj|jd}|jtj d}tjj||d}|j|}|sdS|j|j |j } x^|D]V} y| j | Wn8t k rytj| Wnt k rYnXYqX| SqWdS)Nrz .grail-unixz-*)globpwdsockettempfiler'r(joinZ gettempdirgetpwuidgetuidZAF_UNIXZ SOCK_STREAMZconnectrAunlink) r.rcrdrerfZtempdiruserfilenameZmaybessfnr r r _find_grail_rcks*         zGrail._find_grail_rccCs1|j}|sdS|j||jdS)Nrr )rosendclose)r.rRrmr r r _remotes    z Grail._remoterTcCs3|r|jd|}n|jd|}|S)NzLOADNEW zLOAD )rr)r.r!r"r#okr r r rsz Grail.openN)rr r rorrrr r r r rbgs   rbc Cstjdr(tddtdndtjkr_tjdr_tddtdndtjkrtjdrtddtdndtjkrtjdrtdttdntjdrtddtdnx6dD].}tj|rt|dt|qqWtjdrVtdttdn(tjdr~tdttdnx6dD].}tj|rt|dt|qqWtjdrtddtdnx6dD].}tj|rt|dt |qqWtjdr@tddt dntjdrhtddtdntjdrtdt dndS) Nzxdg-openZGNOME_DESKTOP_SESSION_IDz gvfs-openz gnome-openZKDE_FULL_SESSIONr^z x-www-browsermozilla-firefoxfirefoxmozilla-firebirdfirebird iceweaseliceape seamonkeymozillanetscaper`r_galeonepiphanyZ skipstone google-chromechromechromiumchromium-browseroperaZmosaicZgrail) rtrurvrwrxryrzr{r|)r}r~)rrrr) r%r&rrr'environr]rXrYrZr[rb)rr r r register_X_browserssD   rZDISPLAYZTERMz www-browserZlinksZelinksZlynxZw3mr9r:c@s"eZdZddddZdS)WindowsDefaultrTc Cs2ytj|Wntk r)dSYnXdSdS)NFT)r'Z startfilerA)r.r!r"r#r r r rs   zWindowsDefault.openN)rr r rr r r r rs rzwindows-defaultZ PROGRAMFILESzC:\Program FileszInternet Explorer\IEXPLORE.EXErurwrzr{r|rdarwinc@s4eZdZdZddZddddZdS) MacOSXa{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 ||_dS)N)r)r.rr r r r/szMacOSX.__init__rTc Csd|kstd|kr+d|}ntt|}|jdkred|jdd}nR|jdkr}d }nd |d }d |jdd}d |j||f}tjdd}|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) AssertionErrorrLboolrr5r'popenwriterq) r.r!r"r#scriptZtoWindowr+osapiperPr r r rs"      z MacOSX.openN)rr r r1r/rr r r r rs  rc@s.eZdZddZddddZdS)MacOSXOSAScriptcCs ||_dS)N)_name)r.rr r r r/@szMacOSXOSAScript.__init__rTcCs|jdkr(d|jdd}nd|j|jddf}tjdd}|dkridS|j||j}| S) Nrzopen location "%s"rz%22z tell application "%s" activate open location "%s" end rrF)rr5r'rrrq)r.r!r"r#rrrPr r r rCs   zMacOSXOSAScript.openN)rr r r/rr r r r r?s  rZsafarirZBROWSERr-c CsEddl}dtjd}y)|jtjddd\}}Wn[|jk r}z8t|dtjt|dtjtjdWYdd}~XnXd}x>|D]6\}}|dkrd}q|dkrd}qqWt|dkr t|dtjtjdn|d}t||td dS) NrzDUsage: %s [-n | -t] url -n: open new window -t: open new tabr Zntdfilez-nz-tr$) getoptr<argverrorprintrIexitlenr) rZusageZoptsr2msgZnew_winoar!r r r mainrs( )     r__main__rrrrr)2r1r'rr%r<r>__all__ Exceptionrrrrrrrrrobjectr,rrrFrXZNetscaperYrZZChromiumr[r\r]rbrrr&r=rr(rgZiexplorerrrrpathsepZ _userchoicesreverserBr+rrr r r r s       "N    45 >     .   #