%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/current/usr/lib/python3.5/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/current/usr/lib/python3.5/__pycache__/mailcap.cpython-35.pyc



|�g� �@sdZddlZddlZddlZddgZejd�jZGdd�de�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zddgdd�Zddd�Zgdd�Zdd�Zdd�Zdd�Zedkre�dS)z%Mailcap file handling.  See RFC 1524.�N�getcaps�	findmatchz[^\xa1-\xff\w@+=:,./-]c@seZdZdZdS)�UnsafeMailcapInputz)Warning raised when refusing unsafe inputN)�__name__�
__module__�__qualname__�__doc__�r	r	�/usr/lib/python3.5/mailcap.pyrsrcCs�i}x�t�D]�}yt|d�}Wntk
r@wYnX|�t|�}WdQRXxE|j�D]7\}}||kr�|||<qh|||||<qhWqW|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�valuer	r	r
rs


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)ZpathstrZmailcapsZhomer	r	r
r+s

rcCs;i}x.|j�}|sP|ddks	|j�dkrAq	|}xF|d	d�dkr�|j�}|sxd}|dd
�|}qJWt|�\}}|o�|s�q	|jd�}x.tt|��D]}||j�||<q�Wdj|�j�}||kr&||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�jr	r	r
r>s0	"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.
    r�rN�view�=r)NN)r%�
parsefieldr(�findr")
r)r*�i�n�fieldrr.�restZfkeyZfvaluer	r	r
r#ds*
&
	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)r2r3�start�cr	r	r
r0�s

r0r.z	/dev/nullc
Cs�t|�r-d|f}tj|t�dSt|||�}x�|D]�}d|kr�t|d||�}|dkr}qF|r�tj|�dkr�qFt|||||�}	|	dk	rF|	|fSqFWdS)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.

    zHRefusing to use mailcap with filename %r. Use a safe temporary filename.N�testr)NN)NN)�_find_unsafe�warnings�warnr�lookup�substr�system)
r�MIMEtyper�filename�plist�msg�entries�er:�commandr	r	r
r�s 	

cs�g}||kr |||}|jd�}|dd}||krW|||}�dk	r|�fdd�|D�}|S)Nrrz/*cs"g|]}�|kr|�qSr	r	)�.0rF)rr	r
�
<listcomp>�s	zlookup.<locals>.<listcomp>)r)rrArrEZ	MIMEtypesr	)rr
r>�sr>cCs�d}dt|�}}x�||kr�||}|d}|dkr|dkrr|||d�}|d}||}q||}|d}|dkr�||}q|dkr�||}q|dkrt|�r�d|f}tj|t�dS||}q|d	kr�|}	x*||krI||d
krI|d}q W||	|�}
|d}t|
|�}t|�r�d||
f}tj|t�dS||}q|d|}qW|S)Nrrr-�%r7�s�tz9Refusing to substitute MIME type %r into a shell command.�{�}z=Refusing to substitute parameter %r (%s) into a shell command)r%r;r<r=r�	findparam)r4rArBrCZresr2r3r9rDr8�nameZparamr	r	r
r?�sH











r?cCs[|j�d}t|�}x8|D]0}|d|�j�|kr#||d�Sq#WdS)Nr/r)r'r%)rPrCr3�pr	r	r
rO�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)	Nrr-rz"usage: mailcap [MIMEtype file] ...r.zNo viewer found forz
Executing:zExit status:)�sysr�argv�showr$r%�printr�typerr@)	rRrr2�argsrA�filerGrF�stsr	r	r
r:�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)rUrr�sorted)r�fnZckeysrVrErF�keys�kr	r	r
rTs"
	





rT�__main__)rrr<�re�__all__�compile�searchr;�Warningrrrrr#r0rr>r?rOr:rTrr	r	r	r
�<module>s&&)

Zerion Mini Shell 1.0