HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3.5/__pycache__/mailcap.cpython-35.pyc


��j`��@s�dZddlZddlZddgZdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
ddgdd�Zddd�Zgdd�Z
dd�Zdd�Zdd�Zedkr�e�dS) z%Mailcap file handling.  See RFC 1524.�N�getcaps�	findmatchcCs"d|krd|dfSdSdS)N�linenor�)rr�)�entryrr�/usr/lib/python3.5/mailcap.py�lineno_sort_key	sr	cCs�i}d}x�t�D]�}yt|d�}Wntk
rFwYnX|�t||�\}}WdQRXxE|j�D]7\}}||kr�|||<qw|||||<qwWqW|S)a�Return a dictionary containing the mailcap database.

    The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
    to a list of dictionaries corresponding to mailcap entries.  The list
    collects all the entries for that MIME type from all available mailcap
    files.  Each dictionary contains key-value pairs for that MIME type,
    where the viewing command is stored with the key "view".

    r�rN)�listmailcapfiles�open�OSError�_readmailcapfile�items)�capsrZmailcap�fpZmorecaps�key�valuerrrrs


cCspdtjkr1tjd}|jtj�}n;dtjkrPtjd}nd}|ddddg}|S)z7Return a list of all mailcap files found on the system.ZMAILCAPS�HOME�.z	/.mailcapz/etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)�os�environ�split�pathsep)ZpathstrZmailcapsZhomerrrr-s

rcCs,tjdtd�t|d�\}}|S)z?Read a mailcap file and return a dictionary keyed by MIME type.z2readmailcapfile is deprecated, use getcaps instead�N)�warnings�warn�DeprecationWarningr)rr�_rrr�readmailcapfile?s	
rc	Csai}xN|j�}|sP|ddks	|j�dkrAq	|}xF|dd�dkr�|j�}|sxd}|dd�|}qJWt|�\}}|o�|s�q	|dk	r�||d<|d	7}|jd
�}x.tt|��D]}||j�||<q�Wd
j|�j�}||krF||j|�q	|g||<q	W||fS)
a�Read a mailcap file and return a dictionary keyed by MIME type.

    Each MIME type is mapped to an entry consisting of a list of
    dictionaries; the list will contain more than one such dictionary
    if a given MIME type appears more than once in the mailcap file.
    Each dictionary contains key-value pairs for that MIME type, where
    the viewing command is stored with the key "view".
    r�#�rNz\
�
rr�/���r$)	�readline�strip�	parseliner�range�len�join�lower�append)	rrr�lineZnextliner�fields�types�jrrrrGs6	"

rc
Cs1g}dt|�}}x?||krZt|||�\}}|j|�|d}qWt|�dkrqdS|d|d|dd�}}}d|i}x�|D]y}|jd�}|dkr�|}d}	n0|d|�j�}||dd�j�}	||krq�|	||<q�W||fS)	z�Parse one entry in a mailcap file and return a dictionary.

    The viewing command is stored as the value with the key "view",
    and the rest of the fields produce key-value pairs in the dict.
    rrrN�view�=r!)NN)r)�
parsefieldr,�findr&)
r-r.�i�n�fieldrr1�restZfkeyZfvaluerrrr'ps*
&
	r'cCsp|}xM||krU||}|dkr/Pq	|dkrH|d}q	|d}q	W|||�j�|fS)z/Separate one key-value pair in a mailcap entry.�;�\rr)r&)r-r5r6�start�crrrr3�s

r3r1z	/dev/nullc	Cs�t|||�}xn|D]f}d|kr_t|d||�}|r_tj|�dkr_qt|||||�}||fSWdS)aFind a match for a mailcap entry.

    Return a tuple containing the command line, and the mailcap entry
    used; (None, None) if no match is found.  This may invoke the
    'test' command of several matching entries before deciding which
    entry to use.

    �testrN)NN)�lookup�substr�system)	r�MIMEtyper�filename�plist�entries�er=�commandrrrr�s	
cs�g}||kr |||}|jd�}|dd}||krW|||}�dk	r|�fdd�|D�}t|dt�}|S)Nr#rz/*cs"g|]}�|kr|�qSrr)�.0rE)rrr�
<listcomp>�s	zlookup.<locals>.<listcomp>r)r�sortedr	)rrArrDZ	MIMEtypesr)rrr>�sr>c
Cscd}dt|�}}xC||kr^||}|d}|dkr|dkrr|||d�}|d}||}q||}|d}|dkr�||}q|dkr�||}q|dkr�||}q|dkrM|}x*||kr||d	kr|d}q�W|||�}	|d}|t|	|�}q|d|}qW|S)
Nr!rr�%r:�s�t�{�})r)�	findparam)
r7rArBrCZresr5r6r<r;�namerrrr?�s6









r?cCs[|j�d}t|�}x8|D]0}|d|�j�|kr#||d�Sq#WdS)Nr2r!)r+r))rPrCr6�prrrrO�s
rOc	Csddl}t�}|jdd�s6t|�dSx�tdt|j�d�D]�}|j||d�}t|�dkr�td�dS|d}|d}t||d|�\}}|s�tdt�qRtd|�t	j
|�}|rRtd|�qRWdS)	Nrrrz"usage: mailcap [MIMEtype file] ...r1zNo viewer found forz
Executing:zExit status:)�sysr�argv�showr(r)�printr�typerr@)	rRrr5�argsrA�filerFrE�stsrrrr=�s&	
"



r=cCs�td�xt�D]}td|�qWt�|sBt�}td�t�t|�}xl|D]d}t|�||}xG|D]?}t|�}x#|D]}td|||�q�Wt�q�WqfWdS)NzMailcap files:�	zMailcap entries:z  %-15s)rUrrrI)r�fnZckeysrVrDrE�keys�krrrrTs"
	





rT�__main__)�__doc__rr�__all__r	rrrrr'r3rr>r?rOr=rT�__name__rrrr�<module>s$
)