3 \U@sdZddlZddlZddlZddlZddlZddddddgZGd ddeZiZ gZ dOd dZ dPd dZ dQddZ ddZddZdRddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZGd!d"d"eZeZGd#d$d$eZGd%d&d&eZGd'd(d(eZGd)d*d*eZd+d,Zej j d-rleej j d.rej!d/re d/ded/ej!d0re d0ded0ej!d1re d1ded1ej!d2re d2ded2ej!d3re d3ded3ej"dd4d5krGd6d7d7eZ#gZ iZ e d8e#ej$j%ej j d9d:d;Z&x8dd?d@dAe&fD]"Z'ej!e'rhe e'dee'qhWej"dBkrGdCdDdDeZ(GdEdFdFeZ)e dGde)dGdSe dsz'GenericBrowser.open..winT) close_fdsF)rr2sysplatform subprocessPopenwaitOSError)r.r!r"r#cmdlinepr )r!r rs   zGenericBrowser.openN)rT)rr r r1r/rr r r r r|s rc@seZdZdZdddZdS)rzHClass for all browsers which are to be started in the background.rTc sp|jgfdd|jD}y:tjdddkr.r9r:T)r;start_new_sessionF)rr2r<r=r>r?pollrA)r.r!r"r#rBrCr )r!r rs   zBackgroundBrowser.openN)rT)rr r r1rr r r r rsrc@sBeZdZdZdZdZdZddgZdZdZ dZ ddZ d d d Z dS) UnixBrowserz=Parent class for all Unix browsers with remote functionality.NFTz%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;stdinstdoutstderrrDF) raise_optsintr backgroundr>DEVNULLr?redirect_stdoutr@ZTimeoutExpiredrE) r.r2Zremoter#Z raise_optoptrBZinoutrCrcr 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)r5)r6r7)actionr!r r r8sz$UnixBrowser.open..cSsg|] }|r|qSr r )r6r7r r r r8sTcsg|]}|jdqS)z%s)r5)r6r7)r!r r r8sF) remote_actionremote_action_newwinremote_action_newtabr remote_argsrRr2)r.r!r"r#r2Zsuccessr )rSr!r rs$    zUnixBrowser.open)rT) rr r r1rKrMrOrWrTrUrVrRrr r r r rFs#rFc@s(eZdZdZddgZdZdZdZdZdS) Mozillaz$Launcher class for Mozilla browsers.z%actionz%sr-z -new-windowz-new-tabTN) rr r r1rWrTrUrVrMr r r r rXs rXc@s0eZdZdZddgZddgZdZdZdZd Z d S) Netscapez$Launcher class for Netscape browser.z-noraisez-raisez-remotezopenURL(%s%action)r-z ,new-windowz,new-tabTN) rr r r1rKrWrTrUrVrMr r r r rYsrYc@s,eZdZdZddgZddgZdZdZdZd S) Galeonz,Launcher class for Galeon/Epiphany browsers.z-noraiser-z%actionz%sz-nz-wTN) rr r r1rKrWrTrUrMr r r r rZ s rZc@s(eZdZdZddgZdZdZdZdZdS)Chromez)Launcher class for Google Chrome browser.z%actionz%sr-z --new-windowTN) rr r r1rWrTrUrVrMr r r r r[s r[c@s(eZdZdZddgZdZdZdZdZdS)Operaz!Launcher class for Opera browser.z%actionz%sr-z --new-windowTN) rr r r1rWrTrUrVrMr 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 r1rWrTrUrVrMrOr r r r r],sr]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. rTcCs|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;rGrHrI konquerorz--silent)r;rGrHrIrDkfmz-dF)r>rNr?rAr@rE)r.r!r"r#rSdevnullrCr r r rAs:      zKonqueror.openN)rT)rr r r1rr 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_STREAMZconnectrAunlink) r.rdrerfrgZtempdiruserfilenameZmaybessfnr r r _find_grail_rcrs*    zGrail._find_grail_rccCs&|j}|sdS|j||jdS)Nrr )rpsendclose)r.rSrnr r r _remotes  z Grail._remoterTcCs&|r|jd|}n|jd|}|S)NzLOADNEW zLOAD )rs)r.r!r"r#okr r r rsz Grail.openN)rT)rr r rprsrr r r r rcnsrccCstjdrtddtddtjkr>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-firebirdfirebirdmozillanetscaperar`galeonepiphanyZ skipstone google-chromechromechromiumchromium-browseroperaZmosaicZgrail)rurvrwrx)ryrzr{r|r})r~r)rrrr) r%r&rrr'environr^rXrYrZr[r\rc)rr r r register_X_browserssH               rZDISPLAYZTERMz www-browserZlinksZelinksZlynxZw3mr9r:c@seZdZdddZdS)WindowsDefaultrTc Cs,ytj|Wntk r"dSXdSdS)NFT)r'Z startfilerA)r.r!r"r#r r r rs zWindowsDefault.openN)rT)rr r rr r r r rsrzwindows-defaultZ PROGRAMFILESzC:\Program FileszInternet Explorer\IEXPLORE.EXErur{rxr|r}rdarwinc@s"eZdZdZddZd ddZdS) 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|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)rLboolrr5r'popenwriterr) r.r!r"r#scriptZtoWindowr+osapiperQr r r r)s       z MacOSX.openN)rT)rr r r1r/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)rr5r'rrrr)r.r!r"r#rrrQr 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<argverrorprintrIexitlenr) rZusageZoptsr2msgZnew_winoar!r r r main~s(   r__main__)Nr )N)rT)r rrrrrr)2r1r'rr%r<r>__all__ Exceptionrrrrrrrrrobjectr,rrrFrXrYrZr[ZChromiumr\r]r^rcrrr&r=rr(rhZiexplorerrrrpathsepZ _userchoicesreverserBr+rrr r r r s    "N     45B          .