ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python34/lib64/python3.4/__pycache__/mailcap.cpython-34.pyo

�
e f
�@s�dZddlZddgZdd�Zdd�Zdd	�Zd
d�Zdd
�Zddgdd�Zddd�Z	gdd�Z
dd�Zdd�Zdd�Z
edkr�e�ndS)z%Mailcap file handling.  See RFC 1524.�N�getcaps�	findmatchcCs�i}x�t�D]�}yt|d�}Wntk
r@wYnX|�t|�}WdQXxE|j�D]7\}}||kr�|||<qg|||||<qgWqW|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".

    �rN)�listmailcapfiles�open�OSError�readmailcapfile�items)�capsZmailcap�fpZmorecaps�key�value�r�,/opt/alt/python34/lib64/python3.4/mailcap.pyr	s


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)ZpathstrZmailcaps�homerrrr"s

rcCsGi}x:|j�}|sPn|ddks	|j�dkrGq	n|}xI|d	d�dkr�|j�}|s�d}n|dd
�|}qPWt|�\}}|o�|s�q	n|jd�}x.tt|��D]}||j�||<q�Wdj|�j�}||kr2||j|�q	|g||<q	W|S)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�#��Nz\
�
�/���r)	�readline�strip�	parseliner�range�len�join�lower�append)rr
�lineZnextliner�fields�types�jrrrr5s0	"	rc
Cs2g}dt|�}}x?||krZt|||�\}}|j|�|d}qWt|�dkrqdS|d|d|dd�}}}i|d6}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.
    r�rN�view�=r)NN)r!�
parsefieldr$�findr)
r%r&�i�n�fieldrr*�restZfkeyZfvaluerrrr[s*
&

	rcCsp|}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%r.r/�start�crrrr,zs

r,r*z	/dev/nullc	Cs�t|||�}xt|D]l}d|kret|d||�}|retj|�dkreqqent|||||�}||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�er6�commandrrrr�s	
	cs�g}||kr#|||}n|jd�}|dd}||kr]|||}n�dk	r��fdd�|D�}n|S)Nrrz/*cs"g|]}�|kr|�qSrr)�.0r>)rrr�
<listcomp>�s	zlookup.<locals>.<listcomp>)r)r
r:rr=Z	MIMEtypesr)rrr7�sr7c
Csfd}dt|�}}xF||kra||}|d}|dkr�|dkru|||d�}|d}n||}q||}|d}|dkr�||}q|dkr�||}q|dkr�||}q|dkrP|}x*||kr||d	kr|d}q�W|||�}	|d}|t|	|�}q|d|}qW|S)
Nrrr)�%r3�s�t�{�})r!�	findparam)
r0r:r;r<�resr.r/r5r4�namerrrr8�s6









r8cCs[|j�d}t|�}x8|D]0}|d|�j�|kr#||d�Sq#WdS)Nr+r)r#r!)rIr<r/�prrrrG�s
rGc	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|�qRqRWdS)	Nrr)rz"usage: mailcap [MIMEtype file] ...r*zNo viewer found forz
Executing:zExit status:)�sysr�argv�showr r!�printr�typerr9)	rKr
r.�argsr:�filer?r>�stsrrrr6�s&	
"



r6cCs�td�xt�D]}td|�qWt�|sEt�}ntd�t�t|�}xl|D]d}t|�||}xG|D]?}t|�}x#|D]}td|||�q�Wt�q�WqiWdS)NzMailcap files:�	zMailcap entries:z  %-15s)rNrr�sorted)r
�fnZckeysrOr=r>�keys�krrrrM�s"






rM�__main__)�__doc__r�__all__rrrrr,rr7r8rGr6rM�__name__rrrr�<module>s& 

Zerion Mini Shell 1.0