a �DOg^�@s�ddlZddlZddlZddlZddlZddlZgd�ZGdd�de�Ze� �Z iZ da da dd d �Zdd�Zdd�Zdd�dd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGd d!�d!e�ZGd"d#�d#e�ZeZGd$d%�d%e�ZGd&d'�d'e�ZGd(d)�d)e�Z Gd*d+�d+e�Z!d,d-�Z"d.d/�Z#ej$dd0�d1k�r�Gd2d3�d3e�Z%ej$d4k�r�Gd5d6�d6e�Z&Gd7d8�d8e�Z'd9d:�Z(e)d;k�r�e(�dS)?�N)�Error�open�open_new� open_new_tab�get�registerc@s eZdZdS)rN)�__name__� __module__� __qualname__�r r �"/usr/lib64/python3.9/webbrowser.pyrsrF�� preferredcCsnt�Vtdurt�||gt|��<|s4trB|tvrBt�d|�n t�|�Wd�n1s`0YdS)Nr)�_lock� _tryorder�register_standard_browsers� _browsers�lower�_os_preferred_browser�insert�append)�name�klass�instancerr r r rsrc Cstdur:t�tdurt�Wd�n1s00Y|durJ|g}nt}|D]�}d|vr�t�|�}|ddkr�t|dd��St|�SqRzt|��}Wnt y�t |�}Yn0|ddur�|dS|ddurR|d�SqRt d��dS)N�%s������&�rz!could not locate runnable browser) rrr�shlex�split�BackgroundBrowser�GenericBrowserrr�KeyError� _synthesizer)ZusingZ alternatives�browser�commandr r r r%s,$      rTcCsdtdur:t�tdurt�Wd�n1s00YtD] }t|�}|�|||�r>dSq>dS)NTF)rrrrr)�url�new� autoraiserr$r r r rGs $rcCs t|d�S�Nr�r�r&r r r rZsrcCs t|d�S�N�r*r+r r r rasrcCs�|��d}t�|�sddgStj�|�}zt|��}WntyTddgYS0|d}|r�|��|jkr�ddl }|� |�}||_ tj�|�|_t |d||d�d|gSddgS)Nrr)rr) r�shutil�which�os�path�basenamerrr"�copyrr)r$r�cmdrr%Z controllerr3r r r r#is"     r#c@s6eZdZdgZddd�Zddd�Zd d �Zd d �Zd S)� BaseBrowserr�cCs||_||_dS�N)rr2��selfrr r r �__init__�szBaseBrowser.__init__rTcCst�dSr7)�NotImplementedError�r9r&r'r(r r r r�szBaseBrowser.opencCs |�|d�Sr)r*�r9r&r r r r�szBaseBrowser.open_newcCs |�|d�Sr,r*r=r r r r�szBaseBrowser.open_new_tabN)r6)rT)rr r �argsr:rrrr r r r r5�s   r5c@seZdZdd�Zddd�ZdS) r!cCsFt|t�r||_dg|_n|d|_|dd�|_tj�|j�|_dS)Nrrr)� isinstance�strrr>r0r1r2r8r r r r:�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�r9r&r'r(�cmdline�pr r+r r�s �   zGenericBrowser.openN)rT�rr r r:rr r r r r!�s r!c@seZdZddd�ZdS)r rTcs~|jg�fdd�|jD�}t�d��z.rArIrJT)rK�start_new_sessionF) rr>rLrMrNrOrP�pollrRrSr r+r r�s�  � zBackgroundBrowser.openN)rT�rr r rr r r r r �sr c@s@eZdZdZdZdZddgZdZdZdZ d dd�Z d d d �Z dS) � UnixBrowserNFT�%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�rK�stdin�stdout�stderrrW�F) � raise_opts�intr� backgroundrO�DEVNULLrP�redirect_stdoutrQ�TimeoutExpiredrX) r9r>Zremoter(r&Z raise_opt�optrTZinoutrU�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) NrArrr-zBad 'new' parameter to open(); zexpected 0, 1, or 2, got %scs g|]}|�d���d���qS)rr[rCrE��actionr&r r rHs�z$UnixBrowser.open..cSsg|] }|r|�qSr r rEr r r rH�Tcsg|]}|�d���qSrBrCrEr+r r rHrlF) rLrM� remote_action�remote_action_newwin�remote_action_newtabr� remote_argsrir>)r9r&r'r(r>�successr rjr rs*  � �zUnixBrowser.open)N)rT) rr r rarcrerprmrnrorirr r r r rZ�s #rZc@s$eZdZddgZdZdZdZdZdS)�Mozillar[rr6z -new-windowz-new-tabTN�rr r rprmrnrorcr r r r rrs rrc@s,eZdZddgZddgZdZdZdZdZd S) �Netscape�-noraisez-raise�-remote�openURL(%s%action)r6� ,new-window�,new-tabTN) rr r rarprmrnrorcr r r r rt&s rtc@s(eZdZddgZddgZdZdZdZdS) �Galeonrur6r[r�-nz-wTN)rr r rarprmrnrcr r r r rz1s rzc@s$eZdZddgZdZdZdZdZdS)�Chromer[rr6� --new-windowTNrsr r r r r|;s r|c@s$eZdZddgZdZdZdZdZdS)�Operar[rr6r}TNrsr r r r r~Gs r~c@s(eZdZddgZdZdZdZdZdZdS)�Elinksrvrwr6rxryFN) rr r rprmrnrorcrer r r r rQs rc@seZdZddd�ZdS)� KonquerorrTcCs�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)NrAr-ZnewTabZopenURL� kfmclientT)rKr]r^r_� konquerorz--silentr\�kfmz-dF)rLrMrOrdrPrRrQrX)r9r&r'r(rk�devnullrUr r r rfsB  �   �    �  zKonqueror.openN)rTrYr r r r r�_sr�c@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�tempfiler0r1�join� gettempdir�getpwuid�getuid�escape�AF_UNIX� SOCK_STREAM�connectrR�unlink) r9r�r�r�r��tempdir�user�filenameZmaybes�s�fnr r r �_find_grail_rc�s, �    zGrail._find_grail_rccCs&|��}|sdS|�|�|��dS)Nrr)r��send�close)r9rkr�r r r �_remote�s  z Grail._remoterTcCs2t�d|�|r |�d|�}n|�d|�}|S)NrAzLOADNEW zLOAD )rLrMr�)r9r&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 r0�environr�rrrtrzr|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�ZsafarirIrJzwindows-defaultZ PROGRAMFILESzC:\Program FileszInternet Explorer\IEXPLORE.EXEr�r�r�r�r�ZDISPLAYZWAYLAND_DISPLAYz$xdg-settings get default-web-browser)r_ZTERMz www-browserZlinksZelinksZlynxZw3mZBROWSERr6Tr r)rrLrNr�MacOSXOSAScript�WindowsDefaultr0r1r�r�rr.r/r rrO� check_outputrd�decode�strip�FileNotFoundError�CalledProcessError�PermissionError�NotADirectoryErrorrr�r!r�pathsep�reverser#)Ziexplorer$r4Z raw_result�resultZ userchoicesrTr r r r sX  ��         rrIrJc@seZdZddd�ZdS)r�rTcCs8t�d|�zt�|�Wnty.YdS0dSdS)NrAFT)rLrMr0Z startfilerRr<r r r rXs   zWindowsDefault.openN)rTrYr r r r r�Wsr�r�c@seZdZdd�Zddd�ZdS) r�cCs ||_dSr7)rr8r r r r:sszMacOSX.__init__rTc Cs�t�d|�d|vrd|}tt|��}|jdkrDd|�dd�}n<|jdkrTd }n d |d }d |�dd�}d |j||f}t�dd�}|dur�dS|�|�|� �}| S)NrA�:zfile:r��open location "%s"�"�%22ZOmniWebr6z toWindow %drz OpenURL "%s"z�tell application "%s" activate %s %s end tell� osascript�wF) rLrMrb�boolrrDr0�popen�writer�) r9r&r'r(�scriptZtoWindowr4�osapiperhr r r rvs&      �  z MacOSX.openN)rTrVr r r r r�is r�c@seZdZdd�Zddd�ZdS) r�cCs ||_dSr7)�_namer8r r r r:�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�rDr0r�r�r�)r9r&r'r(r�r�rhr r r r�s �  zMacOSXOSAScript.openN)rTrVr 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)�filer{z-tr-�) �getoptrL�argv�error�printr_�exit�lenr) r��usageZoptsr>�msgZnew_win�o�ar&r r r �main�s(�     r��__main__)N)N)rT)*r0rr.rLrO� threading�__all__� Exceptionr�RLockrrrrrrrrrr#�objectr5r!r rZrrrtrzr|ZChromiumr~rr�r�r�rrNr�r�r�r�rr r r r �sP " "O     56AK /