a �DOg^�@s�dZddlZddlZddlZddlZddlZddlZgd�ZGdd�de�Z e� �Z iZ da dad=dd�dd �Zd>d d �Zd?d d�Zdd�Zdd�Zdd�dd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$e�ZeZGd%d&�d&e�ZGd'd(�d(e�Z Gd)d*�d*e�Z!Gd+d,�d,e�Z"d-d.�Z#d/d0�Z$ej%dd1�d2k�r�Gd3d4�d4e�Z&ej%d5k�r�Gd6d7�d7e�Z'Gd8d9�d9e�Z(d:d;�Z)e*ddSq>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)�url�new� autoraiserr$r r r rGs $rcCs t|d�S)zuOpen url in a new window of the default browser. If not possible, then open url in the only browser window. r�r�r&r r r rZsrcCs t|d�S)z�Open 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 rasrcCs�|��d}t�|�sddgStj�|�}zt|��}WntyTddgYS0|d}|r�|��|jkr�ddl }|� |�}||_ tj�|�|_t |d||d�d|gSddgS)a�Attempt 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) r�shutil�which�os�path�basenamerrr"�copyrr)r$r�cmdrr%Z controllerr1r r r r#is"     r#c@s:eZdZdZdgZddd�Zddd �Zd d �Zd d �ZdS)� BaseBrowserz3Parent class for all browsers. Do not use directly.r�cCs||_||_dS�N)rr0��selfrr r r �__init__�szBaseBrowser.__init__rTcCst�dSr5)�NotImplementedError�r7r&r'r(r r r r�szBaseBrowser.opencCs |�|d�S)Nrr)�r7r&r r r r�szBaseBrowser.open_newcCs |�|d�S)Nr+r)r;r r r r�szBaseBrowser.open_new_tabN)r4)rT) rr r �__doc__�argsr8rrrr r r r r3�s   r3c@s"eZdZdZdd�Zd dd�ZdS) r!zVClass for all browsers started with a command and without remote functionality.cCsFt|t�r||_dg|_n|d|_|dd�|_tj�|j�|_dS)Nrrr)� isinstance�strrr=r.r/r0r6r r r r8�s    zGenericBrowser.__init__rTcszt�d��|jg�fdd�|jD�}z8tjdd�dkrHt�|�}ntj|dd�}|�� WStytYdS0dS) N�webbrowser.opencsg|]}|�d���qS�r��replace��.0�argr*r r � �s�z'GenericBrowser.open..��winT)� close_fdsF) �sys�auditrr=�platform� subprocess�Popen�wait�OSError�r7r&r'r(�cmdline�pr r*r r�s �   zGenericBrowser.openN)rT�rr r r<r8rr r r r r!�s r!c@seZdZdZddd�ZdS)r zHClass for all browsers which are to be started in the background.rTcs~|jg�fdd�|jD�}t�d��z.r@rHrIT)rJ�start_new_sessionF) rr=rKrLrMrNrO�pollrQrRr r*r r�s�  � zBackgroundBrowser.openN)rT�rr r r<rr r r r r �sr c@sDeZdZdZdZdZdZddgZdZdZ dZ d dd�Z d d d �Z dS)� UnixBrowserz=Parent class for all Unix browsers with remote functionality.NFT�%actionrc Cs�g}|r*|jr*t|�}|j|}|r*|g}|jg||}|sD|jrLtj}nd}tj|d||jrd|pfd|dd�} |r�z| �d�} | WStj y�YdS0n&|jr�| � �dur�dSdSn | �� SdS)NT�rJ�stdin�stdout�stderrrV�F) � raise_opts�intr� backgroundrN�DEVNULLrO�redirect_stdoutrP�TimeoutExpiredrW) r7r=Zremoter(r&Z raise_opt�optrSZinoutrT�rcr r r �_invoke�s0      �   zUnixBrowser._invokercs�t�d��|dkr|j�nB|dkr,|j�n2|dkrN|jdurF|j�q^|j�ntdd|����fdd�|jD�}d d�|D�}|�|d |��}|s��fd d�|jD�}|�|d d �Sd SdS) Nr@rrr+zBad 'new' parameter to open(); zexpected 0, 1, or 2, got %scs g|]}|�d���d���qS)rrZrBrD��actionr&r r rGs�z$UnixBrowser.open..cSsg|] }|r|�qSr r rDr r r rG�Tcsg|]}|�d���qSrArBrDr*r r rGrkF) rKrL� remote_action�remote_action_newwin�remote_action_newtabr� remote_argsrhr=)r7r&r'r(r=�successr rir rs*  � �zUnixBrowser.open)N)rT) rr r r<r`rbrdrorlrmrnrhrr r r r rY�s #rYc@s(eZdZdZddgZdZdZdZdZdS) �Mozillaz$Launcher class for Mozilla browsers.rZrr4z -new-windowz-new-tabTN� rr r r<rorlrmrnrbr r r r rqs rqc@s0eZdZdZddgZddgZdZdZdZd Z d S) �Netscapez$Launcher class for Netscape browser.�-noraisez-raise�-remote�openURL(%s%action)r4� ,new-window�,new-tabTN) rr r r<r`rorlrmrnrbr r r r rs&srsc@s,eZdZdZddgZddgZdZdZdZd S) �Galeonz,Launcher class for Galeon/Epiphany browsers.rtr4rZr�-nz-wTN) rr r r<r`rorlrmrbr r r r ry1s ryc@s(eZdZdZddgZdZdZdZdZdS)�Chromez)Launcher class for Google Chrome browser.rZrr4� --new-windowTNrrr r r r r{;s r{c@s(eZdZdZddgZdZdZdZdZdS)�Operaz!Launcher class for Opera browser.rZrr4r|TNrrr r r r r}Gs r}c@s,eZdZdZddgZdZdZdZdZdZ dS) �Elinksz#Launcher class for Elinks browsers.rurvr4rwrxFN) rr r r<rorlrmrnrbrdr r r r r~Qsr~c@seZdZdZddd�ZdS)� Konquerorz�Controller for the KDE File Manager (kfm, or Konqueror). See the output of ``kfmclient --commands`` for more information on the Konqueror remote-control interface. rTcCs�t�d|�|dkrd}nd}tj}ztjd||gd|||d�}WntyTYn0|��dSz tjdd |gd|||dd �}Wnty�Yn0|��dur�dSz tjd d |gd|||dd �}Wnty�Yd S0|��duSdS)Nr@r+ZnewTabZopenURL� kfmclientT)rJr\r]r^� konquerorz--silentr[�kfmz-dF)rKrLrNrcrOrQrPrW)r7r&r'r(rj�devnullrTr r r rfsB  �   �    �  zKonqueror.openN)rTrXr r r r r_src@s&eZdZdd�Zdd�Zd dd�Zd S) �Grailc Cs�ddl}ddl}ddl}ddl}tj�|��d�}|�t� ��d}tj�|� |�|� |�d�}|�|�}|stdS|�|j |j �} |D]P} z| � | �Wn4ty�zt�| �Wnty�Yn0Yq�0| Sq�dS)Nrz .grail-unixz-*)�glob�pwd�socket�tempfiler.r/�join� gettempdir�getpwuid�getuid�escape�AF_UNIX� SOCK_STREAM�connectrQ�unlink) r7r�r�r�r��tempdir�user�filenameZmaybes�s�fnr r r �_find_grail_rc�s, �    zGrail._find_grail_rccCs&|��}|sdS|�|�|��dS)Nrr)r��send�close)r7rjr�r r r �_remote�s  z Grail._remoterTcCs2t�d|�|r |�d|�}n|�d|�}|S)Nr@zLOADNEW zLOAD )rKrLr�)r7r&r'r(�okr r r r�s  z Grail.openN)rT)rr r r�r�rr r r r r��sr�cCs�t�d�rtddtd��dtjvr>t�d�r>tddtd��dtjvrbt�d�rbtddtd��dtjvr�t�d�r�tdttd��t�d�r�tddtd��dD]}t�|�r�t|dt|��q�d D]}t�|�r�t|dt|��q�t�d ��rtd ttd ��nt�d ��r"td ttd ��d D]"}t�|��r&t|dt |���q&t�d ��rftd dtd ��dD]"}t�|��rjt|dt |���qjt�d��r�tddt d��t�d��r�tddtd��t�d��r�tdt d�dS)Nzxdg-openZGNOME_DESKTOP_SESSION_IDz gvfs-openz gnome-openZKDE_FULL_SESSIONr�z x-www-browser)�firefoxZ iceweaselZiceape� seamonkey)zmozilla-firefoxzmozilla-firebird�firebird�mozilla�netscaper�r�)ZgaleonZepiphanyZ skipstone)z google-chrome�chromeZchromiumzchromium-browser�operaZmosaicZgrail) r,r-rr r.�environrrqrsryr{r}r�)r$r r r �register_X_browsers�sD            r�c Cs,gatjdkrNtddtd��tddtd��tddtd��tddtd��tjdd�dkr�td t�tj�tj � d d �d �}dd dddd|fD]}t � |�r�t|dt |��q��ntj � d�s�tj � d��r$z(d��}tj|tjd�}|����}Wnttjttf�yYn0|at�tj � d��r�t � d��rNtddtd��t � d��rjtddtd��t � d��r�tddtd��t � d��r�tddtd��t � d��r�tddtd��dtj v�r(tj d�tj�}|��|D]>}|dk�r�t|dd�}|d du�r�t|dt|�dd��q�dS)!N�darwin�MacOSX�defaultr�r�ZsafarirHrIzwindows-defaultZ PROGRAMFILESzC:\Program FileszInternet Explorer\IEXPLORE.EXEr�r�r�r�r�ZDISPLAYZWAYLAND_DISPLAYz$xdg-settings get default-web-browser)r^ZTERMz www-browserZlinksZelinksZlynxZw3mZBROWSERr4Tr r)rrKrMr�MacOSXOSAScript�WindowsDefaultr.r/r�r�rr,r-r rrN� check_outputrc�decode�strip�FileNotFoundError�CalledProcessError�PermissionError�NotADirectoryErrorrr�r!r~�pathsep�reverser#)Ziexplorer$r2Z raw_result�resultZ userchoicesrSr r r r sX  ��         rrHrIc@seZdZddd�ZdS)r�rTcCs8t�d|�zt�|�Wnty.YdS0dSdS)Nr@FT)rKrLr.Z startfilerQr:r r r rXs   zWindowsDefault.openN)rT)rr r rr r r r r�Wsr�r�c@s"eZdZdZdd�Zd dd�ZdS) r�a{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 Cs�t�d|�d|vsJ�d|vr(d|}tt|��}|jdkrPd|�dd�}n<|jd kr`d }n d |d }d |�dd�}d|j||f}t�dd�}|dur�dS|�|�|� �}| S)Nr@�'�:zfile:r��open location "%s"�"�%22ZOmniWebr4z toWindow %drz OpenURL "%s"z�tell application "%s" activate %s %s end tell� osascript�wF) rKrLra�boolrrCr.�popen�writer�) r7r&r'r(�scriptZtoWindowr2�osapipergr r r rvs(       �  z MacOSX.openN)rTrUr r r r r�is r�c@seZdZdd�Zddd�ZdS) r�cCs ||_dSr5)�_namer6r r r r8�szMacOSXOSAScript.__init__rTcCsb|jdkrd|�dd�}nd|j|�dd�f}t�dd�}|durJdS|�|�|��}| S) Nr�r�r�r�z� tell application "%s" activate open location "%s" end r�r�F)r�rCr.r�r�r�)r7r&r'r(r�r�rgr r r r�s �  zMacOSXOSAScript.openN)rT)rr r r8rr r r r r��sr�c Cs�ddl}dtjd}z|�tjdd�d�\}}WnL|jy�}z2t|tjd�t|tjd�t�d�WYd}~n d}~00d}|D]"\}}|dkr�d}q�|dkr�d}q�t|�dkr�t|tjd�t�d�|d}t||�td �dS) NrzDUsage: %s [-n | -t] url -n: open new window -t: open new tabrZntd)�filerzz-tr+�) �getoptrK�argv�error�printr^�exit�lenr) r��usageZoptsr=�msgZnew_win�o�ar&r r r �main�s(�     r��__main__)N)N)rT)+r<r.rr,rKrN� threading�__all__� Exceptionr�RLockrrrrrrrrrr#�objectr3r!r rYrqrsryr{ZChromiumr}r~rr�r�rrMr�r�r�r�rr r r r �sR " "O     56AK /