ÿØÿà JFIF      ÿÛ „ 	 ( %!1!%)+//.383,7(-.+



-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ               ÿÄ J  	     ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ              ÿÄ *        !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍÑ¶¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     ÿØÿà JFIF      ÿÛ „ 	 ( %!1!%)+//.383,7(-.+



-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ               ÿÄ J  	     ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ              ÿÄ *        !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍÑ¶¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     3
ik#                 @   s   d Z ddlZddlZddlZddgZdd ZejdjZG dd	 d	e	Z
d
d Zdd Zdd Zdd Zdd Zdd Zddg fddZd#ddZg fddZdd Zdd Zd d! Zed"kre  dS )$z%Mailcap file handling.  See RFC 1524.    Ngetcaps	findmatchc             C   s   d| krd| d fS dS d S )Nlinenor      )r   r    )entryr   r   /usr/lib64/python3.6/mailcap.pylineno_sort_key
   s    r	   z[^\xa1-\U0010FFFF\w@+=:,./-]c               @   s   e Zd ZdZdS )UnsafeMailcapInputz)Warning raised when refusing unsafe inputN)__name__
__module____qualname____doc__r   r   r   r   r
      s   r
   c              C   s   i } d}xt  D ]}yt|d}W n tk
r8   wY nX | t||\}}W dQ R X x6|j D ]*\}}|| kr||| |< qb| | | | |< qbW qW | 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)capsr   ZmailcapfpZmorecapskeyvaluer   r   r   r      s    

c              C   sP   dt jkr"t jd } | jt j}n*dt jkr8t jd }nd}|d dddg}|S )z7Return a list of all mailcap files found on the system.ZMAILCAPSHOME.z	/.mailcapz/etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)osenvironsplitpathsep)ZpathstrZmailcapshomer   r   r   r   3   s    


r   c             C   s    t jdtd 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   )r   r   _r   r   r   readmailcapfileE   s    r%   c       	      C   s  i }x| j  }|sP |d dks|j dkr.q|}x4|dd dkrf| j  }|sTd}|dd | }q4W t|\}}|oz|s~q|dk	r||d< |d	7 }|jd
}x$tt|D ]}|| j ||< qW d
j|j }||kr|| j| q|g||< qW ||f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   # r    Nz\

r   r   /r*   )	readlinestrip	parseliner   rangelenjoinlowerappend)	r   r   r   lineZnextliner   fieldstypesjr   r   r   r   M   s6    	  
r   c       
      C   s   g }dt |  }}x.||k r@t| ||\}}|j| |d }qW t |dk rRdS |d |d |dd   }}}d|i}x^|D ]V}|jd}|dk r|}d}	n$|d| j }||d d j }	||krq|	||< qW ||fS )	zParse 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   r   r    Nview=r'   )NN)r/   
parsefieldr2   findr,   )
r3   r4   infieldr   r7   restZfkeyZfvaluer   r   r   r-   v   s*    

 

r-   c             C   sT   |}x:||k r>| | }|dkr"P q|dkr4|d }q|d }qW | || j  |fS )z/Separate one key-value pair in a mailcap entry.;\r    r   )r,   )r3   r;   r<   startcr   r   r   r9      s    

r9   r7   z	/dev/nullc       
      C   s   t |r"d|f }tj|t dS t| ||}xd|D ]\}d|krnt|d ||}|dkrZq4|rntj|dkrnq4t|| |||}	|	dk	r4|	|fS q4W dS )a  Find 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_unsafer!   r"   r
   lookupsubstr   system)
r   MIMEtyper   filenameplistmsgentrieserC   commandr   r   r   r      s     	

c                sl   g }|| kr|| |  }|j d}|d d }|| krB|| |  } d k	r\ fdd|D }t|td}|S )Nr)   r   z/*c                s   g | ]} |kr|qS r   r   ).0rM   )r   r   r   
<listcomp>   s    zlookup.<locals>.<listcomp>)r   )r   sortedr	   )r   rH   r   rL   Z	MIMEtypesr   )r   r   rE      s    
rE   c             C   s\  d}dt |  }}xB||k rV| | }|d }|dkrb|dkrX| ||d  }|d }|| }q| | }|d }|dkr|| }q|dkr|| }q|dkrt|rd|f }tj|t d S || }q|d	krH|}	x ||k r| | d
kr|d }qW | |	| }
|d }t|
|}t|r>d||
f }tj|t d S || }q|d | }qW |S )Nr'   r   r   %r@   stz9Refusing to substitute MIME type %r into a shell command.{}z=Refusing to substitute parameter %r (%s) into a shell command)r/   rD   r!   r"   r
   	findparam)r=   rH   rI   rJ   resr;   r<   rB   rK   rA   nameZparamr   r   r   rF      sH      
 







rF   c             C   sF   | j  d } t| }x,|D ]$}|d | j  | kr||d  S qW dS )Nr8   r'   )r1   r/   )rY   rJ   r<   pr   r   r   rW      s    
rW   c        	      C   s   dd l } t }| jdd  s(t| d S xtdt| jdD ]}| j||d  }t|dk rjtd d S |d }|d }t||d|\}}|stdt q<td| t	j
|}|r<td| q<W d S )	Nr   r   r    z"usage: mailcap [MIMEtype file] ...r7   zNo viewer found forz
Executing:zExit status:)sysr   argvshowr.   r/   printr   typer   rG   )	r[   r   r;   argsrH   filerN   rM   stsr   r   r   rC     s&    

rC   c             C   s   t d xt D ]}t d|  qW t   | s4t } t d t   t| }xX|D ]P}t | | | }x:|D ]2}t|}x|D ]}t d| ||  q|W t   qjW qPW d S )NzMailcap files:	zMailcap entries:z  %-15s)r^   r   r   rQ   )r   fnZckeysr_   rL   rM   keyskr   r   r   r]     s"      


r]   __main__)N)r   r   r!   re__all__r	   compilesearchrD   Warningr
   r   r   r%   r   r-   r9   r   rE   rF   rW   rC   r]   r   r   r   r   r   <module>   s*   )
)