관리-도구
편집 파일: mailcap.cpython-39.pyc
a �����DOg�#����������������������@���s����d�Z�ddlZddlZddlZddgZdd��Ze�d�jZG�dd ��d e �Z d d��Zdd��Zd d��Z dd��Zdd��Zdd��Zddg�fdd�Zd#dd�Zg�fdd�Zdd��Zdd��Zd d!��Zed"kr�e���dS�)$z%Mailcap file handling. See RFC 1524.�����N�getcaps� findmatchc�����������������C���s���d|�v�rd|�d�fS�dS�d�S�)N�linenor���)����r�����)�entryr���r����/usr/lib64/python3.9/mailcap.py�lineno_sort_key ���s����r ���z[^\xa1-\U0010FFFF\w@+=:,./-]c�������������������@���s���e�Zd�ZdZdS�)�UnsafeMailcapInputz)Warning raised when refusing unsafe inputN)�__name__� __module__�__qualname__�__doc__r���r���r���r���r ������s���r ���c��������������� ���C���s����i�}�d}t���D�]�}zt|d�}W�n�ty6���Y�qY�n0�|��t||�\}}W�d����n1�s`0����Y��|���D�]*\}}||�vr�||�|<�qr|�|�|�|�|<�qrq|�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���Zmailcap�fpZmorecaps�key�valuer���r���r���r������s���� , c������������������C���sP���dt�jv�r"t�jd�}�|��t�j�}n*dt�jv�r8t�jd�}nd}|d�dddg}|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�homer���r���r���r���3���s���� �r���c�����������������C���s ���t��dtd��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�}|�����}|sq�|d�dks|���dkr,q|}|dd��dkrb|�����}|sPd}|dd��|�}q0t|�\}}|r|sxq|dur�||d<�|d 7�}|�d �}tt|��D�]}||����||<�q�d �|����}||v�r�||��|��q|g||<�q||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����#�����Nz\ � r���r����/) �readline�strip� parseliner����range�len�join�lower�append) r���r���r����lineZnextliner����fields�types�jr���r���r���r���M���s0���� r���c����������� ������C���s����g�}dt�|���}}||k�r>t|�||�\}}|�|��|d�}qt�|�dk�rNdS�|d�|d�|dd����}}}d|i}|D�]V}|�d�}|dk�r�|}d} n$|d|�����}||d�d�����} ||v�r�qz| ||<�qz||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���r���r ����NNN�view�=r'���)r/���� parsefieldr2����findr,���) r3���r4����i�n�fieldr���r8����restZfkeyZfvaluer���r���r���r-���v���s*���� r-���c�����������������C���sP���|}||k�r<|�|�}|dkr q<q|dkr2|d�}q|d�}q|�||������|fS�)z/Separate one key-value pair in a mailcap entry.�;�\r ���r���)r,���)r3���r<���r=����start�cr���r���r���r:�������s���� r:���r8���z /dev/nullc����������� ������C���s����t�|�r"d|f�}t�|t��dS�t|�||�}|D�]`}d|v�rlt|d�||�}|du�rXq2|rlt�|�dkrlq2t||�|||�} | dur2| |f��S�q2dS�)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.r7����testNr���)�_find_unsafer!���r"���r ����lookup�substr����system) r����MIMEtyper����filename�plist�msg�entries�erD����commandr���r���r���r�������s ���� c��������������������sl���g�}||�v�r||�|��}|��d�}|d�d�}||�v�rB||�|��}��d�ur\��fdd�|D��}t|td�}|S�)Nr*���r���z/*c��������������������s���g�|�]}��|v�r|�qS�r���r���)�.0rN����r���r���r���� <listcomp>���������zlookup.<locals>.<listcomp>rQ���)r����sortedr ���)r���rI���r���rM���Z MIMEtypesr���rQ���r���rF�������s���� rF���c�����������������C���sR��d}dt�|���}}||k��rN|�|�}|d�}|dkr^|dkrT|�||d���}|d�}||�}q|�|�}|d�}|dkr�||�}q|dkr�||�}q|dkr�t|�r�d|f�}t�|t��d�S�||�}q|d k�r@|} ||k�r�|�|�d kr�|d�}q�|�| |��} |d�}t| |�}t|��r6d|| f�}t�|t��d�S�||�}q|d�|�}q|S�)Nr'���r���r����%rA����s�tz9Refusing to substitute MIME type %r into a shell command.�{�}z=Refusing to substitute parameter %r (%s) into a shell command)r/���rE���r!���r"���r ���� findparam)r>���rI���rJ���rK����resr<���r=���rC���rL���rB����nameZparamr���r���r���rG�������sB���� rG���c�����������������C���sF���|�����d�}�t|��}|D�](}|d�|������|�kr||d�����S�qdS�)Nr9���r'���)r1���r/���)r\���rK���r=����pr���r���r���rZ�������s����rZ���c������������ ������C���s����dd�l�}�t��}|�jdd���s(t|��d�S�tdt|�j�d�D�]�}|�j||d���}t|�dk�rjtd���d�S�|d�}|d�}t||d|�\}}|s�tdt��q:td|��t � |�}t �|�}|r:td|��q:d�S�) Nr���r���r ���z"usage: mailcap [MIMEtype file] ...r8���zNo viewer found forz Executing:zExit status:)�sysr����argv�showr.���r/����printr����typer���rH����waitstatus_to_exitcode) r^���r���r<����argsrI����filerO���rN����stsr���r���r���rD�����s(���� rD���c�����������������C���s����t�d��t��D�]}t�d|���qt����|�s0t��}�t�d��t����t|��}|D�]H}t�|��|�|�}|D�].}t|�}|D�]}t�d|�||���qrt����qbqJd�S�)NzMailcap files:� zMailcap entries:z %-15s)ra���r���r���rT���)r����fnZckeysrb���rM���rN����keys�kr���r���r���r`�����s���� r`����__main__)N)r���r���r!����re�__all__r ����compile�searchrE����Warningr ���r���r���r%���r���r-���r:���r���rF���rG���rZ���rD���r`���r���r���r���r���r����<module>���s*���) )