File: //snap/core/17212/usr/lib/python3.5/__pycache__/mailcap.cpython-35.pyc
|�g� � @ s d Z d d l Z d d l Z d d l Z d d g Z e j d � j Z Gd d � d e � Z d d � Z
d d
� Z d d � Z d
d � Z
d d � Z d d g d d � Z d d d � Z g 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� findmatchz[^\xa1-\xff\w@+=:,./-]c @ s e Z d Z d Z d S)�UnsafeMailcapInputz)Warning raised when refusing unsafe inputN)�__name__�
__module__�__qualname__�__doc__� r r �/usr/lib/python3.5/mailcap.pyr s r c C s� i } x� t � D]� } y t | d � } Wn t k
r@ w Yn X| � t | � } Wd QRXxE | j � D]7 \ } } | | k r� | | | <qh | | | | | <qh Wq 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".
�rN)�listmailcapfiles�open�OSError�readmailcapfile�items)�capsZmailcap�fpZmorecaps�key�valuer r r
r s
c C sp d t j k r1 t j d } | j t j � } n; d t j k rP t j d } n d } | d d d d g } | 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 c C s; i } x.| j � } | s P| d d k s | j � d k rA q | } xF | d d � d k r� | j � } | sx d } | d d
� | } qJ Wt | � \ } } | o� | s� q | j d � } x. t t | � � D] } | | j � | | <q� Wd j | � j � } | | k r&| | 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)r r �lineZnextliner �fields�types�jr r r
r >