U ifk#@sddlZddlZddlZddgZddZedjZGdddeZ d dZ d d Z d d Z ddZ ddZddZddgfddZd"ddZgfddZddZddZdd Zed!kredS)#Ngetcaps findmatchcCsd|krd|dfSdSdS)Nlinenor)r)entryrr,/opt/alt/python38/lib64/python3.8/mailcap.pylineno_sort_key s r z[^\xa1-\U0010FFFF\w@+=:,./-]c@s eZdZdS)UnsafeMailcapInputN)__name__ __module__ __qualname__rrrrr sr c Csi}d}tD]~}zt|d}Wntk r8YqYnX|t||\}}W5QRX|D]*\}}||krz|||<q`|||||<q`q|S)Nrr)listmailcapfilesopenOSError_readmailcapfileitems)capsrZmailcapfpZmorecapskeyvaluerrrrs    cCsPdtjkr"tjd}|tj}n*dtjkr8tjd}nd}|ddddg}|S)NZMAILCAPSHOME.z /.mailcapz /etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)osenvironsplitpathsep)ZpathstrZmailcapshomerrrr3s    rcCs tdtdt|d\}}|S)Nz2readmailcapfile is deprecated, use getcaps instead)warningswarnDeprecationWarningr)rr_rrrreadmailcapfileEs r$c Csi}|}|sq|ddks|dkr,q|}|dddkrb|}|sPd}|dd|}q0t|\}}|r|sxq|dk r||d<|d7}|d }tt|D]}||||<qd |}||kr|||q|g||<q||fS) Nr#z\  rr/) readlinestrip parselinerrangelenjoinlowerappend) rrrlineZnextlinerfieldstypesjrrrrMs4    rc Csg}dt|}}||kr>t|||\}}|||d}qt|dkrNdS|d|d|dd}}}d|i}|D]V}|d}|dkr|}d} n$|d|}||dd} ||krqz| ||<qz||fS)NrrrNNview=r&)r. parsefieldr1findr+) r2r3infieldrr7restZfkeyZfvaluerrrr,vs*      r,cCsP|}||kr<||}|dkr qszlookup..rP)rsortedr )rrHrrLZ MIMEtypesrrPrrEs     rEc CsRd}dt|}}||krN||}|d}|dkr^|dkrT|||d}|d}||}q||}|d}|dkr||}q|dkr||}q|dkrt|rd|f}t|tdS||}q|d kr@|} ||kr||d kr|d}q|| |} |d}t| |} t| r6d | | f}t|tdS|| }q|d|}q|S) Nr&rr%r@stz9Refusing to substitute MIME type %r into a shell command.{}z=Refusing to substitute parameter %r (%s) into a shell command)r.rDr r!r findparam) r=rHrIrJresr;r<rBrKrAnameZparamrrrrFsH               rFcCsF|d}t|}|D](}|d||kr||dSqdS)Nr8r&)r0r.)rZrJr<prrrrXs  rXc Csddl}t}|jdds(t|dStdt|jdD]}|j||d}t|dkrjtddS|d}|d}t||d|\}}|stdtq:td|t |}|r:td|q:dS) Nrrrz"usage: mailcap [MIMEtype file] ...r7zNo viewer found forz Executing:z Exit status:) sysrargvshowr-r.printrtyperrG) r\rr;argsrHfilerNrMstsrrrrCs&    rCcCstdtD]}td|qt|s0t}tdtt|}|D]H}t|||}|D].}t|}|D]}td|||qrtqbqJdS)NzMailcap files: zMailcap entries:z %-15s)r_rrrR)rfnZckeysr`rLrMkeyskrrrr^s" r^__main__)N)rr re__all__r compilesearchrDWarningr rrr$rr,r9rrErFrXrCr^r rrrrs( ) )