B XyC@sddlZddlZddlZddgZddZedjZGdddeZ d dZ d d Z d d Z ddZ ddZddZddgfddZd"ddZgfddZddZddZdd Zed!kredS)#Ngetcaps findmatchcCsd|krd|dfSdSdS)Nlinenor)r)entryrr*/opt/alt/python37/lib/python3.7/mailcap.pylineno_sort_key s r z[^\xa1-\U0010FFFF\w@+=:,./-]c@s eZdZdS)UnsafeMailcapInputN)__name__ __module__ __qualname__rrrrr sr c Csi}d}xtD]}yt|d}Wntk r8wYnX|t||\}}WdQRXx6|D]*\}}||kr||||<qb|||||<qbWqW|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_rrrreadmailcapfileEsr$c Csi}x|}|sP|ddks|dkr.q|}x4|dddkrf|}|sTd}|dd|}q4Wt|\}}|r|s~q|dk r||d<|d7}|d }x$tt|D]}||||<qWd |}||kr|||q|g||<qW||fS) Nr#z\  rr/) readlinestrip parselinerrangelenjoinlowerappend) rrrlineZnextlinerfieldstypesjrrrrMs6   rc Csg}dt|}}x.||kr@t|||\}}|||d}qWt|dkrRdS|d|d|dd}}}d|i}x^|D]V}|d}|dkr|}d} n$|d|}||dd} ||krq| ||<qW||fS)Nrrr)NNview=r&)r. parsefieldr1findr+) r2r3infieldrr6restZfkeyZfvaluerrrr,vs*        r,cCsT|}x:||kr>||}|dkr"Pq|dkr4|d}q|d}qW||||fS)N;\rr)r+)r2r:r;startcrrrr8s   r8r6z /dev/nullc Cst|r"d|f}t|tdSt|||}xd|D]\}d|krnt|d||}|dkrZq4|rnt|dkrnq4t|||||} | dk r4| |fSq4WdS)NzHRefusing to use mailcap with filename %r. Use a safe temporary filename.)NNtestr) _find_unsafer r!r lookupsubstrsystem) rMIMEtyperfilenameplistmsgentrieserBcommandrrrrs      cslg}||kr|||}|d}|dd}||krB|||}dk r\fdd|D}t|td}|S)Nr)rz/*csg|]}|kr|qSrr).0rL)rrr szlookup..)r)rsortedr )rrGrrKZ MIMEtypesr)rrrDs     rDc Cs\d}dt|}}xB||krV||}|d}|dkrb|dkrX|||d}|d}||}q||}|d}|dkr||}q|dkr||}q|dkrt|rd|f}t|tdS||}q|d krH|} x ||kr||d kr|d}qW|| |} |d}t| |} t| r>d | | f}t|tdS|| }q|d|}qW|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.rCr r!r findparam) r<rGrHrIZresr:r;rArJr@nameZparamrrrrEsH              rEcCsF|d}t|}x,|D]$}|d||kr||dSqWdS)Nr7r&)r0r.)rWrIr;prrrrVs   rVc Csddl}t}|jdds(t|dSxtdt|jdD]}|j||d}t|dkrjtddS|d}|d}t||d|\}}|stdtqs( ) )