a �DOg�#�@s�ddlZddlZddlZddgZdd�Ze�d�jZGdd�de�Z d d�Z d d �Z d d �Z dd�Z dd�Zdd�Zddgfdd�Zd"dd�Zgfdd�Zdd�Zdd�Zdd �Zed!kr�e�dS)#�N�getcaps� findmatchcCsd|vrd|dfSdSdS)N�linenor)�r�)�entryrr�/usr/lib64/python3.9/mailcap.py�lineno_sort_key s r z[^\xa1-\U0010FFFF\w@+=:,./-]c@s eZdZdS)�UnsafeMailcapInputN)�__name__� __module__� __qualname__rrrrr sr c Cs�i}d}t�D]�}zt|d�}Wnty6YqYn0|�t||�\}}Wd�n1s`0Y|��D]*\}}||vr�|||<qr|||||<qrq|S)Nr�r)�listmailcapfiles�open�OSError�_readmailcapfile�items)�capsrZmailcap�fpZmorecaps�key�valuerrrrs    , cCsPdtjvr"tjd}|�tj�}n*dtjvr8tjd}nd}|ddddg}|S)NZMAILCAPS�HOME�.z /.mailcapz /etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)�os�environ�split�pathsep)ZpathstrZmailcaps�homerrrr3s    �rcCs t�dtd�t|d�\}}|S)Nz2readmailcapfile is deprecated, use getcaps instead�)�warnings�warn�DeprecationWarningr)rr�_rrr�readmailcapfileEs �r$c Cs�i}|��}|sq�|ddks|��dkr,q|}|dd�dkrb|��}|sPd}|dd�|}q0t|�\}}|r|sxq|dur�||d<|d7}|�d �}tt|��D]}||��||<q�d �|���}||vr�||�|�q|g||<q||fS) Nr�#������z\ � rr�/) �readline�strip� parseliner�range�len�join�lower�append) rrr�lineZnextliner�fields�types�jrrrrMs0    rc Cs�g}dt|�}}||kr>t|||�\}}|�|�|d}qt|�dkrNdS|d|d|dd�}}}d|i}|D]V}|�d�}|dkr�|}d} n$|d|���}||dd���} ||vr�qz| ||<qz||fS)Nrrr�NN�view�=r&)r.� parsefieldr1�findr+) r2r3�i�n�fieldrr7�restZfkeyZfvaluerrrr,vs*      r,cCsP|}||kr<||}|dkr q��zlookup..rP)r�sortedr )rrHrrLZ MIMEtypesrrPrrE�s     rEc CsRd}dt|�}}||k�rN||}|d}|dkr^|dkrT|||d�}|d}||}q||}|d}|dkr�||}q|dkr�||}q|dkr�t|�r�d|f}t�|t�dS||}q|d k�r@|} ||kr�||d kr�|d}q�|| |�} |d}t| |�} t| ��r6d | | f}t�|t�dS|| }q|d|}q|S) Nr&rr�%r@�s�tz9Refusing to substitute MIME type %r into a shell command.�{�}z=Refusing to substitute parameter %r (%s) into a shell command)r.rDr r!r � findparam) r=rHrIrJ�resr;r<rBrKrA�nameZparamrrrrF�sB               rFcCsF|��d}t|�}|D](}|d|���|kr||d�SqdS)Nr8r&)r0r.)r[rJr<�prrrrY�s  rYc Cs�ddl}t�}|jdd�s(t|�dStdt|j�d�D]�}|j||d�}t|�dkrjtd�dS|d}|d}t||d|�\}}|s�tdt�q:td|�t � |�}t � |�}|r:td|�q:dS) Nrrrz"usage: mailcap [MIMEtype file] ...r7zNo viewer found forz Executing:z Exit status:) �sysr�argv�showr-r.�printr�typerrG�waitstatus_to_exitcode) r]rr;�argsrH�filerNrM�stsrrrrCs(     rCcCs�td�t�D]}td|�qt�|s0t�}td�t�t|�}|D]H}t|�||}|D].}t|�}|D]}td|||�qrt�qbqJdS)NzMailcap files:� zMailcap entries:z %-15s)r`rrrS)r�fnZckeysrarLrM�keys�krrrr_s r_�__main__)N)rr �re�__all__r �compile�searchrD�Warningr rrr$rr,r9rrErFrYrCr_r rrrr�s( ) )