3 \@sddlZddlZddgZddZddZddZd d Zd d Zd dZddZ ddgfddZ dddZ gfddZ ddZ ddZddZedkredS) Ngetcaps findmatchcCsd|krd|dfSdSdS)Nlinenor)rr)entryrr/usr/lib64/python3.6/mailcap.pylineno_sort_key s r cCsi}d}xtD]}yt|d}Wntk r8wYnX|t||\}}WdQRXx6|jD]*\}}||kr||||<qb|||||<qbWqW|S)Nrr)listmailcapfilesopenOSError_readmailcapfileitems)capsrZmailcapfpZmorecapskeyvaluerrrrs   cCsPdtjkr"tjd}|jtj}n*dtjkr8tjd}nd}|ddddg}|S)NZMAILCAPSHOME.z /.mailcapz /etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)osenvironsplitpathsep)ZpathstrZmailcapshomerrrr -s    r cCs tjdtdt|d\}}|S)Nz2readmailcapfile is deprecated, use getcaps instead)warningswarnDeprecationWarningr)rr_rrrreadmailcapfile?sr c Csi}x|j}|sP|ddks|jdkr.q|}x4|d ddkrf|j}|sTd}|dd |}q4Wt|\}}|oz|s~q|dk r||d<|d7}|jd }x$tt|D]}||j||<qWd j|j}||kr||j|q|g||<qW||fS) Nr#rz\  rr/r%) readlinestrip parselinerrangelenjoinlowerappend) rrrlineZnextlinerfieldstypesjrrrrGs6   rc Csg}dt|}}x.||kr@t|||\}}|j||d}qWt|dkrRdS|d|d|dd}}}d|i}x^|D]V}|jd}|dkr|}d} n$|d|j}||ddj} ||krq| ||<qW||fS)Nrrrview=r")NN)r* parsefieldr-findr') r.r/infieldrr2restZfkeyZfvaluerrrr(ps*        r(cCsT|}x:||kr>||}|dkr"Pq|dkr4|d}q|d}qW|||j|fS)N;\rr)r')r.r6r7startcrrrr4s   r4r2z /dev/nullc Csbt|||}xP|D]H}d|krBt|d||}|rBtj|dkrBqt|||||}||fSWdS)Ntestr)NN)lookupsubstrsystem) rMIMEtyperfilenameplistentrieser>commandrrrrs   cslg}||kr|||}|jd}|dd}||krB|||}dk r\fdd|D}t|td}|S)Nr$rz/*csg|]}|kr|qSrr).0rF)rrr szlookup..)r)rsortedr )rrBrrEZ MIMEtypesr)rrr?s     r?c Cs d}dt|}}x||kr||}|d}|dkr`|dkrV|||d}|d}||}q||}|d}|dkr||}q|dkr||}q|dkr||}q|dkr|}x ||kr||d kr|d}qW|||} |d}|t| |}q|d|}qW|S) Nr"rr%r;st{})r* findparam) r8rBrCrDresr6r7r=r<namerrrr@s6       r@cCsF|jd}t|}x,|D]$}|d|j|kr||dSqWdS)Nr3r")r,r*)rRrDr7prrrrPs   rPc Csddl}t}|jdds(t|dSxtdt|jdD]}|j||d}t|dkrjtddS|d}|d}t||d|\}}|stdtqs&    r>cCstdxtD]}td|qWt|s4t}tdtt|}xX|D]P}t|||}x:|D]2}t|}x|D]}td|||q|WtqjWqPWdS)NzMailcap files: zMailcap entries:z %-15s)rWr rrJ)rfnZckeysrXrErFkeyskrrrrVs"    rV__main__)N)rr__all__r rr r rr(r4rr?r@rPr>rV__name__rrrrs" )